From fc4a8e12af694a40fe17bcebddd9e4617075400f Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sun, 30 Dec 2018 18:39:31 +0100 Subject: Implement the pin unblock subcommand This patch implements the pin unblock command that unblocks and resets the user PIN. The name unblock is chosen over libnitrokey's unlock to be consistent with the GnuPG terminology and to avoid confusion with the unrelated lock command. --- nitrocli/src/args.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'nitrocli/src/args.rs') diff --git a/nitrocli/src/args.rs b/nitrocli/src/args.rs index edfd811..4341235 100644 --- a/nitrocli/src/args.rs +++ b/nitrocli/src/args.rs @@ -278,12 +278,14 @@ impl From for nitrokey::OtpMode { #[derive(Debug)] enum PinCommand { Clear, + Unblock, } impl PinCommand { fn execute(&self, args: Vec) -> Result<()> { match *self { PinCommand::Clear => pin_clear(args), + PinCommand::Unblock => pin_unblock(args), } } } @@ -295,6 +297,7 @@ impl fmt::Display for PinCommand { "{}", match *self { PinCommand::Clear => "clear", + PinCommand::Unblock => "unblock", } ) } @@ -306,6 +309,7 @@ impl str::FromStr for PinCommand { fn from_str(s: &str) -> result::Result { match s { "clear" => Ok(PinCommand::Clear), + "unblock" => Ok(PinCommand::Unblock), _ => Err(()), } } @@ -689,7 +693,7 @@ fn pin(args: Vec) -> Result<()> { let _ = parser.refer(&mut subcommand).required().add_argument( "subcommand", argparse::Store, - "The subcommand to execute (clear)", + "The subcommand to execute (clear|unblock)", ); let _ = parser.refer(&mut subargs).add_argument( "arguments", @@ -713,6 +717,15 @@ fn pin_clear(args: Vec) -> Result<()> { commands::pin_clear() } +/// Unblock and reset the user PIN. +fn pin_unblock(args: Vec) -> Result<()> { + let mut parser = argparse::ArgumentParser::new(); + parser.set_description("Unblocks and resets the user PIN"); + parse(&parser, args)?; + + commands::pin_unblock() +} + /// Parse the command-line arguments and return the selected command and /// the remaining arguments for the command. fn parse_arguments(args: Vec) -> Result<(Command, Vec)> { -- cgit v1.2.1