Struct authenticator::models::otp::OTP

source ·
pub struct OTP {
    secret: Vec<u8>,
    algorithm: Algorithm,
    digits: u32,
}

Fields§

§secret: Vec<u8>§algorithm: Algorithm§digits: u32

Implementations§

source§

impl OTP

source

const STEAM_CHARS: &'static str = "23456789BCDFGHJKMNPQRTVWXY"

source

pub const STEAM_DEFAULT_PERIOD: u32 = 30u32

source

pub const STEAM_DEFAULT_DIGITS: u32 = 5u32

source

pub const DEFAULT_COUNTER: u32 = 1u32

source

pub const DEFAULT_DIGITS: u32 = 6u32

source

pub const DEFAULT_PERIOD: u32 = 30u32

source

pub fn is_valid(secret: &str) -> bool

source

fn time_based_counter(period: u32) -> u64

source

pub fn from_bytes_steam(secret: impl AsRef<[u8]>) -> Self

source

pub fn from_str_steam(secret: &str) -> Result<Self>

source

pub fn from_str_with_defaults(secret: &str) -> Result<Self>

source

pub fn from_str(secret: &str, algorithm: Algorithm, digits: u32) -> Result<Self>

source

pub fn from_bytes_with_defaults(secret: impl AsRef<[u8]>) -> Self

source

pub fn from_bytes( secret: impl AsRef<[u8]>, algorithm: Algorithm, digits: u32 ) -> Self

source

pub fn hotp(&self, counter: u64) -> Result<u32>

Performs the HMAC-based One-time Password Algorithm (HOTP) given an RFC4648 base32 encoded secret, and an integer counter.

source

pub fn hotp_formatted(&self, counter: u64) -> Result<String>

source

pub fn totp(&self, period: Option<u32>) -> Result<u32>

source

pub fn totp_formatted(&self, period: Option<u32>) -> Result<String>

source

pub fn steam(&self, counter: Option<u64>) -> Result<String>

source

pub fn secret(&self) -> String

Trait Implementations§

source§

impl Debug for OTP

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for OTP

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Zeroize for OTP

source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.

Auto Trait Implementations§

§

impl RefUnwindSafe for OTP

§

impl Send for OTP

§

impl Sync for OTP

§

impl Unpin for OTP

§

impl UnwindSafe for OTP

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> IntoSql for T

§

fn into_sql<T>(self) -> Self::Expression
where Self: AsExpression<T> + Sized, T: SqlType + TypedExpressionType,

Convert self to an expression for Diesel’s query builder. Read more
§

fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
where &'a Self: AsExpression<T>, T: SqlType + TypedExpressionType,

Convert &self to an expression for Diesel’s query builder. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more