From 5350b380e287951afd143d8954fdac76413f81a0 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Mon, 21 Mar 2022 12:24:47 +0100 Subject: [PATCH] Show code lifetime --- src/main.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main.rs b/src/main.rs index 43fbe60..4e092bf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,15 @@ +use std::time::{SystemTime, UNIX_EPOCH}; + use base32::Alphabet; use clap::Parser; use totp_rfc6238::{HashAlgorithm, TotpGenerator}; +/// Get the current time since epoch +pub fn time() -> u64 { + SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs() +} + + /// TOTP - One Time Password generator #[derive(Parser, Debug)] #[clap(author, version, about, long_about = None)] @@ -32,7 +40,10 @@ fn main() { Alphabet::RFC4648 { padding: true }, &args.secret, ).unwrap(); + let code = totp_generator.get_code(&key); + let next_update = totp_generator.get_next_update_time().unwrap(); println!("Secret = {}", code); + println!("Next update = {} seconds", next_update - time()); }