Struct ootp::totp::Totp[][src]

pub struct Totp<'a> {
    pub hotp: Hotp<'a>,
    pub digits: u32,
    pub period: u64,
    pub algorithm: &'a ShaTypes,
}
Expand description

The TOTP is a HOTP-based one-time password algorithm, with a time value as moving factor.

It takes four parameter. An Hotp istance, the desired number of digits, a time period and the SHA algorithm.

Fields

hotp: Hotp<'a>digits: u32period: u64algorithm: &'a ShaTypes

Implementations

TOTP instance constructor

This function returns a string of the one-time password

Example

use ootp::totp::{Totp, CreateOption};

let secret = "A strong shared secrett";
let totp = Totp::secret(
    secret,
    CreateOption::Default
);

let otp = totp.make(); // Generate a one-time password
println!("{}", otp); // Print the one-time password

This function returns a string of the one-time password, valid a period from time seconds since the UNIX epoch

Example

use ootp::totp::{Totp, CreateOption};

let secret = "A strong shared secrett";
let totp = Totp::secret(
    secret,
    CreateOption::Default
);

let otp = totp.make_time(59); // Generate a one-time password, valid a `DEFAULT_PERIOD from `59` seconds since the UNIX epoch
println!("{}", otp); // Print the one-time password

Returns a boolean indicating if the one-time password is valid.

Example #1

use ootp::totp::{Totp, CreateOption};

let secret = "A strong shared secret";
let totp = Totp::secret(
    secret,
    CreateOption::Default
);
let otp = totp.make(); // Generate a one-time password
let check = totp.check(otp.as_str(), None);

Example #2

use ootp::totp::{Totp, CreateOption};

let secret = "A strong shared secret";
let totp = Totp::secret(
    secret,
    CreateOption::Digits(8)
);
let otp = totp.make(); // Generate a one-time password
let check = totp.check(otp.as_str(), Some(42));

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

Performs the conversion.

Performs the conversion.

Should always be Self

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.