From 1d1cc940f47c41637adea5c5a1e5d3c80807f9d7 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sun, 6 Jan 2019 00:23:27 +0100 Subject: Add the base32 format for OTP secrets Many applications display OTP secrets in the base32 format (according to RFC 4648). This patch adds base32 as a possible value for the --format option to the otp set subcommand. --- nitrocli/src/args.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'nitrocli/src/args.rs') diff --git a/nitrocli/src/args.rs b/nitrocli/src/args.rs index b109944..b5d4e81 100644 --- a/nitrocli/src/args.rs +++ b/nitrocli/src/args.rs @@ -327,6 +327,7 @@ impl From for nitrokey::OtpMode { #[derive(Clone, Copy, Debug, PartialEq)] pub enum OtpSecretFormat { Ascii, + Base32, Hex, } @@ -337,6 +338,7 @@ impl fmt::Display for OtpSecretFormat { "{}", match *self { OtpSecretFormat::Ascii => "ascii", + OtpSecretFormat::Base32 => "base32", OtpSecretFormat::Hex => "hex", } ) @@ -349,6 +351,7 @@ impl str::FromStr for OtpSecretFormat { fn from_str(s: &str) -> result::Result { match s { "ascii" => Ok(OtpSecretFormat::Ascii), + "base32" => Ok(OtpSecretFormat::Base32), "hex" => Ok(OtpSecretFormat::Hex), _ => Err(()), } @@ -777,7 +780,7 @@ pub fn otp_set(ctx: &ExecCtx, args: Vec) -> Result<()> { let _ = parser.refer(&mut secret_format).add_option( &["-f", "--format"], argparse::StoreOption, - "The format of the secret (ascii|hex)", + "The format of the secret (ascii|base32|hex)", ); parse(&parser, args)?; drop(parser); -- cgit v1.2.1