Struct HOTP

Source
pub struct HOTP { /* private fields */ }
Expand description

This is the secret that will be used to generate HMAC based one-time-passwords.

§References

  • This object implements utilities for RFC4226.

Implementations§

Source§

impl HOTP

Source

pub fn new(algorithm: HOTPAlgorithm) -> Result<HOTP, Unspecified>

Creates a new HOTPSecret from OS generated random number.

§Arguments
  • algorithm - Algorithm to use for OTP generation.
Source

pub fn from_base32(data: &str) -> Result<HOTP, ()>

Loads a base32 encoded secret.

§Arguments
  • data - base32 encoded secret to load.
Source

pub fn from_bin(data: &[u8]) -> Result<HOTP, ()>

Loads the HOTP secret from a given [u8].

§Arguments
  • data - The shared secret.
  • algorithm - Algorithm used for OTP generation.
Source

pub fn get_secret_base32(&self) -> String

Exports the HOTP Secret as base32 encoded string.

Source

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

Generates a One Time Password from the provided parameters.

§Arguments
  • counter - Password’s counter. This counter value should never be reused for security reasons.
  • digits - Desired OTP length, this value should be at least 6.
Source

pub fn validate(&self, counter: &[u8], digits: u32, guess: u32) -> bool

Validates the given OTP

§Arguments
  • counter - The counter to test against.
  • digits - The OTPs length.
  • guess - A user provided guess to validate.
§Note

It is recommended to check the following counters in case the user skipped an OTP. You should verify that an OTP with the same counter was not already used.

Auto Trait Implementations§

§

impl Freeze for HOTP

§

impl RefUnwindSafe for HOTP

§

impl Send for HOTP

§

impl Sync for HOTP

§

impl Unpin for HOTP

§

impl UnwindSafe for HOTP

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.