diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2018-12-27 15:55:03 +0100 |
---|---|---|
committer | Daniel Mueller <deso@posteo.net> | 2019-01-07 18:13:32 -0800 |
commit | c8db48074625680030fd8364097cc1a68f852b9d (patch) | |
tree | 98830fe1d926f11a41dcb93258343cdfa26dcf28 /nitrocli | |
parent | 696d9fb4164c2c92fa614030c18a4216e7bd4c13 (diff) | |
download | nitrocli-c8db48074625680030fd8364097cc1a68f852b9d.tar.gz nitrocli-c8db48074625680030fd8364097cc1a68f852b9d.tar.bz2 |
Implement the pws command
This patch adds the basic structure for the pws command that can be used
to access the password safe on the Nitrokey Pro and Nitrokey Storage.
Diffstat (limited to 'nitrocli')
-rw-r--r-- | nitrocli/CHANGELOG.md | 5 | ||||
-rw-r--r-- | nitrocli/src/args.rs | 66 |
2 files changed, 70 insertions, 1 deletions
diff --git a/nitrocli/CHANGELOG.md b/nitrocli/CHANGELOG.md index 1b24ba2..f582461 100644 --- a/nitrocli/CHANGELOG.md +++ b/nitrocli/CHANGELOG.md @@ -1,3 +1,8 @@ +Unreleased +---------- +- Added the `pws` command for accessing the password safe + + 0.2.0 ----- - Use the `nitrokey` crate for the `open`, `close`, and `status` diff --git a/nitrocli/src/args.rs b/nitrocli/src/args.rs index f00ac2a..df7f56c 100644 --- a/nitrocli/src/args.rs +++ b/nitrocli/src/args.rs @@ -34,6 +34,7 @@ pub enum Command { Config, Otp, Pin, + Pws, Status, Storage, } @@ -45,6 +46,7 @@ impl Command { Command::Config => config(args), Command::Otp => otp(args), Command::Pin => pin(args), + Command::Pws => pws(args), Command::Status => status(args), Command::Storage => storage(args), } @@ -60,6 +62,7 @@ impl fmt::Display for Command { Command::Config => "config", Command::Otp => "otp", Command::Pin => "pin", + Command::Pws => "pws", Command::Status => "status", Command::Storage => "storage", } @@ -75,6 +78,7 @@ impl str::FromStr for Command { "config" => Ok(Command::Config), "otp" => Ok(Command::Otp), "pin" => Ok(Command::Pin), + "pws" => Ok(Command::Pws), "status" => Ok(Command::Status), "storage" => Ok(Command::Storage), _ => Err(()), @@ -320,6 +324,42 @@ impl str::FromStr for PinCommand { } } +#[derive(Debug)] +enum PwsCommand { + Get, +} + +impl PwsCommand { + fn execute(&self, _args: Vec<String>) -> Result<()> { + match *self { + PwsCommand::Get => Err(Error::Error("Not implemented".to_string())), + } + } +} + +impl fmt::Display for PwsCommand { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "{}", + match *self { + PwsCommand::Get => "get", + } + ) + } +} + +impl str::FromStr for PwsCommand { + type Err = (); + + fn from_str(s: &str) -> result::Result<Self, Self::Err> { + match s { + "get" => Ok(PwsCommand::Get), + _ => Err(()), + } + } +} + fn parse(parser: &argparse::ArgumentParser<'_>, args: Vec<String>) -> Result<()> { if let Err(err) = parser.parse(args, &mut io::stdout(), &mut io::stderr()) { Err(Error::ArgparseError(err)) @@ -747,6 +787,30 @@ fn pin_unblock(args: Vec<String>) -> Result<()> { commands::pin_unblock() } +/// Execute a PWS subcommand. +fn pws(args: Vec<String>) -> Result<()> { + let mut subcommand = PwsCommand::Get; + let mut subargs = vec![]; + let mut parser = argparse::ArgumentParser::new(); + parser.set_description("Accesses the password safe"); + let _ = parser.refer(&mut subcommand).required().add_argument( + "subcommand", + argparse::Store, + "The subcommand to execute (get)", + ); + let _ = parser.refer(&mut subargs).add_argument( + "arguments", + argparse::List, + "The arguments for the subcommand", + ); + parser.stop_on_first_argument(true); + parse(&parser, args)?; + drop(parser); + + subargs.insert(0, format!("nitrocli pws {}", subcommand)); + subcommand.execute(subargs) +} + /// Parse the command-line arguments and return the selected command and /// the remaining arguments for the command. fn parse_arguments(args: Vec<String>) -> Result<(Command, Vec<String>)> { @@ -757,7 +821,7 @@ fn parse_arguments(args: Vec<String>) -> Result<(Command, Vec<String>)> { let _ = parser.refer(&mut command).required().add_argument( "command", argparse::Store, - "The command to execute (config|otp|pin|status|storage)", + "The command to execute (config|otp|pin|pws|status|storage)", ); let _ = parser.refer(&mut subargs).add_argument( "arguments", |