use super::*; impl Operation { /// Validate the options i/o. pub fn try_into_validated(self) -> Result { match &self { Self::KeyGen{ key_type: GenerateKey::Aes, output, cycle, .. } => { if output == cycle { warn!("Cycle output is the same as input."); } if let Some(output) = output { if output.is_dir() { return Err(output.clone())?; } if output.exists() { warn!("Output will be overwritten."); } } if let Some(cycle) = cycle { if !cycle.exists() || cycle.is_dir() { return Err(cycle.clone())?; } } }, Self::KeyGen{ key_type: GenerateKey::Rsa, output, output_public, cycle, .. } => { if output == output_public && output.is_some() { return Err("Output and public key output are the same.")?; } if cycle == output && output.is_some() { warn!("Cycle output is the same as input."); } if let Some(output) = output { if output.is_dir() { return Err(output.clone())?; } if output.exists() { warn!("Output will be overwritten."); } } if let Some(output_public) = output_public { if output_public.is_dir() { return Err(output_public.clone())?; } if output_public.exists() { warn!("Output for public will be overwritten."); } } if let Some(cycle) = cycle { if !cycle.exists() || cycle.is_dir() { return Err(cycle.clone())?; } } }, _ => (), } Ok(self) } }