diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2019-01-06 00:10:44 +0100 |
---|---|---|
committer | Daniel Mueller <deso@posteo.net> | 2019-01-13 18:36:58 -0800 |
commit | 53a2893ee725e4ad678b2060fd71729ff55e6cee (patch) | |
tree | 0d17667568b8f6fcb19fa111cc5efd8a7c16df13 /nitrocli/src/commands.rs | |
parent | 091e01ba40e488dfd68b43db56fc0693a350510a (diff) | |
download | nitrocli-53a2893ee725e4ad678b2060fd71729ff55e6cee.tar.gz nitrocli-53a2893ee725e4ad678b2060fd71729ff55e6cee.tar.bz2 |
Add the --format option to otp set to select the secret format
This patch introduces the -f/--format options for the otp set
subcommand to specify the format of the OTP secret. Previously, the
default format was hexadecimal and ASCII format could be selected using
the --ascii option. The new --format option takes the argument hex or
ascii, defaulting to hex, and replaces the --ascii option.
This patch does not remove the --ascii option but marks it as
deprecated. It may not be set together with --format, and a warning is
printed if it is set. It should be deleted with the next minor release.
This patch prepares the addition of a new format, base32.
Diffstat (limited to 'nitrocli/src/commands.rs')
-rw-r--r-- | nitrocli/src/commands.rs | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/nitrocli/src/commands.rs b/nitrocli/src/commands.rs index ac2bbf1..c1942e8 100644 --- a/nitrocli/src/commands.rs +++ b/nitrocli/src/commands.rs @@ -450,7 +450,7 @@ fn prepare_secret(secret: &str) -> Result<String> { ) } else { Err(Error::Error( - "The given secret is not an ASCII string despite --ascii being set".to_string(), + "The given secret is not an ASCII string despite --format ascii being set".to_string(), )) } } @@ -462,12 +462,11 @@ pub fn otp_set( algorithm: args::OtpAlgorithm, counter: u64, time_window: u16, - ascii: bool, + secret_format: args::OtpSecretFormat, ) -> Result<()> { - let secret = if ascii { - prepare_secret(&data.secret)? - } else { - data.secret + let secret = match secret_format { + args::OtpSecretFormat::Ascii => prepare_secret(&data.secret)?, + args::OtpSecretFormat::Hex => data.secret, }; let data = nitrokey::OtpSlotData { secret, ..data }; let device = authenticate_admin(get_device(ctx)?)?; |