diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2018-12-30 18:32:45 +0100 |
---|---|---|
committer | Daniel Mueller <deso@posteo.net> | 2019-01-01 17:14:58 -0800 |
commit | cc3aa7f14eaec746e6718ef155a59e10c67a03fb (patch) | |
tree | 3d9c64d275236fa18b7b2d04eda54b6900b42fdb /nitrocli/src/pinentry.rs | |
parent | fc4a8e12af694a40fe17bcebddd9e4617075400f (diff) | |
download | nitrocli-cc3aa7f14eaec746e6718ef155a59e10c67a03fb.tar.gz nitrocli-cc3aa7f14eaec746e6718ef155a59e10c67a03fb.tar.bz2 |
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.
Diffstat (limited to 'nitrocli/src/pinentry.rs')
-rw-r--r-- | nitrocli/src/pinentry.rs | 27 |
1 files changed, 27 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>. * // ************************************************************************* +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<Self, Self::Err> { + match s { + "admin" => Ok(PinType::Admin), + "user" => Ok(PinType::User), + _ => Err(()), + } + } +} + impl PinType { fn cache_id(self) -> &'static str { match self { |