aboutsummaryrefslogtreecommitdiff
path: root/nitrocli/src/args.rs
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2018-12-31 00:06:06 +0100
committerDaniel Mueller <deso@posteo.net>2019-01-01 17:14:43 -0800
commitec298ea1fc7d2339ef44d283644d6ee2ebcd54bd (patch)
treeae93437a53105bf3075c1812d77970ab4e0fc771 /nitrocli/src/args.rs
parentcf7218436686ed06852836e79e89971ac4f34c8e (diff)
downloadnitrocli-ec298ea1fc7d2339ef44d283644d6ee2ebcd54bd.tar.gz
nitrocli-ec298ea1fc7d2339ef44d283644d6ee2ebcd54bd.tar.bz2
Set the time before generating a TOTP
This patch changes the otp get command to set the Nitrokey's time before generating a one-time password using the TOTP algorithm. Per default, it sets the time to the current system time. If the --time option is set, it uses its value instead. See issue #34 [0] for a discussion of this change. [0] https://github.com/d-e-s-o/nitrocli/issues/34
Diffstat (limited to 'nitrocli/src/args.rs')
-rw-r--r--nitrocli/src/args.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/nitrocli/src/args.rs b/nitrocli/src/args.rs
index e533c82..b4733f6 100644
--- a/nitrocli/src/args.rs
+++ b/nitrocli/src/args.rs
@@ -204,7 +204,7 @@ impl str::FromStr for OtpCommand {
}
}
-#[derive(Clone, Copy, Debug)]
+#[derive(Clone, Copy, Debug, PartialEq)]
pub enum OtpAlgorithm {
Hotp,
Totp,
@@ -525,6 +525,7 @@ fn otp(args: Vec<String>) -> Result<()> {
fn otp_get(args: Vec<String>) -> Result<()> {
let mut slot: u8 = 0;
let mut algorithm = OtpAlgorithm::Totp;
+ let mut time: Option<u64> = None;
let mut parser = argparse::ArgumentParser::new();
parser.set_description("Generates a one-time password");
let _ =
@@ -537,10 +538,15 @@ fn otp_get(args: Vec<String>) -> Result<()> {
argparse::Store,
"The OTP algorithm to use (hotp|totp)",
);
+ let _ = parser.refer(&mut time).add_option(
+ &["-t", "--time"],
+ argparse::StoreOption,
+ "The time to use for TOTP generation (Unix timestamp, default: system time)",
+ );
parse(&parser, args)?;
drop(parser);
- commands::otp_get(slot, algorithm)
+ commands::otp_get(slot, algorithm, time)
}
/// Configure a one-time password slot on the Nitrokey device.