From 608e83d65dc7cfb3778f2920fa23a902ba7e856a Mon Sep 17 00:00:00 2001 From: Avril Date: Tue, 22 Sep 2020 16:31:05 +0100 Subject: [PATCH] parsing generate works --- src/args/error.rs | 4 ++-- src/args/parse/generate.rs | 6 ++++-- src/args/parse/mod.rs | 17 +---------------- src/config.rs | 22 +++++++++++++++++++++- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/args/error.rs b/src/args/error.rs index 0c749fe..3b6cbd7 100644 --- a/src/args/error.rs +++ b/src/args/error.rs @@ -12,7 +12,7 @@ pub enum ParseErrorKind ExpectedArg(String), UnexpectedArg(Option), UnknownOption(char), - UnknownKeyFormat(&'static str), + UnknownKeyFormat(&'static str, String), UnknownOptionFor(char, char), CannotCombine(char, char), BadTail(char, String), @@ -32,7 +32,7 @@ impl fmt::Display for ParseErrorKind Self::UnexpectedArg(None) => write!(f, "unknown argument"), Self::UnexpectedArg(Some(arg)) => write!(f, "argument {:?} not expected here", arg), 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::CannotCombine(o1,o2) => write!(f, "cannot combine option `{}` with `{}`", o2, o1), Self::BadTail(ch, ret) => write!(f, "unexpected tail {:?} for option `{}`", ret, ch), diff --git a/src/args/parse/generate.rs b/src/args/parse/generate.rs index a087d88..5c08399 100644 --- a/src/args/parse/generate.rs +++ b/src/args/parse/generate.rs @@ -71,6 +71,7 @@ pub(super) async fn handle(mut rx: Receiver) -> Result) -> Result>(args: I, mut atoms: mpsc "PEM" => KeyFormat::PEM, "BIN" => KeyFormat::Bin, "TEXT" => KeyFormat::Text, - __ => return Err((arg, error::ParseErrorKind::UnknownKeyFormat("rsa")).into()), + other => return Err((arg, error::ParseErrorKind::UnknownKeyFormat("rsa", other.to_owned())).into()), })).await?, "format" => send!(GenerateAtom::Format(match take_one!("--format: Expected output format").to_uppercase().trim() { "BIN" => KeyFormat::Bin, "TEXT" => KeyFormat::Text, - __ => return Err((arg, error::ParseErrorKind::UnknownKeyFormat("aes")).into()), + other => return Err((arg, error::ParseErrorKind::UnknownKeyFormat("aes", other.to_owned())).into()), })).await?, _ => return Err((arg, error::ParseErrorKind::UnexpectedArg(None)).into()), } diff --git a/src/args/parse/mod.rs b/src/args/parse/mod.rs index 6f69c3f..ba640ed 100644 --- a/src/args/parse/mod.rs +++ b/src/args/parse/mod.rs @@ -58,22 +58,7 @@ impl Default for TranslationMode } } -#[derive(Debug, Hash, PartialEq, Eq)] -enum KeyFormat -{ - Bin, - Text, - PEM, -} - -impl Default for KeyFormat -{ - #[inline] - fn default() -> Self - { - Self::Bin - } -} +use config::op::KeyFormat; #[derive(Debug, Hash, PartialEq, Eq)] enum GenerateKeyKind diff --git a/src/config.rs b/src/config.rs index 0757c10..8dcf77a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -10,6 +10,24 @@ pub mod op { 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)] pub struct Normal { pub rsa: Vec<(String, Password)>, @@ -61,6 +79,7 @@ pub mod op { pub output_priv: String, pub output_pub: Option, pub password: Password, + pub format: KeyFormat, pub description: KeyDescription, } @@ -71,7 +90,8 @@ pub mod op { pub output: String, pub password: Password, - + pub format: KeyFormat, + pub description: KeyDescription, } }