Packages / rupm

otp-tools 0.1.0

HOTP and TOTP one-time passwords (RFC 4226 and 6238) with base32 secrets and otpauth URIs

Install

cargo add otp-tools --registry rupm

In Ruststudio: Packages, search for otp-tools, Install.

Owner: Rust Studio. Licence: MIT OR Apache-2.0. Total downloads: 0. Published 2026-11-22.

Versions

README

# otp-tools

HOTP and TOTP one-time passwords (RFC 4226 and 6238) with base32 secrets and otpauth URIs

Add it with `rupm add otp-tools` (or `cargo add otp-tools --registry rupm`).

Matches the RFC 4226 and RFC 6238 test vectors, with the hashes built in (std only). The hashes are unaudited and not constant-time, so this crate is not meant for security-critical use; use an audited crate for a real authentication system.

```rust
use otp_tools::{hotp, Algorithm};
// RFC 4226 test secret, counter 0.
assert_eq!(hotp(b"12345678901234567890", 0, 6, Algorithm::Sha1).unwrap(), "755224");
let secret = otp_tools::base32_decode("JBSWY3DPEHPK3PXP").unwrap();
let code = otp_tools::totp(&secret, 59, 30, 6, Algorithm::Sha1).unwrap();
assert_eq!(code.len(), 6);
```