pub struct SessionCache { /* private fields */ }Expand description
LRU Session Cache with eviction
Implementations§
Source§impl SessionCache
impl SessionCache
Source§impl SessionCache
impl SessionCache
Sourcepub fn with_capacity(max_entries: usize, ticket_lifetime: Duration) -> Self
pub fn with_capacity(max_entries: usize, ticket_lifetime: Duration) -> Self
Create with custom limits (for Device Profiles)
Sourcepub fn store(
&mut self,
session_id: SessionId,
resumption_secret: &[u8; 32],
cipher_suite: CipherSuite,
)
pub fn store( &mut self, session_id: SessionId, resumption_secret: &[u8; 32], cipher_suite: CipherSuite, )
Store a ticket after a successful handshake.
resumption_secret must be the same value
Session::resumption_hint() exposes to the client — it is
stored verbatim so both peers derive the same early-data key.
Sourcepub fn try_resume(
&mut self,
session_id: &SessionId,
) -> Option<([u8; 32], CipherSuite)>
pub fn try_resume( &mut self, session_id: &SessionId, ) -> Option<([u8; 32], CipherSuite)>
Attempt to resume a session (0-RTT). One-shot: a successful
lookup REMOVES the ticket, so a replayed ClientHello carrying
the same resume_session_id finds nothing and falls back to a
full 1-RTT handshake. This is the anti-replay guarantee for
0-RTT early-data (Phase 4.1).
Returns (raw resumption_secret, cipher_suite) — the verbatim
secret stored at store time, ready to feed into
crypto::kdf::derive_early_data_keying.
Sourcepub fn peek(
&mut self,
session_id: &SessionId,
) -> Option<([u8; 32], CipherSuite, Instant, Instant)>
pub fn peek( &mut self, session_id: &SessionId, ) -> Option<([u8; 32], CipherSuite, Instant, Instant)>
Look up a still-valid ticket without consuming it (HS-03). Expired
tickets are removed and None returned. The returned
created_at/expires_at let the caller re-insert the ticket unchanged
via reinsert_with_expiry if a resume that
passed the binder check later fails (ZERORTT-2) — without extending the
lifetime. Actual consumption is a separate explicit remove
once the resume’s proof-of-possession (binder) has been verified.
Sourcepub fn reinsert_with_expiry(
&mut self,
session_id: SessionId,
resumption_secret: &[u8; 32],
cipher_suite: CipherSuite,
created_at: Instant,
expires_at: Instant,
)
pub fn reinsert_with_expiry( &mut self, session_id: SessionId, resumption_secret: &[u8; 32], cipher_suite: CipherSuite, created_at: Instant, expires_at: Instant, )
Re-insert a ticket that a resume attempt consumed but then failed to
complete (ZERORTT-2 — e.g. a corrupted KEM ciphertext aborts the
handshake after the ticket was removed). Restores the ticket with its
original timestamps so the lifetime is not extended, and refuses to
resurrect an already-expired ticket. Mirrors store’s
eviction + LRU bookkeeping so evict_oldest stays consistent.
Sourcepub fn remove(&mut self, session_id: &SessionId) -> bool
pub fn remove(&mut self, session_id: &SessionId) -> bool
Remove a specific ticket. Returns true iff a ticket was actually
present — the resume path uses this to make eager consumption race-free:
of two concurrent resumes of the same id, exactly one observes true
and proceeds, so the same 0-RTT early-data cannot be accepted twice.