pub struct SagaHttpReplayGuard { /* private fields */ }Expand description
业务作用:在 HMAC 时间窗内原子拒绝已经验真的 nonce,防止认证请求被原样重放。
本结构有意使用有界内存:过期项在每次 claim 前清理,未过期项达到上限时 fail-closed,绝不 淘汰仍可重放的证据。它保护单进程 connector;多副本生产入口必须把 nonce claim 放入共享的 强一致存储,或由网关提供等价的一次性请求语义。
Implementations§
Source§impl SagaHttpReplayGuard
impl SagaHttpReplayGuard
Sourcepub fn new(max_entries: usize) -> Result<Self, SagaHttpMessageAuthError>
pub fn new(max_entries: usize) -> Result<Self, SagaHttpMessageAuthError>
业务作用:构造有界 replay guard,限制攻击流量可占用的 nonce 记录数。
参数说明:
max_entries: 同一进程允许保留的未过期 nonce 上限,必须大于零。
返回:上限合法时返回空 guard;零容量直接拒绝启动。
Sourcepub fn verify_once(
&self,
authenticator: &SagaHttpMessageAuthenticator,
message: &SagaHttpSignedMessage<'_>,
now_ms: u64,
) -> Result<(), SagaHttpMessageAuthError>
pub fn verify_once( &self, authenticator: &SagaHttpMessageAuthenticator, message: &SagaHttpSignedMessage<'_>, now_ms: u64, ) -> Result<(), SagaHttpMessageAuthError>
业务作用:先校验完整 HMAC,再原子占用 producer/nonce,形成仅可消费一次的身份凭据。
参数说明:
authenticator: 当前部署信任边绑定的 HMAC 认证器。message: 冻结 producer/path/timestamp/nonce/body/signature 的原始收据。now_ms: 接收端当前 Unix 毫秒。
返回:签名有效且 nonce 首次出现时成功;重放、容量耗尽或认证失败均脱敏拒绝。
Sourcepub fn metrics(&self, now_ms: u64) -> SagaHttpReplayMetrics
pub fn metrics(&self, now_ms: u64) -> SagaHttpReplayMetrics
业务作用:读取并顺带清理一条信任边的 replay 防护指标,供控制面区分攻击与容量不足。
参数说明:
now_ms: 指标采集时钟,用于剔除已经越过 replay horizon 的 active claim。
返回:不含 producer、nonce、path 或 payload 的低基数计数快照。
Auto Trait Implementations§
impl !Freeze for SagaHttpReplayGuard
impl RefUnwindSafe for SagaHttpReplayGuard
impl Send for SagaHttpReplayGuard
impl Sync for SagaHttpReplayGuard
impl Unpin for SagaHttpReplayGuard
impl UnsafeUnpin for SagaHttpReplayGuard
impl UnwindSafe for SagaHttpReplayGuard
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