pub struct SessionManager<SS, K, C, A> { /* private fields */ }Expand description
Manages session issuance, validation, and revocation (RFC-013 §3).
Session issuance requires a RedeemSuccess proof to enforce the
invariant that sessions can only be created after a confirmed won claim
(RFC-013 §5, acceptance checklist: “session issuance cannot occur before
claim success”).
Implementations§
Source§impl<SS, K, C, A> SessionManager<SS, K, C, A>
impl<SS, K, C, A> SessionManager<SS, K, C, A>
Sourcepub fn new(
store: SS,
hasher: SecretHasher<K>,
clock: C,
audit: A,
cookie_policy: CookiePolicy,
) -> Self
pub fn new( store: SS, hasher: SecretHasher<K>, clock: C, audit: A, cookie_policy: CookiePolicy, ) -> Self
Construct a session manager.
Sourcepub async fn issue<R: RandomSource>(
&self,
success: &RedeemSuccess,
session_id: SessionId,
rng: &mut R,
) -> Result<IssuedSession, SessionError>
pub async fn issue<R: RandomSource>( &self, success: &RedeemSuccess, session_id: SessionId, rng: &mut R, ) -> Result<IssuedSession, SessionError>
Issue a new session for the authenticated subject.
Requires a RedeemSuccess proof so this cannot be called without a
prior confirmed won claim. Generates a high-entropy session secret,
derives the HMAC lookup key, inserts the record, and returns the
Set-Cookie header value.
The plaintext session secret leaves this function only inside
IssuedSession::set_cookie; it is never stored or logged by codlet.
§Errors
Returns SessionError::Internal if the RNG, hasher, or store fails.
Sourcepub async fn validate(
&self,
cookie_value: &str,
) -> Result<SessionValidationOutcome, SessionError>
pub async fn validate( &self, cookie_value: &str, ) -> Result<SessionValidationOutcome, SessionError>
Validate a session from the bearer credential in a cookie.
Derives the lookup key from cookie_value, queries the store for an
active (unexpired, unrevoked) session, and returns the authentication
outcome. Expired and revoked sessions both collapse to
Unauthenticated (INV-8).
§Errors
Returns SessionError::Internal only on store/key failure.
A missing or invalid session returns Ok(Unauthenticated), not an error.
Sourcepub async fn revoke(
&self,
session_id: &SessionId,
) -> Result<String, SessionError>
pub async fn revoke( &self, session_id: &SessionId, ) -> Result<String, SessionError>
Revoke a session (logout or incident response).
Returns the Set-Cookie header value that clears the session cookie
from the client.
§Errors
Returns SessionError::Internal on store failure.
Borrow the cookie policy (e.g. to build the initial Set-Cookie name
for extraction on the next request).