pub struct NonceManager { /* private fields */ }Expand description
Nonce Manager | Nonce 管理器
Manages nonce generation and validation to prevent replay attacks 管理 nonce 的生成和验证以防止重放攻击
Implementations§
Source§impl NonceManager
impl NonceManager
Sourcepub fn new(storage: Arc<dyn SaStorage>, timeout: i64) -> Self
pub fn new(storage: Arc<dyn SaStorage>, timeout: i64) -> Self
Create new nonce manager | 创建新的 nonce 管理器
§Arguments | 参数
storage- Storage backend | 存储后端timeout- Nonce validity period in seconds | Nonce 有效期(秒)
Sourcepub async fn store(&self, nonce: &str, login_id: &str) -> SaTokenResult<()>
pub async fn store(&self, nonce: &str, login_id: &str) -> SaTokenResult<()>
Store and mark nonce as used | 存储并标记 nonce 为已使用
§Arguments | 参数
nonce- Nonce to store | 要存储的 noncelogin_id- Associated user ID | 关联的用户ID
Sourcepub async fn validate(&self, nonce: &str) -> SaTokenResult<bool>
pub async fn validate(&self, nonce: &str) -> SaTokenResult<bool>
Sourcepub async fn validate_and_consume(
&self,
nonce: &str,
login_id: &str,
) -> SaTokenResult<()>
pub async fn validate_and_consume( &self, nonce: &str, login_id: &str, ) -> SaTokenResult<()>
Sourcepub fn check_timestamp(
&self,
nonce: &str,
window_seconds: i64,
) -> SaTokenResult<bool>
pub fn check_timestamp( &self, nonce: &str, window_seconds: i64, ) -> SaTokenResult<bool>
Extract timestamp from nonce and check if it’s within valid time window 从 nonce 中提取时间戳并检查是否在有效时间窗口内
§Arguments | 参数
nonce- Nonce to check | 要检查的 noncewindow_seconds- Time window in seconds | 时间窗口(秒)
Sourcepub async fn cleanup_expired(&self) -> SaTokenResult<()>
pub async fn cleanup_expired(&self) -> SaTokenResult<()>
Clean up expired nonces (implementation depends on storage) 清理过期的 nonce(实现依赖于存储)
Note: Most storage backends automatically expire keys with TTL 注意:大多数存储后端会自动过期带 TTL 的键
Trait Implementations§
Source§impl Clone for NonceManager
impl Clone for NonceManager
Source§fn clone(&self) -> NonceManager
fn clone(&self) -> NonceManager
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for NonceManager
impl !RefUnwindSafe for NonceManager
impl Send for NonceManager
impl Sync for NonceManager
impl Unpin for NonceManager
impl !UnwindSafe for NonceManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more