Show code lifetime
This commit is contained in:
parent
84d1a3cc9b
commit
5350b380e2
11
src/main.rs
11
src/main.rs
@ -1,7 +1,15 @@
|
|||||||
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
use base32::Alphabet;
|
use base32::Alphabet;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use totp_rfc6238::{HashAlgorithm, TotpGenerator};
|
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
|
/// TOTP - One Time Password generator
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[clap(author, version, about, long_about = None)]
|
#[clap(author, version, about, long_about = None)]
|
||||||
@ -32,7 +40,10 @@ fn main() {
|
|||||||
Alphabet::RFC4648 { padding: true },
|
Alphabet::RFC4648 { padding: true },
|
||||||
&args.secret,
|
&args.secret,
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
let code = totp_generator.get_code(&key);
|
let code = totp_generator.get_code(&key);
|
||||||
|
let next_update = totp_generator.get_next_update_time().unwrap();
|
||||||
|
|
||||||
println!("Secret = {}", code);
|
println!("Secret = {}", code);
|
||||||
|
println!("Next update = {} seconds", next_update - time());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user