aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md5
-rw-r--r--Cargo.toml4
-rw-r--r--README.md2
-rw-r--r--TODO.md1
-rw-r--r--src/device.rs41
-rw-r--r--src/lib.rs17
-rw-r--r--tests/device.rs7
7 files changed, 55 insertions, 22 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index edc33f6..6c5ebf3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+# Unreleased
+- Remove the `test-pro` and `test-storage` features.
+- Implement `Display` for `Version`.
+- Introduce `DEFAULT_ADMIN_PIN` and `DEFAULT_USER_PIN` constants.
+
# v0.3.4 (2019-01-20)
- Fix authentication methods that assumed that `char` is signed.
diff --git a/Cargo.toml b/Cargo.toml
index 838ab45..99ddd0c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,10 +12,6 @@ categories = ["api-bindings"]
readme = "README.md"
license = "MIT"
-[features]
-test-pro = []
-test-storage = []
-
[dependencies]
libc = "0.2"
nitrokey-sys = "3.4"
diff --git a/README.md b/README.md
index 567ae58..0819c9d 100644
--- a/README.md
+++ b/README.md
@@ -30,6 +30,8 @@ supported by `nitrokey-rs`:
configuration).
- `NK_get_status_storage_as_string`. This method only provides an incomplete
string representation of the data returned by `NK_get_status_storage`.
+- `NK_is_AES_supported`. This method is no longer needed for Nitrokey devices
+ with a recent firmware version.
- `NK_set_unencrypted_volume_rorw_pin_type_user`,
`NK_set_unencrypted_read_only`, `NK_set_unencrypted_read_write`,
`NK_set_encrypted_read_only` and `NK_set_encrypted_read_write`. These
diff --git a/TODO.md b/TODO.md
index 28bd3b8..53de7e9 100644
--- a/TODO.md
+++ b/TODO.md
@@ -1,5 +1,4 @@
- Add support for the currently unsupported commands:
- - `NK_is_AES_supported`
- `NK_send_startup`
- `NK_fill_SD_card_with_random_data`
- `NK_get_SD_usage_data_as_string`
diff --git a/src/device.rs b/src/device.rs
index 9813c50..d794e1b 100644
--- a/src/device.rs
+++ b/src/device.rs
@@ -225,13 +225,26 @@ pub struct SdCardData {
pub manufacturer: u8,
}
-#[derive(Debug)]
-/// Production information for a Storage device.
-pub struct StorageProductionInfo {
+/// A firmware version for a Nitrokey device.
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub struct FirmwareVersion {
/// The major firmware version, e. g. 0 in v0.40.
- pub firmware_version_major: u8,
+ pub major: u8,
/// The minor firmware version, e. g. 40 in v0.40.
- pub firmware_version_minor: u8,
+ pub minor: u8,
+}
+
+impl fmt::Display for FirmwareVersion {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(f, "v{}.{}", self.major, self.minor)
+ }
+}
+
+/// Production information for a Storage device.
+#[derive(Debug)]
+pub struct StorageProductionInfo {
+ /// The firmware version.
+ pub firmware_version: FirmwareVersion,
/// The internal firmware version.
pub firmware_version_internal: u8,
/// The serial number of the CPU.
@@ -249,10 +262,8 @@ pub struct StorageStatus {
pub encrypted_volume: VolumeStatus,
/// The status of the hidden volume.
pub hidden_volume: VolumeStatus,
- /// The major firmware version, e. g. 0 in v0.40.
- pub firmware_version_major: u8,
- /// The minor firmware version, e. g. 40 in v0.40.
- pub firmware_version_minor: u8,
+ /// The firmware version.
+ pub firmware_version: FirmwareVersion,
/// Indicates whether the firmware is locked.
pub firmware_locked: bool,
/// The serial number of the SD card in the Storage stick.
@@ -1321,8 +1332,10 @@ impl GenerateOtp for Storage {}
impl From<nitrokey_sys::NK_storage_ProductionTest> for StorageProductionInfo {
fn from(data: nitrokey_sys::NK_storage_ProductionTest) -> Self {
Self {
- firmware_version_major: data.FirmwareVersion_au8[0],
- firmware_version_minor: data.FirmwareVersion_au8[1],
+ firmware_version: FirmwareVersion {
+ major: data.FirmwareVersion_au8[0],
+ minor: data.FirmwareVersion_au8[1],
+ },
firmware_version_internal: data.FirmwareVersionInternal_u8,
serial_number_cpu: data.CPU_CardID_u32,
sd_card: SdCardData {
@@ -1352,8 +1365,10 @@ impl From<nitrokey_sys::NK_storage_status> for StorageStatus {
read_only: status.hidden_volume_read_only,
active: status.hidden_volume_active,
},
- firmware_version_major: status.firmware_version_major,
- firmware_version_minor: status.firmware_version_minor,
+ firmware_version: FirmwareVersion {
+ major: status.firmware_version_major,
+ minor: status.firmware_version_minor,
+ },
firmware_locked: status.firmware_locked,
serial_number_sd_card: status.serial_number_sd_card,
serial_number_smart_card: status.serial_number_smart_card,
diff --git a/src/lib.rs b/src/lib.rs
index 02a622b..93a9894 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -93,6 +93,8 @@ mod otp;
mod pws;
mod util;
+use std::fmt;
+
use nitrokey_sys;
pub use crate::auth::{Admin, Authenticate, User};
@@ -105,6 +107,11 @@ pub use crate::otp::{ConfigureOtp, GenerateOtp, OtpMode, OtpSlotData};
pub use crate::pws::{GetPasswordSafe, PasswordSafe, SLOT_COUNT};
pub use crate::util::{CommandError, LogLevel};
+/// The default admin PIN for all Nitrokey devices.
+pub const DEFAULT_ADMIN_PIN: &'static str = "12345678";
+/// The default user PIN for all Nitrokey devices.
+pub const DEFAULT_USER_PIN: &'static str = "123456";
+
/// A version of the libnitrokey library.
///
/// Use the [`get_library_version`](fn.get_library_version.html) function to query the library
@@ -125,6 +132,16 @@ pub struct Version {
pub minor: u32,
}
+impl fmt::Display for Version {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ if self.git.is_empty() {
+ write!(f, "v{}.{}", self.major, self.minor)
+ } else {
+ f.write_str(&self.git)
+ }
+ }
+}
+
/// Enables or disables debug output. Calling this method with `true` is equivalent to setting the
/// log level to `Debug`; calling it with `false` is equivalent to the log level `Error` (see
/// [`set_log_level`][]).
diff --git a/tests/device.rs b/tests/device.rs
index 849d2ff..abede67 100644
--- a/tests/device.rs
+++ b/tests/device.rs
@@ -441,8 +441,8 @@ fn get_storage_status(device: Storage) {
#[test_device]
fn get_production_info(device: Storage) {
let info = device.get_production_info().unwrap();
- assert_eq!(0, info.firmware_version_major);
- assert!(info.firmware_version_minor != 0);
+ assert_eq!(0, info.firmware_version.major);
+ assert!(info.firmware_version.minor != 0);
assert!(info.serial_number_cpu != 0);
assert!(info.sd_card.serial_number != 0);
assert!(info.sd_card.size > 0);
@@ -454,8 +454,7 @@ fn get_production_info(device: Storage) {
assert!(info.sd_card.manufacturer != 0);
let status = device.get_status().unwrap();
- assert_eq!(status.firmware_version_major, info.firmware_version_major);
- assert_eq!(status.firmware_version_minor, info.firmware_version_minor);
+ assert_eq!(status.firmware_version, info.firmware_version);
assert_eq!(status.serial_number_sd_card, info.sd_card.serial_number);
}