aboutsummaryrefslogtreecommitdiff
path: root/nitrocli/src
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-02-02 22:11:21 +0000
committerRobin Krahl <robin.krahl@ireas.org>2019-07-14 13:52:51 +0000
commitc0dc9686110dda2ba1918e7744b8c8d6063b6bd1 (patch)
tree55b2a04b59a1b1b681594dfa8b0563b989be7c86 /nitrocli/src
parent0d34f3075ff5807cb58e2e1a28a338aadeb9177c (diff)
downloadnitrocli-c0dc9686110dda2ba1918e7744b8c8d6063b6bd1.tar.gz
nitrocli-c0dc9686110dda2ba1918e7744b8c8d6063b6bd1.tar.bz2
Use nitrokey::DEFAULT_{ADMIN,USER}_PIN constants
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.
Diffstat (limited to 'nitrocli/src')
-rw-r--r--nitrocli/src/commands.rs4
-rw-r--r--nitrocli/src/tests/mod.rs13
-rw-r--r--nitrocli/src/tests/pin.rs8
-rw-r--r--nitrocli/src/tests/reset.rs4
4 files changed, 12 insertions, 17 deletions
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(())
}