From f3c13434e91eea3bcceaa95b86bfcd0db1ec56d4 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Tue, 25 Dec 2018 10:39:06 +0100 Subject: Implement the config get subcommand This change implements the config get subcommand. The subcommand reads the device configuration and prints it. --- nitrocli/src/commands.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'nitrocli/src/commands.rs') diff --git a/nitrocli/src/commands.rs b/nitrocli/src/commands.rs index 528fa99..8ce1076 100644 --- a/nitrocli/src/commands.rs +++ b/nitrocli/src/commands.rs @@ -17,6 +17,7 @@ // * along with this program. If not, see . * // ************************************************************************* +use std::fmt; use std::result; use nitrokey::ConfigureOtp; @@ -276,6 +277,33 @@ pub fn clear() -> Result<()> { Ok(()) } +/// Return a String representation of the given Option. +fn format_option(option: Option) -> String { + match option { + Some(value) => format!("{}", value), + None => "not set".to_string(), + } +} + +/// Read the Nitrokey configuration. +pub fn config_get() -> Result<()> { + let config = get_device()? + .get_config() + .map_err(|err| get_error("Could not get configuration", &err))?; + println!( + r#"Config: + numlock binding: {nl} + capslock binding: {cl} + scrollock binding: {sl} + require user PIN for OTP: {otp}"#, + nl = format_option(config.numlock), + cl = format_option(config.capslock), + sl = format_option(config.scrollock), + otp = config.user_password, + ); + Ok(()) +} + fn get_otp(slot: u8, algorithm: args::OtpAlgorithm, device: &T) -> Result { match algorithm { args::OtpAlgorithm::Hotp => device.get_hotp_code(slot), -- cgit v1.2.1