pub struct CookieSealer {
key_bytes: [u8; 32],
rng: SystemRandom,
}Expand description
Seals and opens encrypted session cookies with a fixed derived key.
Fields§
§key_bytes: [u8; 32]§rng: SystemRandomImplementations§
Source§impl CookieSealer
impl CookieSealer
Sourcepub fn new(secret: &str) -> Self
pub fn new(secret: &str) -> Self
Derives the AES-256 key from secret (SHA-256), so any-length secrets
work. The same secret must be configured on every gateway instance.
fn key(&self) -> LessSafeKey
Sourcepub fn seal(&self, payload: &[u8], ttl: Duration) -> String
pub fn seal(&self, payload: &[u8], ttl: Duration) -> String
Seals payload into a cookie value that expires after ttl.
Layout of the returned base64url string:
nonce(12) || AES-256-GCM(expiry_be_u64(8) || payload). The expiry is
authenticated, so an attacker cannot extend a session.
Sourcepub fn open(&self, value: &str) -> Result<Vec<u8>, CookieError>
pub fn open(&self, value: &str) -> Result<Vec<u8>, CookieError>
Opens a sealed cookie value, returning the original payload.
Fails with CookieError if the value is malformed, authentication
fails (wrong key or tampering), or the embedded expiry has passed.
Auto Trait Implementations§
impl Freeze for CookieSealer
impl RefUnwindSafe for CookieSealer
impl Send for CookieSealer
impl Sync for CookieSealer
impl Unpin for CookieSealer
impl UnsafeUnpin for CookieSealer
impl UnwindSafe for CookieSealer
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more