[][src]Struct libreauth::oath::HOTP

pub struct HOTP { /* fields omitted */ }

Generates, manipulates and checks HOTP codes.

Methods

impl HOTP[src]

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

Generate the HOTP value.

Examples

let key_ascii = "12345678901234567890".to_owned();
let mut hotp = libreauth::oath::HOTPBuilder::new()
    .ascii_key(&key_ascii)
    .finalize()
    .unwrap();

let code = hotp.generate();
assert_eq!(code, "755224");
let code = hotp.increment_counter().generate();
assert_eq!(code, "287082");

pub fn increment_counter(&mut self) -> &mut HOTP[src]

Increments the internal counter.

pub fn is_valid(&self, code: &str) -> 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 = libreauth::oath::HOTPBuilder::new()
    .ascii_key(&key_ascii)
    .finalize()
    .unwrap()
    .is_valid(&user_code);
assert!(valid);

pub fn key_uri_format<'a>(
    &'a self,
    issuer: &'a str,
    account_name: &'a str
) -> KeyUriBuilder<'a>
[src]

Creates the Key Uri Format according to the Google authenticator specification. This value can be used to generete QR codes which allow easy scanning by the end user. The returned KeyUriBuilder allows for additional customizations.

WARNING: The finalized value contains the secret key of the authentication process and should only be displayed to the corresponding user!

Example

let key_ascii = "12345678901234567890".to_owned();
let mut hotp = libreauth::oath::HOTPBuilder::new()
    .ascii_key(&key_ascii)
    .finalize()
    .unwrap();

let uri = hotp
    .key_uri_format("Provider1", "alice@example.com")
    .finalize();

assert_eq!(
    uri,
    "otpauth://hotp/Provider1:alice@example.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&issuer=Provider1&counter=0"
);

Auto Trait Implementations

impl Unpin for HOTP

impl Sync for HOTP

impl Send for HOTP

impl UnwindSafe for HOTP

impl RefUnwindSafe for HOTP

Blanket Implementations

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

impl<T> From<T> for 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]

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<T> Same<T> for T

type Output = T

Should always be Self