File: gen_secret.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 (28 lines) | stat: -rw-r--r-- 640 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
#[cfg(all(feature = "gen_secret", feature = "otpauth"))]
use totp_rs::{Algorithm, Secret, TOTP};

#[cfg(all(feature = "gen_secret", feature = "otpauth"))]
fn main() {
    let secret = Secret::generate_secret();

    let totp = TOTP::new(
        Algorithm::SHA1,
        6,
        1,
        30,
        secret.to_bytes().unwrap(),
        None,
        "account".to_string(),
    )
    .unwrap();

    println!(
        "secret raw: {} ; secret base32 {} ; code: {}",
        secret,
        secret.to_encoded(),
        totp.generate_current().unwrap()
    )
}

#[cfg(not(all(feature = "gen_secret", feature = "otpauth")))]
fn main() {}