pub struct CookieService { /* private fields */ }Expand description
Signs and verifies HTTP cookie values.
Not #[Injectable] — provide manually via ctx.provide(CookieService::new(...)).
§Secret rotation
The HMAC secret lives behind Rotating:
signing/verification pay one atomic pointer load, and
rotate_secret hot-swaps the secret with the
previous one retained for verification, so cookies issued just before
rotation stay valid until their natural Max-Age expiry.
Implementations§
Source§impl CookieService
impl CookieService
pub fn new(config: CookieConfig) -> Self
Sourcepub fn rotate_secret(&self, new_secret: &[u8], version: u64)
pub fn rotate_secret(&self, new_secret: &[u8], version: u64)
Hot-swap the HMAC secret. Stale (≤ current) versions are ignored.
Sourcepub fn sign(&self, value: &str) -> String
pub fn sign(&self, value: &str) -> String
Returns "{value}.{base64url_hmac}" — the signed form stored in the cookie.
Sourcepub fn verify<'a>(&self, signed: &'a str) -> Option<&'a str>
pub fn verify<'a>(&self, signed: &'a str) -> Option<&'a str>
Verifies the HMAC signature and returns the original value if valid.
Tries the current secret, then the previous one (rotation grace
window). Returns None for any tampered, malformed, or missing
signature.
Auto Trait Implementations§
impl !Freeze for CookieService
impl RefUnwindSafe for CookieService
impl Send for CookieService
impl Sync for CookieService
impl Unpin for CookieService
impl UnsafeUnpin for CookieService
impl UnwindSafe for CookieService
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request