[][src]Struct boringauth::oath::TOTP

pub struct TOTP { /* fields omitted */ }

Methods

impl TOTP[src]

pub fn generate(&self) -> String[src]

Generate the current TOTP value.

Examples

let key_base32 = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ".to_owned();
let mut totp = boringauth::oath::TOTPBuilder::new()
    .base32_key(&key_base32)
    .finalize()
    .unwrap();

let code = totp.generate();
assert_eq!(code.len(), 6);

pub fn is_valid(&self, code: &String) -> bool[src]

Checks if the given code is valid. This implementation uses the double HMAC verification in order to prevent a timing side channel attack.

Examples

let key_ascii = "12345678901234567890".to_owned();
let user_code = "755224".to_owned();
let valid = boringauth::oath::TOTPBuilder::new()
    .ascii_key(&key_ascii)
    .finalize()
    .unwrap()
    .is_valid(&user_code);

Auto Trait Implementations

impl Send for TOTP

impl Sync for TOTP

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]