Struct Totp

Source
pub struct Totp<'t> {
    pub base: Base<'t>,
    pub skew: Skew,
    pub period: Period,
}
Expand description

Represents TOTP configurations.

Fields§

§base: Base<'t>

The base configuration.

§skew: Skew

The skew to apply.

§period: Period

The period to use.

Implementations§

Source§

impl<'t> Totp<'t>

Source

pub fn builder() -> TotpBuilder<'t>

Create an instance of Totp using the builder syntax

Source§

impl<'t> Totp<'t>

Source

pub const fn base(&self) -> &Base<'t>

Returns the base configuration.

Source

pub fn base_mut(&mut self) -> &mut Base<'t>

Returns the mutable base configuration.

Source

pub fn into_base(self) -> Base<'t>

Consumes Self, returning the base configuration.

Source§

impl Totp<'_>

Source

pub const fn input_at(&self, time: u64) -> u64

Returns the input value corresponding to the given time.

Source

pub const fn next_period_at(&self, time: u64) -> u64

Returns the time corresponding to the next period from the given time.

Source

pub fn try_next_period(&self) -> Result<u64, Error>

Tries to return the time corresponding to the next period from the current time.

§Errors

Returns time::Error if the system time is before the epoch.

Source

pub fn next_period(&self) -> u64

Returns the time corresponding to the next period from the current time.

§Panics

Panics if the system time is before the epoch.

Source

pub const fn time_to_live_at(&self, time: u64) -> u64

Returns the time to live of the code for the given time.

Source

pub fn try_time_to_live(&self) -> Result<u64, Error>

Tries to return the time to live of the code for the current time.

§Errors

Returns time::Error if the system time is before the epoch.

Source

pub fn time_to_live(&self) -> u64

Returns the time to live of the code for the current time.

§Panics

Panics if the system time is before the epoch.

Source

pub fn generate_at(&self, time: u64) -> u32

Generates the code for the given time.

Source

pub fn generate_string_at(&self, time: u64) -> String

Generates the string code for the given time.

Source

pub fn try_generate(&self) -> Result<u32, Error>

Tries to generate the code for the current time.

§Errors

Returns time::Error if the system time is before the epoch.

Source

pub fn generate(&self) -> u32

Generates the code for the current time.

§Panics

Panics if the system time is before the epoch.

Source

pub fn try_generate_string(&self) -> Result<String, Error>

Tries to generate the string code for the current time.

§Errors

Returns time::Error if the system time is before the epoch.

Source

pub fn generate_string(&self) -> String

Generates the string code for the current time.

§Panics

Panics if the system time is before the epoch.

Source

pub fn verify_exact_at(&self, time: u64, code: u32) -> bool

Verifies the given code for the given time.

Source

pub fn verify_string_exact_at<S: AsRef<str>>(&self, time: u64, code: S) -> bool

Verifies the given string code for the given time.

Source

pub fn try_verify_exact(&self, code: u32) -> Result<bool, Error>

Tries to verify the given code for the current time exactly.

§Errors

Returns time::Error if the system time is before the epoch.

Source

pub fn verify_exact(&self, code: u32) -> bool

Verifies the given code for the current time exactly.

§Panics

Panics if the system time is before the epoch.

Source

pub fn try_verify_string_exact<S: AsRef<str>>( &self, code: S, ) -> Result<bool, Error>

Tries to verify the given string code for the current time exactly.

§Errors

Returns time::Error if the system time is before the epoch.

Source

pub fn verify_string_exact<S: AsRef<str>>(&self, code: S) -> bool

Verifies the given string code for the current time exactly.

§Panics

Panics if the system time is before the epoch.

Source

pub fn verify_at(&self, time: u64, code: u32) -> bool

Verifies the given code for the given time, accounting for skews.

Source

pub fn verify_string_at<S: AsRef<str>>(&self, time: u64, code: S) -> bool

Verifies the given string code for the given time, accounting for skews.

Source

pub fn try_verify(&self, code: u32) -> Result<bool, Error>

Tries to verify the given code for the current time, accounting for skews.

§Errors

Returns time::Error if the system time is before the epoch.

Source

pub fn verify(&self, code: u32) -> bool

Verifies the given code for the current time, accounting for skews.

§Panics

Panics if the system time is before the epoch.

Source

pub fn try_verify_string<S: AsRef<str>>(&self, code: S) -> Result<bool, Error>

Tries to verify the given string code for the current time, accounting for skews.

§Errors

Returns time::Error if the system time is before the epoch.

Source

pub fn verify_string<S: AsRef<str>>(&self, code: S) -> bool

Verifies the given string code for the current time, accounting for skews.

§Panics

Panics if the system time is before the epoch.

Source§

impl Totp<'_>

Source

pub fn query_for(&self, url: &mut Url)

Available on crate feature auth only.

Applies the HOTP configuration to the given URL.

Note that this method applies the base configuration on its own.

Source

pub fn extract_from(query: &mut Query<'_>) -> Result<Self, Error>

Available on crate feature auth only.

Extracts the TOTP configuration from the given query.

§Errors

Returns Error if extraction fails.

Source§

impl Totp<'_>

Source

pub fn into_owned(self) -> Owned

Converts Self into Owned.

Trait Implementations§

Source§

impl<'t> Clone for Totp<'t>

Source§

fn clone(&self) -> Totp<'t>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'t> Debug for Totp<'t>

Source§

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

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

impl<'de, 't> Deserialize<'de> for Totp<'t>

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'t> From<Totp<'t>> for Otp<'t>

Source§

fn from(totp: Totp<'t>) -> Self

Converts to this type from the input type.
Source§

impl<'t> Hash for Totp<'t>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'t> PartialEq for Totp<'t>

Source§

fn eq(&self, other: &Totp<'t>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'t> Serialize for Totp<'t>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<'t> Eq for Totp<'t>

Source§

impl<'t> StructuralPartialEq for Totp<'t>

Auto Trait Implementations§

§

impl<'t> Freeze for Totp<'t>

§

impl<'t> RefUnwindSafe for Totp<'t>

§

impl<'t> Send for Totp<'t>

§

impl<'t> Sync for Totp<'t>

§

impl<'t> Unpin for Totp<'t>

§

impl<'t> UnwindSafe for Totp<'t>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,