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
//! Copyright (c) 2026 Kirky.X. All rights reserved.
//! See LICENSE for full license text.
//! TOTP 子模块,时间一次性密码实现(RFC 6238)。
//!
//! 基于 `totp-rs` crate 实现,
//! 提供二步验证(2FA)能力。
//!
//! 使用 SHA1 算法(RFC 6238 默认,兼容主流 Authenticator App),
//! 允许 ±1 时间窗口偏差以容忍时钟漂移。
/// TOTP 处理器,封装 RFC 6238 动态验证码生成与校验。
///
/// # 示例
///
/// ```
/// #[cfg(feature = "secure-totp")]
/// # {
/// use garrison::secure::totp::TotpHandler;
///
/// let secret = b"12345678901234567890".to_vec();
/// let handler = TotpHandler::new(secret, 30, 6).unwrap();
/// let code = handler.generate(1700000000);
/// assert_eq!(code.len(), 6);
/// assert!(handler.validate(&code, 1700000000));
/// # }
/// ```