aboutsummaryrefslogtreecommitdiff
path: root/nitrocli/src/commands.rs
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2018-12-30 18:32:45 +0100
committerDaniel Mueller <deso@posteo.net>2019-01-01 17:14:58 -0800
commitcc3aa7f14eaec746e6718ef155a59e10c67a03fb (patch)
tree3d9c64d275236fa18b7b2d04eda54b6900b42fdb /nitrocli/src/commands.rs
parentfc4a8e12af694a40fe17bcebddd9e4617075400f (diff)
downloadnitrocli-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/commands.rs')
-rw-r--r--nitrocli/src/commands.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/nitrocli/src/commands.rs b/nitrocli/src/commands.rs
index e3e2a14..b018a58 100644
--- a/nitrocli/src/commands.rs
+++ b/nitrocli/src/commands.rs
@@ -507,6 +507,20 @@ fn choose_pin(pintype: pinentry::PinType) -> Result<String> {
}
}
+/// Change a PIN.
+pub fn pin_set(pintype: pinentry::PinType) -> Result<()> {
+ let device = get_device()?;
+ let new_pin = choose_pin(pintype)?;
+ try_with_passphrase(
+ pintype,
+ "Could not change the PIN",
+ |current_pin| match pintype {
+ pinentry::PinType::Admin => device.change_admin_pin(&current_pin, &new_pin),
+ pinentry::PinType::User => device.change_user_pin(&current_pin, &new_pin),
+ },
+ )
+}
+
/// Unblock and reset the user PIN.
pub fn pin_unblock() -> Result<()> {
let device = get_device()?;