#otp #one-time #rust #one-time-password

otp-rs

RFC-complaint one-time password algorithms written in Rust

1 unstable release

0.1.1 Nov 18, 2021
0.1.0 Nov 18, 2021

#889 in Authentication

47 downloads per month

MIT license

6KB
132 lines

otp-rs

RFC-complaint one-time password algorithms written in Rust.

The HMAC-based one-time password algorithm is implemented as per RFC4226. The time-based one-time password algorithm is implemented as per RFC 6238.

Installation

[dependencies]
otp-rs= "0.1"

HOTP Example

  let otp = HOTP::new("secret");
  /// Generate code with counter 0 input
  let code = otp.generate(0).unwrap();

  println!("{}", code);

TOTP Example

let otp = TOTP::new("secret");
/// Generate code with period and current timestamp
 let timestamp = SystemTime::now()
    .duration_since(UNIX_EPOCH)
    .unwrap()
    .as_secs();
  let code = otp.generate(30, timestamp);
  println!("{}", code);

Dependencies

~720KB
~13K SLoC