From c0dc9686110dda2ba1918e7744b8c8d6063b6bd1 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sat, 2 Feb 2019 22:11:21 +0000 Subject: Use nitrokey::DEFAULT_{ADMIN,USER}_PIN constants MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since version 0.4.0, nitrokey provides the default admin and user PIN as constants. This patch removes the constants from nitrocli and uses nitrokey’s constant instead. --- nitrocli/src/commands.rs | 4 +--- nitrocli/src/tests/mod.rs | 13 ++++--------- nitrocli/src/tests/pin.rs | 8 +++++--- nitrocli/src/tests/reset.rs | 4 ++-- 4 files changed, 12 insertions(+), 17 deletions(-) (limited to 'nitrocli/src') diff --git a/nitrocli/src/commands.rs b/nitrocli/src/commands.rs index 51b37ca..5deefa2 100644 --- a/nitrocli/src/commands.rs +++ b/nitrocli/src/commands.rs @@ -34,8 +34,6 @@ use crate::error::Error; use crate::pinentry; use crate::Result; -const NITROKEY_DEFAULT_ADMIN_PIN: &str = "12345678"; - /// Create an `error::Error` with an error message of the format `msg: err`. fn get_error(msg: &'static str, err: nitrokey::Error) -> Error { Error::NitrokeyError(Some(msg), err) @@ -382,7 +380,7 @@ pub fn reset(ctx: &mut args::ExecCtx<'_>) -> Result<()> { // build_aes_key after a factory reset on Pro devices. // https://github.com/Nitrokey/nitrokey-pro-firmware/issues/57 let _ = device.get_user_retry_count(); - device.build_aes_key(NITROKEY_DEFAULT_ADMIN_PIN) + device.build_aes_key(nitrokey::DEFAULT_ADMIN_PIN) }) }) } diff --git a/nitrocli/src/tests/mod.rs b/nitrocli/src/tests/mod.rs index 2f2926f..7b4b661 100644 --- a/nitrocli/src/tests/mod.rs +++ b/nitrocli/src/tests/mod.rs @@ -22,11 +22,6 @@ use std::fmt; use nitrokey_test::test as test_device; -// TODO: Those defines should potentially be taken from the `nitrokey` -// crate, once exported. -const NITROKEY_DEFAULT_ADMIN_PIN: &str = "12345678"; -const NITROKEY_DEFAULT_USER_PIN: &str = "123456"; - // TODO: This is a hack to make the nitrokey-test crate work across // module boundaries. Upon first use of the nitrokey_test::test // macro a new function, __nitrokey_mutex, will be emitted, but it @@ -88,8 +83,8 @@ impl Nitrocli { pub fn new() -> Self { Self { model: None, - admin_pin: Some(NITROKEY_DEFAULT_ADMIN_PIN.into()), - user_pin: Some(NITROKEY_DEFAULT_USER_PIN.into()), + admin_pin: Some(nitrokey::DEFAULT_ADMIN_PIN.into()), + user_pin: Some(nitrokey::DEFAULT_USER_PIN.into()), new_admin_pin: None, new_user_pin: None, password: None, @@ -102,8 +97,8 @@ impl Nitrocli { { let result = Self { model: Some(device.get_model()), - admin_pin: Some(NITROKEY_DEFAULT_ADMIN_PIN.into()), - user_pin: Some(NITROKEY_DEFAULT_USER_PIN.into()), + admin_pin: Some(nitrokey::DEFAULT_ADMIN_PIN.into()), + user_pin: Some(nitrokey::DEFAULT_USER_PIN.into()), new_admin_pin: None, new_user_pin: None, password: Some("1234567".into()), diff --git a/nitrocli/src/tests/pin.rs b/nitrocli/src/tests/pin.rs index fe61b2d..91a9d66 100644 --- a/nitrocli/src/tests/pin.rs +++ b/nitrocli/src/tests/pin.rs @@ -46,19 +46,21 @@ fn set_user(device: nitrokey::DeviceWrapper) -> crate::Result<()> { let device = nitrokey::connect_model(ncli.model().unwrap())?; let (device, err) = device - .authenticate_user(NITROKEY_DEFAULT_USER_PIN) + .authenticate_user(nitrokey::DEFAULT_USER_PIN) .unwrap_err(); assert_eq!(err, nitrokey::CommandError::WrongPassword); drop(device); // Revert to the default user PIN. ncli.user_pin("new-pin"); - ncli.new_user_pin(NITROKEY_DEFAULT_USER_PIN); + ncli.new_user_pin(nitrokey::DEFAULT_USER_PIN); let out = ncli.handle(&["pin", "set", "user"])?; assert!(out.is_empty()); let device = nitrokey::connect_model(ncli.model().unwrap())?; - let _ = device.authenticate_user(NITROKEY_DEFAULT_USER_PIN).unwrap(); + let _ = device + .authenticate_user(nitrokey::DEFAULT_USER_PIN) + .unwrap(); Ok(()) } diff --git a/nitrocli/src/tests/reset.rs b/nitrocli/src/tests/reset.rs index 2e567fa..12d7023 100644 --- a/nitrocli/src/tests/reset.rs +++ b/nitrocli/src/tests/reset.rs @@ -43,12 +43,12 @@ fn reset(device: nitrokey::DeviceWrapper) -> crate::Result<()> { // Check that the admin PIN has been reset. let device = nitrokey::connect_model(ncli.model().unwrap())?; let device = device - .authenticate_admin(NITROKEY_DEFAULT_ADMIN_PIN) + .authenticate_admin(nitrokey::DEFAULT_ADMIN_PIN) .unwrap(); // Check that the password store works, i.e., the AES key has been // built. - let _ = device.get_password_safe(NITROKEY_DEFAULT_USER_PIN)?; + let _ = device.get_password_safe(nitrokey::DEFAULT_USER_PIN)?; Ok(()) } -- cgit v1.2.1