aboutsummaryrefslogtreecommitdiff
path: root/nitrocli/src/commands.rs
diff options
context:
space:
mode:
Diffstat (limited to 'nitrocli/src/commands.rs')
-rw-r--r--nitrocli/src/commands.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/nitrocli/src/commands.rs b/nitrocli/src/commands.rs
index 4deb1a7..c903cfd 100644
--- a/nitrocli/src/commands.rs
+++ b/nitrocli/src/commands.rs
@@ -20,6 +20,7 @@
use std::fmt;
use std::result;
use std::time;
+use std::u8;
use nitrokey::ConfigureOtp;
use nitrokey::Device;
@@ -602,6 +603,40 @@ pub fn pws_clear(slot: u8) -> Result<()> {
.map_err(|err| get_error("Could not clear PWS slot", &err))
}
+fn print_pws_slot(pws: &nitrokey::PasswordSafe<'_>, slot: usize, programmed: bool) -> Result<()> {
+ if slot > u8::MAX as usize {
+ return Err(Error::Error("Invalid PWS slot number".to_string()));
+ }
+ let slot = slot as u8;
+ let name = if programmed {
+ pws
+ .get_slot_name(slot)
+ .map_err(|err| get_error("Could not read PWS slot", &err))?
+ } else {
+ "[not programmed]".to_string()
+ };
+ println!("{}\t{}", slot, name);
+ Ok(())
+}
+
+/// Print the status of all PWS slots.
+pub fn pws_status(all: bool) -> Result<()> {
+ let device = get_device()?;
+ let pws = get_password_safe(&device)?;
+ let slots = pws
+ .get_slot_status()
+ .map_err(|err| get_error("Could not read PWS slot status", &err))?;
+ println!("slot\tname");
+ for (i, &value) in slots
+ .into_iter()
+ .enumerate()
+ .filter(|(_, &value)| all || value)
+ {
+ print_pws_slot(&pws, i, value)?;
+ }
+ Ok(())
+}
+
#[cfg(test)]
mod tests {
use super::*;