From cc3aa7f14eaec746e6718ef155a59e10c67a03fb Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sun, 30 Dec 2018 18:32:45 +0100 Subject: Implement the pin set command This change implements the pin set command which can be used to change a Nitrokey's user or admin PIN. --- nitrocli/src/pinentry.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'nitrocli/src/pinentry.rs') diff --git a/nitrocli/src/pinentry.rs b/nitrocli/src/pinentry.rs index 33b5266..0d9fc5f 100644 --- a/nitrocli/src/pinentry.rs +++ b/nitrocli/src/pinentry.rs @@ -17,7 +17,9 @@ // * along with this program. If not, see . * // ************************************************************************* +use std::fmt; use std::process; +use std::str; use crate::error::Error; @@ -33,6 +35,31 @@ pub enum PinType { User, } +impl fmt::Display for PinType { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "{}", + match *self { + PinType::Admin => "admin", + PinType::User => "user", + } + ) + } +} + +impl str::FromStr for PinType { + type Err = (); + + fn from_str(s: &str) -> Result { + match s { + "admin" => Ok(PinType::Admin), + "user" => Ok(PinType::User), + _ => Err(()), + } + } +} + impl PinType { fn cache_id(self) -> &'static str { match self { -- cgit v1.2.1