Function totp_lite::totp_custom

source ·
pub fn totp_custom<H>(
    step: u64,
    digits: u32,
    secret: &[u8],
    time: u64
) -> Stringwhere
    H: Update + FixedOutput + CoreProxy,
    H::Core: HashMarker + UpdateCore + FixedOutputCore + BufferKindUser<BufferKind = Eager> + Default + Clone,
    <H::Core as BlockSizeUser>::BlockSize: IsLess<U256>,
    Le<<H::Core as BlockSizeUser>::BlockSize, U256>: NonZero,
Expand description

Produce a Time-based One-time Password with full control over algorithm parameters.

use std::time::{SystemTime, UNIX_EPOCH};
use totp_lite::{totp_custom, Sha512, DEFAULT_STEP};

// Negotiated between you and the authenticating service.
let password: &[u8] = b"secret";

// The number of seconds since the Unix Epoch.
let seconds: u64 = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs();

// Uses the default step of 30 seconds, but asks for 10 result digits instead.
let result: String = totp_custom::<Sha512>(DEFAULT_STEP, 10, password, seconds);
assert_eq!(10, result.len());