From c9b9607eab20a278f81cfc2595a31086caf7143c Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 27 Mar 2022 13:00:51 +0800 Subject: [PATCH] chore: chall, chall-config --- src/cmd_chall.rs | 13 ++++++------- src/cmd_challconfig.rs | 6 +++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/cmd_chall.rs b/src/cmd_chall.rs index 97c7c3e..aefc9c3 100644 --- a/src/cmd_chall.rs +++ b/src/cmd_chall.rs @@ -12,7 +12,7 @@ impl Command for CommandImpl { fn name(&self) -> &str { "chall" } fn subcommand<'a>(&self) -> App<'a, 'a> { - SubCommand::with_name(self.name()).about("Yubikey challenge-response hmac") + SubCommand::with_name(self.name()).about("YubiKey challenge-response HMAC") .arg(Arg::with_name("challenge").short("c").long("challenge").takes_value(true).help("Challenge")) .arg(Arg::with_name("challenge-hex").short("x").long("challenge-hex").takes_value(true).help("Challenge HEX")) .arg(Arg::with_name("sha256").short("2").long("sha256").help("Output SHA256")) @@ -28,14 +28,13 @@ impl Command for CommandImpl { let sha256_output = sub_arg_matches.is_present("sha256"); let sha384_output = sub_arg_matches.is_present("sha384"); let sha512_output = sub_arg_matches.is_present("sha512"); - let challenge_bytes: Vec; - if let Some(challenge) = sub_arg_matches.value_of("challenge") { - challenge_bytes = challenge.as_bytes().to_vec(); + let challenge_bytes: Vec = if let Some(challenge) = sub_arg_matches.value_of("challenge") { + challenge.as_bytes().to_vec() } else if let Some(challenge_hex) = sub_arg_matches.value_of("challenge-hex") { - challenge_bytes = opt_result!(hex::decode(challenge_hex), "Decode challenge hex: {}, failed: {}", challenge_hex); + opt_result!(hex::decode(challenge_hex), "Decode challenge hex: {}, failed: {}", challenge_hex) } else { return simple_error!("Challenge must assigned"); - } + }; // Challenge can not be greater than 64 bytes if challenge_bytes.len() > 64 { @@ -81,7 +80,7 @@ impl Command for CommandImpl { hex_sha512.map(|hex_sha512| success!("Response SHA512 HEX: {}", hex::encode(hex_sha512))); } } else { - warning!("Yubikey not found"); + warning!("YubiKey not found"); } Ok(None) diff --git a/src/cmd_challconfig.rs b/src/cmd_challconfig.rs index 03470ec..9f0939e 100644 --- a/src/cmd_challconfig.rs +++ b/src/cmd_challconfig.rs @@ -11,10 +11,10 @@ impl Command for CommandImpl { fn name(&self) -> &str { "chall-config" } fn subcommand<'a>(&self) -> App<'a, 'a> { - SubCommand::with_name(self.name()).about("Yubikey challenge-response hmac config") + SubCommand::with_name(self.name()).about("YubiKey challenge-response HMAC config") .arg(Arg::with_name("secret").short("s").long("secret").takes_value(true).help("Secret")) .arg(Arg::with_name("secret-hex").short("x").long("secret-hex").takes_value(true).help("Secret HEX")) - .arg(Arg::with_name("yes-config-chall").long("yes-config-chall").help("Config chall key")) + .arg(Arg::with_name("yes-config-chall").long("yes-config-chall").help("Config challenge-response key")) } fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError { @@ -55,7 +55,7 @@ impl Command for CommandImpl { success!("Device configured"); } } else { - warning!("Yubikey not found"); + warning!("YubiKey not found"); } Ok(None)