aboutsummaryrefslogtreecommitdiff
path: root/nitrocli/src/commands.rs
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2018-12-28 11:01:08 -0800
committerDaniel Mueller <deso@posteo.net>2018-12-28 11:01:08 -0800
commitfb235d0cf88687eb214b3ec7cb5fab596609d2b6 (patch)
treedcc3e8f6dbeea60a42685c9030100e22f4dcc7b1 /nitrocli/src/commands.rs
parent8f8f6b11f353f12b8a4018b8bc25aa02bc914955 (diff)
downloadnitrocli-fb235d0cf88687eb214b3ec7cb5fab596609d2b6.tar.gz
nitrocli-fb235d0cf88687eb214b3ec7cb5fab596609d2b6.tar.bz2
Move printing of storage related status into 'storage status' sub-command
The 'status' command has traditionally printed information about the connected Nitrokey and that included storage specific data if the device present is a Nitrokey Storage. Given that we have a root-level 'storage' command it arguably makes sense to move the printing of the storage related status information into a 'status' sub-command of the said command, which makes the output more predictable.
Diffstat (limited to 'nitrocli/src/commands.rs')
-rw-r--r--nitrocli/src/commands.rs76
1 files changed, 40 insertions, 36 deletions
diff --git a/nitrocli/src/commands.rs b/nitrocli/src/commands.rs
index fdfe049..17426cd 100644
--- a/nitrocli/src/commands.rs
+++ b/nitrocli/src/commands.rs
@@ -197,34 +197,6 @@ fn print_status(model: &'static str, device: &nitrokey::DeviceWrapper) -> Result
Ok(())
}
-/// Pretty print the status of a Nitrokey Storage.
-fn print_storage_status(status: &nitrokey::StorageStatus) {
- println!(
- r#"
- SD card ID: {id:#x}
- firmware: {fw}
- storage keys: {sk}
- volumes:
- unencrypted: {vu}
- encrypted: {ve}
- hidden: {vh}"#,
- id = status.serial_number_sd_card,
- fw = if status.firmware_locked {
- "locked"
- } else {
- "unlocked"
- },
- sk = if status.stick_initialized {
- "created"
- } else {
- "not created"
- },
- vu = get_volume_status(&status.unencrypted_volume),
- ve = get_volume_status(&status.encrypted_volume),
- vh = get_volume_status(&status.hidden_volume),
- );
-}
-
/// Inquire the status of the nitrokey.
pub fn status() -> Result<()> {
let device = get_device()?;
@@ -232,14 +204,7 @@ pub fn status() -> Result<()> {
nitrokey::DeviceWrapper::Pro(_) => "Pro",
nitrokey::DeviceWrapper::Storage(_) => "Storage",
};
- print_status(model, &device)?;
- if let nitrokey::DeviceWrapper::Storage(storage) = device {
- let status = storage
- .get_status()
- .map_err(|err| get_error("Getting Storage status failed", &err))?;
- print_storage_status(&status);
- }
- Ok(())
+ print_status(model, &device)
}
/// Open the encrypted volume on the nitrokey.
@@ -270,6 +235,45 @@ pub fn storage_close() -> Result<()> {
.map_err(|err| get_error("Closing encrypted volume failed", &err))
}
+/// Pretty print the status of a Nitrokey Storage.
+fn print_storage_status(status: &nitrokey::StorageStatus) {
+ println!(
+ r#"Status:
+ SD card ID: {id:#x}
+ firmware: {fw}
+ storage keys: {sk}
+ volumes:
+ unencrypted: {vu}
+ encrypted: {ve}
+ hidden: {vh}"#,
+ id = status.serial_number_sd_card,
+ fw = if status.firmware_locked {
+ "locked"
+ } else {
+ "unlocked"
+ },
+ sk = if status.stick_initialized {
+ "created"
+ } else {
+ "not created"
+ },
+ vu = get_volume_status(&status.unencrypted_volume),
+ ve = get_volume_status(&status.encrypted_volume),
+ vh = get_volume_status(&status.hidden_volume),
+ );
+}
+
+/// Connect to and pretty print the status of a Nitrokey Storage.
+pub fn storage_status() -> Result<()> {
+ let device = get_storage_device()?;
+ let status = device
+ .get_status()
+ .map_err(|err| get_error("Getting Storage status failed", &err))?;
+
+ print_storage_status(&status);
+ Ok(())
+}
+
/// Clear the PIN stored when opening the nitrokey's encrypted volume.
pub fn clear() -> Result<()> {
pinentry::clear_passphrase(pinentry::PinType::Admin)?;