xotp

A Rust implementation the HOTP and TOTP Algorithms.
- HOTP was implemented in accordance with RFC4226
- TOTP was implemented in accordance with RFC6238
Usage
To use HOTP:
use xotp::hotp::HOTP;
fn get_otp_with_hotp() {
let secret = "secret";
let counter = 0;
let hotp_str = HOTP::default_from_utf8(secret);
let otp_from_str = hotp_str.get_otp(counter);
println!("The otp from hotp_str: {}", otp_from_str);
let hotp_bytes = HOTP::new(secret.as_bytes(), 6);
let otp_from_bytes = hotp_bytes.get_otp(counter);
println!("The otp from hotp_bytes: {}", otp_from_bytes);
}
To use TOTP:
use xotp::totp::TOTP;
use xotp::util::MacDigest; use std::time::{Duration, SystemTime, UNIX_EPOCH};
fn get_otp_with_totp() {
let secret = "secret";
let elapsed_seconds = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Error getting time")
.as_secs();
let totp_sha1_str = TOTP::default_from_utf8(secret);
let otp_sha1 = totp_sha1_str.get_otp(elapsed_seconds);
println!("The otp from totp_sha1_str: {}", otp_sha1);
let totp_sha256_bytes = TOTP::new(
secret.as_bytes(),
MacDigest::SHA256, 8, 60 );
let otp_sha256 = totp_sha256_bytes.get_otp_with_custom_time_start(
elapsed_seconds,
0, );
println!("The otp from totp_sha256_bytes: {}", otp_sha256);
}
Changelog
The changelog for this crate can be found at CHANGELOG.md
Features and Bugs
Please file any featre requests or bug reports through the issue tracker
Licensing