File: rfc-6238.rs

package info (click to toggle)
rust-totp-rs 5.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 316 kB
  • sloc: makefile: 4
file content (29 lines) | stat: -rw-r--r-- 858 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use totp_rs::{Rfc6238, TOTP};

#[cfg(feature = "otpauth")]
fn main() {
    let mut rfc = Rfc6238::with_defaults("totp-sercret-123".as_bytes().to_vec()).unwrap();

    // optional, set digits, issuer, account_name
    rfc.digits(8).unwrap();
    rfc.issuer("issuer".to_string());
    rfc.account_name("user-account".to_string());

    // create a TOTP from rfc
    let totp = TOTP::from_rfc6238(rfc).unwrap();
    let code = totp.generate_current().unwrap();
    println!("code: {}", code);
}

#[cfg(not(feature = "otpauth"))]
fn main() {
    let mut rfc = Rfc6238::with_defaults("totp-sercret-123".into()).unwrap();

    // optional, set digits, issuer, account_name
    rfc.digits(8).unwrap();

    // create a TOTP from rfc
    let totp = TOTP::from_rfc6238(rfc).unwrap();
    let code = totp.generate_current().unwrap();
    println!("code: {}", code);
}