1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//! # `otp` — Rust Implementation of HMAC and Time based one-time passwords.
//!
//! This crate provides a fully self-contained implementation of the [HOTP (HMAC-based One-Time Password)](https://datatracker.ietf.org/doc/html/rfc4226)
//! and [TOTP (Time-based One-Time Password)](https://datatracker.ietf.org/doc/html/rfc6238).
//!
//! ## Features
//! - **HOTP**: Counter-based one-time password generator and validator.
//! - **TOTP**: Time-based one-time password generator and validator.
//! - **URI generation**: Generate otpauth-compatible URIs for use with QR code generation (e.g., Google Authenticator).
//!
//! ## Example (TOTP)
//!
//! ```rust
//! use otp::{Totp, Algorithm, Secret};
//!
//! let totp = Totp::new(
//! Algorithm::SHA1,
//! "example.com".into(),
//! "user@example.com".into(),
//! 6,
//! 30,
//! Secret::from_bytes(b"my-secret"),
//! );
//!
//! let timestamp = std::time::SystemTime::now()
//! .duration_since(std::time::UNIX_EPOCH)
//! .expect("Clock may have gone backwards")
//! .as_secs();
//! let otp = totp.generate_at(timestamp);
//!
//! assert!(totp.verify(otp, timestamp, 1));
//!
//! println!("{}", totp.to_uri());
//! // "otpauth://totp/example.com%3Auser%40example.com?secret=NV4S243FMNZGK5A&issuer=example.com&algorithm=SHA1&digits=6&period=30"
//!
//! ```
//!
//! ## References
//! - [RFC 2104](https://datatracker.ietf.org/doc/html/rfc2104) — HMAC: Keyed-Hashing for Message Authentication
//! - [RFC 4226](https://datatracker.ietf.org/doc/html/rfc4226) — HOTP: An HMAC-Based One-Time Password Algorithm
//! - [RFC 6238](https://datatracker.ietf.org/doc/html/rfc6238) — TOTP: Time-Based One-Time Password Algorithm
//! - [RFC 3174](https://datatracker.ietf.org/doc/html/rfc3174/) — US Secure Hash Algorithm 1 (SHA1)
//! - [RFC 6234](https://datatracker.ietf.org/doc/html/rfc6234) — US Secure Hash Algorithms (SHA and SHA-based HMAC and HKDF)
//! - [RFC 2202](https://datatracker.ietf.org/doc/html/rfc2202) — Test Cases for HMAC-MD5 and HMAC-SHA-1
//! - [RFC 4231](https://datatracker.ietf.org/doc/html/rfc4231) — Identifiers and Test Vectors for HMAC-SHA-224, HMAC-SHA-256, HMAC-SHA-384, and HMAC-SHA-512
//! - [RFC 4648](https://datatracker.ietf.org/doc/html/rfc4648) — The Base16, Base32, and Base64 Data Encodings
//! - [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986) — Uniform Resource Identifier (URI): Generic Syntax
//! - [Key URI Format](https://github.com/google/google-authenticator/wiki/Key-Uri-Format) — for QR-compatible URIs
pub use Algorithm;
pub use hmac;
pub use Hotp;
pub use Secret;
pub use Totp;