From 9f3991a74fa5124e298582afa60b229dd005be40 Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Sun, 13 Oct 2019 05:13:36 -0700 Subject: Properly pad user supplied hexadecimal strings to otp set subcommand The library ultimately taking care of communicating with the Nitrokey device, libnitrokey, unconditionally expects hexadecimal strings supplied as part of the configuration of an OTP slot to have an even number of bytes. Users should not be aware of this detail and so with this change we take care of padding the supplied string with a leading zero to make such a configuration go through without an error. --- nitrocli/src/tests/otp.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'nitrocli/src/tests') diff --git a/nitrocli/src/tests/otp.rs b/nitrocli/src/tests/otp.rs index 39ddf29..531ed5f 100644 --- a/nitrocli/src/tests/otp.rs +++ b/nitrocli/src/tests/otp.rs @@ -19,6 +19,8 @@ use super::*; +use crate::args; + #[test_device] fn set_invalid_slot_raw(device: nitrokey::DeviceWrapper) { let (rc, out, err) = Nitrocli::with_dev(device).run(&["otp", "set", "100", "name", "1234"]); @@ -96,6 +98,20 @@ fn set_get_totp(device: nitrokey::DeviceWrapper) -> crate::Result<()> { Ok(()) } +#[test_device] +fn set_totp_uneven_chars(device: nitrokey::DeviceWrapper) -> crate::Result<()> { + let secrets = [ + (args::OtpSecretFormat::Hex, "123"), + (args::OtpSecretFormat::Base32, "FBILDWWGA2"), + ]; + + let mut ncli = Nitrocli::with_dev(device); + for (format, secret) in &secrets { + let _ = ncli.handle(&["otp", "set", "-f", format.as_ref(), "3", "foobar", &secret])?; + } + Ok(()) +} + #[test_device] fn clear(device: nitrokey::DeviceWrapper) -> crate::Result<()> { let mut ncli = Nitrocli::with_dev(device); -- cgit v1.2.1