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/commands.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'nitrocli/src/commands.rs') 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 { } } +/// 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(¤t_pin, &new_pin), + pinentry::PinType::User => device.change_user_pin(¤t_pin, &new_pin), + }, + ) +} + /// Unblock and reset the user PIN. pub fn pin_unblock() -> Result<()> { let device = get_device()?; -- cgit v1.2.3