You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
1.5 KiB
78 lines
1.5 KiB
use super::*;
|
|
|
|
impl Operation
|
|
{
|
|
/// Validate the options i/o.
|
|
pub fn try_into_validated(self) -> Result<Self, Error>
|
|
{
|
|
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)
|
|
}
|
|
}
|