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),
UnexpectedArg(Option<String>),
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),

@ -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_pub: stage.output_public,
password: stage.password,
format: stage.format,
description: Default::default(), /* TODO */
})
} 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)),
output: stage.output.ok_or_else(|| error::ConstructError::ExpectedNotPresent("output"))?,
password: stage.password,
format: stage.format,
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,
"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()),
}

@ -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

@ -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<String>,
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,
}
}

Loading…
Cancel
Save