Show code lifetime
This commit is contained in:
		
							
								
								
									
										11
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								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()); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user