2022-08-09 05:05:36 -04:00
|
|
|
#[cfg(all(feature = "gen_secret", feature = "otpauth"))]
|
2022-08-06 17:04:50 -04:00
|
|
|
use totp_rs::{Secret, TOTP, Algorithm};
|
|
|
|
|
2022-08-09 05:05:36 -04:00
|
|
|
#[cfg(all(feature = "gen_secret", feature = "otpauth"))]
|
2022-08-06 17:04:50 -04:00
|
|
|
fn main () {
|
|
|
|
|
2022-08-08 14:19:04 -04:00
|
|
|
let secret = Secret::generate_secret();
|
2022-08-06 17:04:50 -04:00
|
|
|
|
|
|
|
let totp = TOTP::new(
|
|
|
|
Algorithm::SHA1,
|
|
|
|
6,
|
|
|
|
1,
|
|
|
|
30,
|
2022-08-08 14:19:04 -04:00
|
|
|
secret.to_bytes().unwrap(),
|
2022-08-06 17:04:50 -04:00
|
|
|
None,
|
|
|
|
"account".to_string(),
|
|
|
|
).unwrap();
|
|
|
|
|
|
|
|
println!(
|
2022-08-08 14:19:04 -04:00
|
|
|
"secret raw: {} ; secret base32 {} ; code: {}",
|
2022-08-06 17:04:50 -04:00
|
|
|
secret,
|
2022-08-08 14:19:04 -04:00
|
|
|
secret.to_encoded(),
|
2022-08-06 17:04:50 -04:00
|
|
|
totp.generate_current().unwrap()
|
|
|
|
)
|
|
|
|
}
|
2022-08-09 05:05:36 -04:00
|
|
|
|
|
|
|
#[cfg(not(all(feature = "gen_secret", feature = "otpauth")))]
|
|
|
|
fn main () {}
|