aboutsummaryrefslogtreecommitdiff
path: root/nitrocli/src/main.rs
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2018-12-17 18:31:42 -0800
committerDaniel Mueller <deso@posteo.net>2018-12-17 18:31:42 -0800
commit97accf1ddd79bb69dfb74742a0518c40830657e4 (patch)
tree2e808cd031e70084f2ae7bce704bd7cab4956b5c /nitrocli/src/main.rs
parent953717e1648359baa8196ae32e01313b82f2561e (diff)
downloadnitrocli-97accf1ddd79bb69dfb74742a0518c40830657e4.tar.gz
nitrocli-97accf1ddd79bb69dfb74742a0518c40830657e4.tar.bz2
Make code conforming to rustfmt's expectations
An automated code formatter can help tremendously in reducing the amount of cognitive energy wasted on thinking about the "best" formatting of code as well as the number of nitpicks reviews typically get -- the format is machine checked (and enforced) and there is usually little to no discussion about the validity. To reach the goal of having such automated enforcement, we want to run the rustfmt tool as part of the CI pipeline. With rustfmt having reached 1.0 recently, the believe is that by now the formatting is reasonably stable and usable for this purpose. In that light, this change formats the code using rustfmt and prepares for such an automated style check.
Diffstat (limited to 'nitrocli/src/main.rs')
-rw-r--r--nitrocli/src/main.rs68
1 files changed, 34 insertions, 34 deletions
diff --git a/nitrocli/src/main.rs b/nitrocli/src/main.rs
index 8a8405a..c190d1b 100644
--- a/nitrocli/src/main.rs
+++ b/nitrocli/src/main.rs
@@ -54,7 +54,7 @@
unused_qualifications,
unused_results,
where_clauses_object_safety,
- while_true,
+ while_true
)]
#![warn(
bad_style,
@@ -62,7 +62,7 @@
nonstandard_style,
renamed_and_removed_lints,
rust_2018_compatibility,
- rust_2018_idioms,
+ rust_2018_idioms
)]
//! Nitrocli is a program providing a command line interface to certain
@@ -82,13 +82,11 @@ type Result<T> = result::Result<T, Error>;
const PIN_TYPE: pinentry::PinType = pinentry::PinType::User;
-
/// Create an `error::Error` with an error message of the format `msg: err`.
fn get_error(msg: &str, err: &nitrokey::CommandError) -> Error {
Error::Error(format!("{}: {:?}", msg, err))
}
-
/// Connect to a Nitrokey Storage device and return it.
fn get_storage_device() -> Result<nitrokey::Storage> {
nitrokey::Storage::connect()
@@ -108,37 +106,43 @@ fn get_volume_status(status: &nitrokey::VolumeStatus) -> &'static str {
}
}
-
/// Pretty print the response of a status command.
fn print_status(status: &nitrokey::StorageStatus) {
- println!("Status:");
// We omit displaying information about the smartcard here as this
// program really is only about the SD card portion of the device.
- println!(" SD card ID: {:#x}", status.serial_number_sd_card);
- println!(" firmware version: {}.{}",
- status.firmware_version_major,
- status.firmware_version_minor);
- println!(" firmware: {}",
- if status.firmware_locked {
- "locked".to_string()
- } else {
- "unlocked".to_string()
- });
- println!(" storage keys: {}",
- if status.stick_initialized {
- "created".to_string()
- } else {
- "not created".to_string()
- });
- println!(" user retry count: {}", status.user_retry_count);
- println!(" admin retry count: {}", status.admin_retry_count);
- println!(" volumes:");
- println!(" unencrypted: {}", get_volume_status(&status.unencrypted_volume));
- println!(" encrypted: {}", get_volume_status(&status.encrypted_volume));
- println!(" hidden: {}", get_volume_status(&status.hidden_volume));
+ println!(
+ r#"Status:
+ 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 {
+ "unlocked"
+ },
+ sk = if status.stick_initialized {
+ "created"
+ } 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),
+ );
}
-
/// Inquire the status of the nitrokey.
fn status() -> Result<()> {
let status = get_storage_device()?
@@ -149,7 +153,6 @@ fn status() -> Result<()> {
Ok(())
}
-
/// Open the encrypted volume on the nitrokey.
fn open() -> Result<()> {
let device = get_storage_device()?;
@@ -174,14 +177,13 @@ fn open() -> Result<()> {
}
let error = "Opening encrypted volume failed: Wrong password";
return Err(Error::Error(error.to_string()));
- },
+ }
err => return Err(get_error("Opening encrypted volume failed", &err)),
},
};
}
}
-
#[link(name = "c")]
extern "C" {
fn sync();
@@ -200,13 +202,11 @@ fn close() -> Result<()> {
.map_err(|err| get_error("Closing encrypted volume failed", &err))
}
-
/// Clear the PIN stored when opening the nitrokey's encrypted volume.
fn clear() -> Result<()> {
pinentry::clear_passphrase(PIN_TYPE)
}
-
// A macro for generating a match of the different supported commands.
// Each supplied command is converted into a string and matched against.
macro_rules! commands {