summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nitrocli/src/args.rs22
-rw-r--r--nitrocli/src/commands.rs9
2 files changed, 30 insertions, 1 deletions
diff --git a/nitrocli/src/args.rs b/nitrocli/src/args.rs
index 9982d0f..28ccb1f 100644
--- a/nitrocli/src/args.rs
+++ b/nitrocli/src/args.rs
@@ -326,6 +326,7 @@ impl str::FromStr for PinCommand {
#[derive(Debug)]
enum PwsCommand {
+ Clear,
Get,
Set,
}
@@ -333,6 +334,7 @@ enum PwsCommand {
impl PwsCommand {
fn execute(&self, args: Vec<String>) -> Result<()> {
match *self {
+ PwsCommand::Clear => pws_clear(args),
PwsCommand::Get => pws_get(args),
PwsCommand::Set => pws_set(args),
}
@@ -345,6 +347,7 @@ impl fmt::Display for PwsCommand {
f,
"{}",
match *self {
+ PwsCommand::Clear => "clear",
PwsCommand::Get => "get",
PwsCommand::Set => "set",
}
@@ -357,6 +360,7 @@ impl str::FromStr for PwsCommand {
fn from_str(s: &str) -> result::Result<Self, Self::Err> {
match s {
+ "clear" => Ok(PwsCommand::Clear),
"get" => Ok(PwsCommand::Get),
"set" => Ok(PwsCommand::Set),
_ => Err(()),
@@ -800,7 +804,7 @@ fn pws(args: Vec<String>) -> Result<()> {
let _ = parser.refer(&mut subcommand).required().add_argument(
"subcommand",
argparse::Store,
- "The subcommand to execute (get|set)",
+ "The subcommand to execute (clear|get|set)",
);
let _ = parser.refer(&mut subargs).add_argument(
"arguments",
@@ -889,6 +893,22 @@ fn pws_set(args: Vec<String>) -> Result<()> {
commands::pws_set(slot, &name, &login, &password)
}
+/// Clear a PWS slot.
+fn pws_clear(args: Vec<String>) -> Result<()> {
+ let mut slot: u8 = 0;
+ let mut parser = argparse::ArgumentParser::new();
+ parser.set_description("Clears a password safe slot");
+ let _ = parser.refer(&mut slot).required().add_argument(
+ "slot",
+ argparse::Store,
+ "The PWS slot to clear",
+ );
+ parse(&parser, args)?;
+ drop(parser);
+
+ commands::pws_clear(slot)
+}
+
/// 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>)> {
diff --git a/nitrocli/src/commands.rs b/nitrocli/src/commands.rs
index e1c88c8..4deb1a7 100644
--- a/nitrocli/src/commands.rs
+++ b/nitrocli/src/commands.rs
@@ -593,6 +593,15 @@ pub fn pws_set(slot: u8, name: &str, login: &str, password: &str) -> Result<()>
.map_err(|err| get_error("Could not write PWS slot", &err))
}
+/// Clear a PWS slot.
+pub fn pws_clear(slot: u8) -> Result<()> {
+ let device = get_device()?;
+ let pws = get_password_safe(&device)?;
+ pws
+ .erase_slot(slot)
+ .map_err(|err| get_error("Could not clear PWS slot", &err))
+}
+
#[cfg(test)]
mod tests {
use super::*;