Edit

thodg/totp-rs/examples/steam.rs

Branch :

  • Show log

    Commit

  • Author : Cléo REBERT
    Date : 2023-03-28 10:47:52
    Hash : e4e055de
    Message : 5.0 Signed-off-by: Cléo REBERT <cleo.rebert-ext@treezor.com>

  • examples/steam.rs
  • #[cfg(feature = "steam")]
    use totp_rs::{Secret, TOTP};
    
    #[cfg(feature = "steam")]
    #[cfg(feature = "otpauth")]
    fn main() {
        // create TOTP from base32 secret
        let secret_b32 = Secret::Encoded(String::from("OBWGC2LOFVZXI4TJNZTS243FMNZGK5BNGEZDG"));
        let totp_b32 = TOTP::new_steam(secret_b32.to_bytes().unwrap(), "user-account".to_string());
    
        println!(
            "base32 {} ; raw {}",
            secret_b32,
            secret_b32.to_raw().unwrap()
        );
        println!(
            "code from base32:\t{}",
            totp_b32.generate_current().unwrap()
        );
    }
    
    #[cfg(feature = "steam")]
    #[cfg(not(feature = "otpauth"))]
    fn main() {
        // create TOTP from base32 secret
        let secret_b32 = Secret::Encoded(String::from("OBWGC2LOFVZXI4TJNZTS243FMNZGK5BNGEZDG"));
        let totp_b32 = TOTP::new_steam(secret_b32.to_bytes().unwrap());
    
        println!(
            "base32 {} ; raw {}",
            secret_b32,
            secret_b32.to_raw().unwrap()
        );
        println!(
            "code from base32:\t{}",
            totp_b32.generate_current().unwrap()
        );
    }
    
    #[cfg(not(feature = "steam"))]
    fn main() {}