pub struct ReplayWindow { /* private fields */ }Expand description
Sliding-window replay protection for multiple independent streams.
Streams are keyed by (source_id, payload_type, key_epoch) — see
module-level docs on why the key epoch matters across rekey. Use
Self::accept to atomically check-and-mark a sequence as received.
Implementations§
Source§impl ReplayWindow
impl ReplayWindow
Sourcepub fn with_window_bits(bits: u32) -> Self
pub fn with_window_bits(bits: u32) -> Self
Create an empty replay window with a caller-chosen width.
bits MUST be a multiple of 64, at least 64, at most
MAX_WINDOW_BITS (1024). Panics otherwise.
Sourcepub fn window_bits(&self) -> u32
pub fn window_bits(&self) -> u32
Current window width in bits.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Reset all tracked streams. Primarily useful for tests and for
session teardown. Rekey-driven cleanup is narrower — use
Self::drop_epoch to forget only the old key’s windows while
preserving the current one.
Sourcepub fn accept(
&mut self,
source_id: u64,
payload_type: u8,
key_epoch: u8,
seq: u64,
) -> bool
pub fn accept( &mut self, source_id: u64, payload_type: u8, key_epoch: u8, seq: u64, ) -> bool
Atomically check whether seq is acceptable for the given
(source_id, payload_type, key_epoch) tuple, and mark it as
received if so.
Returns true if the message should be processed (sequence is new
and within the window), false if it should be dropped (duplicate
or too old).
source_id is the 6-byte random identifier from the AEAD nonce
interpreted as little-endian u64. payload_type is the nonce
byte 6. key_epoch is a receiver-local counter that advances on
every install_key call — the caller MUST pass the epoch of the
key that verified the AEAD tag, not (for example) the current
epoch if the previous key is what actually opened the envelope.
Sourcepub fn drop_epoch(&mut self, key_epoch: u8)
pub fn drop_epoch(&mut self, key_epoch: u8)
Drop all stream state associated with a specific key_epoch.
Called by crate::Session::tick when the previous-key grace
period ends — at that point the old key’s envelopes can no longer
verify anyway, so the old window is pure memory overhead and
should be reclaimed. Safe to call for an epoch that has no
entries (no-op).
Sourcepub fn stream_count(&self) -> usize
pub fn stream_count(&self) -> usize
Number of distinct streams currently tracked. Mostly for tests and observability; not part of the protection guarantee.
Trait Implementations§
Source§impl Clone for ReplayWindow
impl Clone for ReplayWindow
Source§fn clone(&self) -> ReplayWindow
fn clone(&self) -> ReplayWindow
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more