Function oath::totp_custom [] [src]

pub fn totp_custom<D: Digest + Default>(
    key: &[u8],
    digits: u32,
    epoch: u64,
    time_step: u64,
    current_time: u64
) -> u64

Low-level function, that computes an one-time password using TOTP algorithm. It's generic over hashing algorithm D.

key is a slice, that represents the shared secret;

digits - number of digits in output (usually 6 or 8);

epoch - initial counter time T0 (default value is 0);

time_step - time step in seconds (default value is 30);

current_time - current Unix time (in seconds);

Example

extern crate sha_1 as sha1;
extern crate oath;

use sha1::Sha1;
use oath::totp_custom;

fn main () {
    assert_eq!(totp_custom::<Sha1>(b"\xff", 6, 0, 1, 23), 330795);
}