summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2020-01-28 17:38:47 +0100
committerRobin Krahl <robin.krahl@ireas.org>2020-02-03 11:30:57 +0100
commit4fb865af37093d9b0ee039d8ae48fb2a820f3760 (patch)
tree99a044ea081cfedc69bd0fc5b9e82e7a406234cc /tests
parentce4479b6f7a353f388aecda03cddc35389940252 (diff)
downloadnitrokey-rs-4fb865af37093d9b0ee039d8ae48fb2a820f3760.tar.gz
nitrokey-rs-4fb865af37093d9b0ee039d8ae48fb2a820f3760.tar.bz2
Represent serial numbers using SerialNumber struct
In a previous commit, we changed the serial number representation from a string to an integer. This made it easier to compare serial numbers, but also introduced new problems: - Serial numbers should be formatted consistently, for example as "{:#010x}". It is hard to ensure this for an integer value. - The format of the serial number may be subject to change. Users should not rely too much on the u32 representation. Therefore we introduce a new SerialNumber struct that represents a serial number. Currently it only stores a u32 value. The following traits and functions can be used to access its value: - FromStr for string parsing - ToString/Display for string formatting - as_u32 to access the underlying integer value
Diffstat (limited to 'tests')
-rw-r--r--tests/device.rs6
1 files changed, 3 insertions, 3 deletions
diff --git a/tests/device.rs b/tests/device.rs
index 2989941..1669d9d 100644
--- a/tests/device.rs
+++ b/tests/device.rs
@@ -10,7 +10,7 @@ use std::{thread, time};
use nitrokey::{
Authenticate, CommandError, CommunicationError, Config, ConfigureOtp, Device, DeviceInfo,
Error, GenerateOtp, GetPasswordSafe, LibraryError, OperationStatus, OtpMode, OtpSlotData,
- Storage, VolumeMode, DEFAULT_ADMIN_PIN, DEFAULT_USER_PIN,
+ SerialNumber, Storage, VolumeMode, DEFAULT_ADMIN_PIN, DEFAULT_USER_PIN,
};
use nitrokey_test::test as test_device;
@@ -47,7 +47,7 @@ fn list_devices(_device: DeviceWrapper) {
nitrokey::Model::Pro => {
assert!(device.serial_number.is_some());
let serial_number = device.serial_number.unwrap();
- assert!(serial_number != 0);
+ assert!(serial_number != SerialNumber::empty());
}
nitrokey::Model::Storage => {
assert_eq!(None, device.serial_number);
@@ -163,7 +163,7 @@ fn get_status(device: DeviceWrapper) {
#[test_device]
fn get_serial_number(device: DeviceWrapper) {
let serial_number = unwrap_ok!(device.get_serial_number());
- assert!(serial_number != 0);
+ assert!(serial_number != SerialNumber::empty());
}
#[test_device]