Struct otpshka::HOTP[][src]

pub struct HOTP { /* fields omitted */ }

HMAC based OTP algorithm that uses simple counter as input.

Implementations

impl HOTP[src]

pub fn new<T: AsRef<[u8]>>(algorithm: Algorithm, secret: T) -> Self[src]

Initializes algorithm using provided algorithm and secret

  • algorithm - Generally acceptable are HMAC based on sha-1, sha-256 and sha-512
  • secret - Raw bytes used to derive HMAC key. User is responsible to decode it before passing.

pub fn sign(&self, counter: u64) -> impl AsRef<[u8]> + Clone + Copy[src]

Signs provided counter value using stored HMAC key.

pub fn generate_num(&self, counter: u64, digits: u8) -> u32[src]

Generates password as number from provided counter value with length of digits.

Note that in this case you must handle missing padding yourself.

pub fn generate_to<T: AsMut<[u8]>>(&self, counter: u64, dest: T)[src]

Generates password based on provided counter value and writes it into provided dest.

This always writes dest.as_ref().len().

Recommended buffer length is be within 6..8

pub fn verify(&self, token: &str, counter: u64) -> bool[src]

Checks whether provided token corresponds to counter.

Auto Trait Implementations

impl RefUnwindSafe for HOTP

impl Send for HOTP

impl Sync for HOTP

impl Unpin for HOTP

impl UnwindSafe for HOTP

Blanket Implementations

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

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

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

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.