rfc_6238/
rfc-6238.rs

1use totp_rs::{Rfc6238, TOTP};
2
3#[cfg(feature = "otpauth")]
4fn main() {
5    let mut rfc = Rfc6238::with_defaults("totp-sercret-123".as_bytes().to_vec()).unwrap();
6
7    // optional, set digits, issuer, account_name
8    rfc.digits(8).unwrap();
9    rfc.issuer("issuer".to_string());
10    rfc.account_name("user-account".to_string());
11
12    // create a TOTP from rfc
13    let totp = TOTP::from_rfc6238(rfc).unwrap();
14    let code = totp.generate_current().unwrap();
15    println!("code: {}", code);
16}
17
18#[cfg(not(feature = "otpauth"))]
19fn main() {
20    let mut rfc = Rfc6238::with_defaults("totp-sercret-123".into()).unwrap();
21
22    // optional, set digits, issuer, account_name
23    rfc.digits(8).unwrap();
24
25    // create a TOTP from rfc
26    let totp = TOTP::from_rfc6238(rfc).unwrap();
27    let code = totp.generate_current().unwrap();
28    println!("code: {}", code);
29}