Struct TOTP

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

Provides Time based One Time Passwords.

§References

  • This object implements utilities for RFC6328.

Implementations§

Source§

impl TOTP

Source

pub fn new(secret: HOTP, time_step: u64, start_time: u64) -> TOTP

Creates a new TOTP instance.

§Arguments
  • secret - HOTP secret to use for TOTP generation.
  • time_step - The time frame to allow every password, in seconds. RFC6238 recommends 30 seconds.
  • start_time - Configurable T0 for OTP.
Source

pub fn get_otp(&self, digits: u32, offset: i32) -> u32

Generates a time based OTP.

§Arguments
  • digits - Desired OTP length, should be at least 6.
  • offset - Should be 0 for current time frame, -1 for previous, 1 for next, etc…
Source

pub fn validate(&self, digits: u32, guess: u32, buffer: u32) -> bool

Validates the given OTP.

§Arguments
  • digits - The amount of digits set for the OTP.
  • guess - The user provided guess to validate.
  • buffer - Amount of OTPs to check before and after the current one (0=Only current, 1=Previous+Now+Next OTP, etc…)

Auto Trait Implementations§

§

impl Freeze for TOTP

§

impl RefUnwindSafe for TOTP

§

impl Send for TOTP

§

impl Sync for TOTP

§

impl Unpin for TOTP

§

impl UnwindSafe for TOTP

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.