aboutsummaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2018-05-22 00:32:12 +0000
committerRobin Krahl <robin.krahl@ireas.org>2018-05-22 02:35:28 +0200
commita9657c48c8c92f6c82834a2abd90e27904e2cf6b (patch)
tree6991987c5fd21a169a233c30b17706330ae085c6 /src/tests
parent2a736067581dd44288b43a01bf47e0d28801e0a8 (diff)
downloadnitrokey-rs-a9657c48c8c92f6c82834a2abd90e27904e2cf6b.tar.gz
nitrokey-rs-a9657c48c8c92f6c82834a2abd90e27904e2cf6b.tar.bz2
Restructure code by functionality
In future versions, we want to support not only the Nitrokey Pro, but also the Nitrokey Storage. This requires a better code layout. This patch introduces two main changes: First, the OTP-specific methods are moved from the Device trait and the AdminAuthenticatedDevice struct to the functionality-based traits ConfigureOtp and GenerateOtp. This will hopefully make it easier to integrate the Nitrokey Storage. Secondly, the code is split into separate modules. These modules are currently all private and re-exported in the lib module, but we can consider making them public in the future.
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/pro.rs19
1 files changed, 6 insertions, 13 deletions
diff --git a/src/tests/pro.rs b/src/tests/pro.rs
index e39c95a..ece94bf 100644
--- a/src/tests/pro.rs
+++ b/src/tests/pro.rs
@@ -1,7 +1,6 @@
use std::ffi::CStr;
-use std::marker::Sized;
-use {set_debug, AdminAuthenticatedDevice, CommandError, CommandStatus, Config, Device, Model,
- OtpMode, OtpSlotData, UnauthenticatedDevice};
+use {set_debug, AdminAuthenticatedDevice, CommandError, CommandStatus, Config, ConfigureOtp,
+ Device, GenerateOtp, Model, OtpMode, OtpSlotData, UnauthenticatedDevice};
static ADMIN_PASSWORD: &str = "12345678";
static ADMIN_NEW_PASSWORD: &str = "1234567890";
@@ -84,15 +83,12 @@ fn get_serial_number() {
assert!(serial_number.chars().all(|c| c.is_ascii_hexdigit()));
}
-fn configure_hotp(admin: &AdminAuthenticatedDevice) {
+fn configure_hotp(admin: &ConfigureOtp) {
let slot_data = OtpSlotData::new(1, "test-hotp", HOTP_SECRET, OtpMode::SixDigits);
assert_eq!(CommandStatus::Success, admin.write_hotp_slot(slot_data, 0));
}
-fn check_hotp_codes<T: Device>(device: &T)
-where
- T: Sized,
-{
+fn check_hotp_codes<T: GenerateOtp>(device: &T) {
for code in HOTP_CODES {
let result = device.get_hotp_code(1);
assert_eq!(code, &result.unwrap());
@@ -181,15 +177,12 @@ fn hotp_erase() {
assert_eq!("test2", device.get_hotp_slot_name(2).unwrap());
}
-fn configure_totp(admin: &AdminAuthenticatedDevice) {
+fn configure_totp(admin: &ConfigureOtp) {
let slot_data = OtpSlotData::new(1, "test-totp", TOTP_SECRET, OtpMode::EightDigits);
assert_eq!(CommandStatus::Success, admin.write_totp_slot(slot_data, 30));
}
-fn check_totp_codes<T: Device>(device: &T)
-where
- T: Sized,
-{
+fn check_totp_codes<T: Device + GenerateOtp>(device: &T) {
for (i, &(time, code)) in TOTP_CODES.iter().enumerate() {
assert_eq!(CommandStatus::Success, device.set_time(time));
let result = device.get_totp_code(1);