From b7b9c6f3591e1ef28371d42229053b5368e79b7d Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sun, 23 Dec 2018 02:19:00 +0100 Subject: Implement the otp clear subcommand This patch implements the `otp clear` subcommand that erases an OTP slot. --- nitrocli/src/commands.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'nitrocli/src/commands.rs') diff --git a/nitrocli/src/commands.rs b/nitrocli/src/commands.rs index 8dc8c42..93e9bd3 100644 --- a/nitrocli/src/commands.rs +++ b/nitrocli/src/commands.rs @@ -322,6 +322,17 @@ pub fn otp_set( Ok(()) } +/// Clear an OTP slot. +pub fn otp_clear(slot: u8, algorithm: args::OtpAlgorithm) -> Result<()> { + let device = authenticate_admin(get_device()?)?; + match algorithm { + args::OtpAlgorithm::Hotp => device.erase_hotp_slot(slot), + args::OtpAlgorithm::Totp => device.erase_totp_slot(slot), + } + .map_err(|err| get_error("Could not clear OTP slot", &err))?; + Ok(()) +} + #[cfg(test)] mod tests { use super::*; -- cgit v1.2.1