parsing generate works

master
Avril 4 years ago
parent 2dd8d37abb
commit 608e83d65d
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -12,7 +12,7 @@ pub enum ParseErrorKind
ExpectedArg(String), ExpectedArg(String),
UnexpectedArg(Option<String>), UnexpectedArg(Option<String>),
UnknownOption(char), UnknownOption(char),
UnknownKeyFormat(&'static str), UnknownKeyFormat(&'static str, String),
UnknownOptionFor(char, char), UnknownOptionFor(char, char),
CannotCombine(char, char), CannotCombine(char, char),
BadTail(char, String), BadTail(char, String),
@ -32,7 +32,7 @@ impl fmt::Display for ParseErrorKind
Self::UnexpectedArg(None) => write!(f, "unknown argument"), Self::UnexpectedArg(None) => write!(f, "unknown argument"),
Self::UnexpectedArg(Some(arg)) => write!(f, "argument {:?} not expected here", arg), Self::UnexpectedArg(Some(arg)) => write!(f, "argument {:?} not expected here", arg),
Self::UnknownOption(ch) => write!(f, "unknown option `{}`", ch), Self::UnknownOption(ch) => write!(f, "unknown option `{}`", ch),
Self::UnknownKeyFormat(key) => write!(f, "unknown key format for {}", key), Self::UnknownKeyFormat(key, fmt) => write!(f, "unknown key format {:?} for {}", fmt, key),
Self::UnknownOptionFor(fo, o) => write!(f, "unknown option `{}` for `{}`", o, fo), Self::UnknownOptionFor(fo, o) => write!(f, "unknown option `{}` for `{}`", o, fo),
Self::CannotCombine(o1,o2) => write!(f, "cannot combine option `{}` with `{}`", o2, o1), Self::CannotCombine(o1,o2) => write!(f, "cannot combine option `{}` with `{}`", o2, o1),
Self::BadTail(ch, ret) => write!(f, "unexpected tail {:?} for option `{}`", ret, ch), Self::BadTail(ch, ret) => write!(f, "unexpected tail {:?} for option `{}`", ret, ch),

@ -71,6 +71,7 @@ pub(super) async fn handle(mut rx: Receiver<Atom>) -> Result<config::Operation,
output_priv: stage.output.ok_or_else(|| error::ConstructError::ExpectedNotPresent("output"))?, output_priv: stage.output.ok_or_else(|| error::ConstructError::ExpectedNotPresent("output"))?,
output_pub: stage.output_public, output_pub: stage.output_public,
password: stage.password, password: stage.password,
format: stage.format,
description: Default::default(), /* TODO */ description: Default::default(), /* TODO */
}) })
} else { } else {
@ -79,6 +80,7 @@ pub(super) async fn handle(mut rx: Receiver<Atom>) -> Result<config::Operation,
input: stage.input.map(|inp| (inp, input_pw)), input: stage.input.map(|inp| (inp, input_pw)),
output: stage.output.ok_or_else(|| error::ConstructError::ExpectedNotPresent("output"))?, output: stage.output.ok_or_else(|| error::ConstructError::ExpectedNotPresent("output"))?,
password: stage.password, password: stage.password,
format: stage.format,
description: Default::default(), /* TODO */ description: Default::default(), /* TODO */
}) })
}; };
@ -146,13 +148,13 @@ pub(super) async fn parse<I: IntoIterator<Item=String>>(args: I, mut atoms: mpsc
"PEM" => KeyFormat::PEM, "PEM" => KeyFormat::PEM,
"BIN" => KeyFormat::Bin, "BIN" => KeyFormat::Bin,
"TEXT" => KeyFormat::Text, "TEXT" => KeyFormat::Text,
__ => return Err((arg, error::ParseErrorKind::UnknownKeyFormat("rsa")).into()), other => return Err((arg, error::ParseErrorKind::UnknownKeyFormat("rsa", other.to_owned())).into()),
})).await?, })).await?,
"format" => "format" =>
send!(GenerateAtom::Format(match take_one!("--format: Expected output format").to_uppercase().trim() { send!(GenerateAtom::Format(match take_one!("--format: Expected output format").to_uppercase().trim() {
"BIN" => KeyFormat::Bin, "BIN" => KeyFormat::Bin,
"TEXT" => KeyFormat::Text, "TEXT" => KeyFormat::Text,
__ => return Err((arg, error::ParseErrorKind::UnknownKeyFormat("aes")).into()), other => return Err((arg, error::ParseErrorKind::UnknownKeyFormat("aes", other.to_owned())).into()),
})).await?, })).await?,
_ => return Err((arg, error::ParseErrorKind::UnexpectedArg(None)).into()), _ => return Err((arg, error::ParseErrorKind::UnexpectedArg(None)).into()),
} }

@ -58,22 +58,7 @@ impl Default for TranslationMode
} }
} }
#[derive(Debug, Hash, PartialEq, Eq)] use config::op::KeyFormat;
enum KeyFormat
{
Bin,
Text,
PEM,
}
impl Default for KeyFormat
{
#[inline]
fn default() -> Self
{
Self::Bin
}
}
#[derive(Debug, Hash, PartialEq, Eq)] #[derive(Debug, Hash, PartialEq, Eq)]
enum GenerateKeyKind enum GenerateKeyKind

@ -10,6 +10,24 @@ pub mod op {
Decrypt, Decrypt,
} }
#[derive(Debug, Clone,PartialEq, Eq, Hash)]
pub enum KeyFormat
{
Bin,
Text,
PEM,
}
impl Default for KeyFormat
{
#[inline]
fn default() -> Self
{
Self::Bin
}
}
#[derive(Debug, Clone,PartialEq, Eq, Default)] #[derive(Debug, Clone,PartialEq, Eq, Default)]
pub struct Normal { pub struct Normal {
pub rsa: Vec<(String, Password)>, pub rsa: Vec<(String, Password)>,
@ -61,6 +79,7 @@ pub mod op {
pub output_priv: String, pub output_priv: String,
pub output_pub: Option<String>, pub output_pub: Option<String>,
pub password: Password, pub password: Password,
pub format: KeyFormat,
pub description: KeyDescription, pub description: KeyDescription,
} }
@ -71,6 +90,7 @@ pub mod op {
pub output: String, pub output: String,
pub password: Password, pub password: Password,
pub format: KeyFormat,
pub description: KeyDescription, pub description: KeyDescription,
} }

Loading…
Cancel
Save