diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2018-12-24 02:06:27 +0100 |
---|---|---|
committer | Daniel Mueller <deso@posteo.net> | 2018-12-27 10:32:24 -0800 |
commit | b2bbb614963dc2517e17587bd7db00feea8f26f9 (patch) | |
tree | 92648d19914c511bb7bf20b0a45d26972d106873 | |
parent | 4f09ff350cf593330d656fc7036b58c66d055d37 (diff) | |
download | nitrocli-b2bbb614963dc2517e17587bd7db00feea8f26f9.tar.gz nitrocli-b2bbb614963dc2517e17587bd7db00feea8f26f9.tar.bz2 |
Extract print_status from print_storage_status function
This patch extracts the print_status function that prints the status
fields common to all supported Nitrokey devices from the
print_storage_status function.
-rw-r--r-- | nitrocli/src/commands.rs | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/nitrocli/src/commands.rs b/nitrocli/src/commands.rs index 1fbeb79..c4d4598 100644 --- a/nitrocli/src/commands.rs +++ b/nitrocli/src/commands.rs @@ -171,25 +171,51 @@ where .map_err(|(_data, err)| err) } +/// Pretty print the status that is common to all Nitrokey devices. +fn print_status( + model: &'static str, + smartcard_id: &str, + firmware_major: i32, + firmware_minor: i32, + user_retries: u8, + admin_retries: u8, +) { + println!( + r#"Status: + model: {model} + smart card ID: {id} + firmware version: {fwv0}.{fwv1} + user retry count: {urc} + admin retry count: {arc}"#, + model = model, + id = smartcard_id, + fwv0 = firmware_major, + fwv1 = firmware_minor, + urc = user_retries, + arc = admin_retries, + ); +} + /// Pretty print the response of a status command for the Nitrokey Storage. fn print_storage_status(status: &nitrokey::StorageStatus) { - // We omit displaying information about the smartcard here as this - // program really is only about the SD card portion of the device. + print_status( + "Storage", + &format!("{:#x}", status.serial_number_smart_card), + status.firmware_version_major as i32, + status.firmware_version_minor as i32, + status.user_retry_count, + status.admin_retry_count, + ); println!( - r#"Status: + r#" SD card ID: {id:#x} - firmware version: {fwv0}.{fwv1} firmware: {fw} storage keys: {sk} - user retry count: {urc} - admin retry count: {arc} volumes: unencrypted: {vu} encrypted: {ve} hidden: {vh}"#, id = status.serial_number_sd_card, - fwv0 = status.firmware_version_major, - fwv1 = status.firmware_version_minor, fw = if status.firmware_locked { "locked" } else { @@ -200,8 +226,6 @@ fn print_storage_status(status: &nitrokey::StorageStatus) { } else { "not created" }, - urc = status.user_retry_count, - arc = status.admin_retry_count, vu = get_volume_status(&status.unencrypted_volume), ve = get_volume_status(&status.encrypted_volume), vh = get_volume_status(&status.hidden_volume), |