Struct totp_sos::TOTP

source ·
pub struct TOTP {
    pub algorithm: Algorithm,
    pub digits: usize,
    pub skew: u8,
    pub step: u64,
    pub secret: Vec<u8>,
    pub account_name: String,
    pub issuer: Option<String>,
}
Expand description

TOTP holds informations as to how to generate an auth code and validate it. Its secret field is sensitive data, treat it accordingly

Fields

algorithm: Algorithm

SHA-1 is the most widespread algorithm used, and for totp pursposes, SHA-1 hash collisions are not a problem as HMAC-SHA-1 is not impacted. It’s also the main one cited in rfc-6238 even though the reference implementation permits the use of SHA-1, SHA-256 and SHA-512.

Not all clients support other algorithms then SHA-1

digits: usize

The number of digits for the auth code.

Per rfc-4226, this can be in the range between 6 and 8 digits

skew: u8

Number of steps allowed as network delay.

One would mean one step before current step and one step after are valid.

The recommended value per rfc-6238 is 1. Anything more is sketchy and should not be used.

step: u64

Duration in seconds of a step.

The recommended value per rfc-6238 is 30 seconds

secret: Vec<u8>

As per rfc-4226 the secret should come from a strong source, most likely a CSPRNG.

It should be at least 128 bits, but 160 are recommended.

account_name: String

The account name, typically either an email address or username.

The “mock@example.com” part of “Github:mock@example.com”.

Must not contain a colon :.

issuer: Option<String>

The name of your service/website.

The “Github” part of “Github:mock@example.com”.

Must not contain a colon :.

Implementations

Create a new instance of TOTP with given parameters.

See the doc for reference as to how to choose those values.

  • digits: MUST be between 6 & 8
  • secret: Must have bitsize of at least 128
  • account_name: Must not contain :
  • issuer: Must not contain :

Sign the given timestamp

Generate a token given the provided timestamp in seconds

Returns the timestamp of the first second for the next step given the provided timestamp in seconds

Returns the timestamp of the first second of the next step According to system time

Give the ttl (in seconds) of the current token

Generate a token from the current system time

Check if token is valid given the provided timestamp in seconds, accounting skew

Check if token is valid by current system time, accounting skew.

Return the base32 representation of the secret, which might be useful when users want to manually add the secret to their authenticator.

Convert a base32 secret into a TOTP.

The account name is the empty string and the issuer is None; so you should set them explicitly after decoding the secret bytes.

Generate a TOTP from the standard otpauth URL

Generate a standard URL used to automatically add TOTP auths.

Usually used with a QR code.

Label and issuer will be URL-encoded; the secret will be converted to base32 without padding, as per the RFC.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
Executes the destructor for this type. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Serialize this value into the given Serde serializer. Read more
Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.