Show code lifetime

This commit is contained in:
Pierre HUBERT 2022-03-21 12:24:47 +01:00
parent 84d1a3cc9b
commit 5350b380e2

View File

@ -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());
}