pub struct PrivateJar<'a> { /* private fields */ }Expand description
A child cookie jar that provides authenticated encryption for its cookies.
A private child jar signs and encrypts all the cookies added to it and
verifies and decrypts cookies retrieved from it. Any cookies stored in a
PrivateJar are simultaneously assured confidentiality, integrity, and
authenticity. In other words, clients cannot discover nor tamper with the
contents of a cookie, nor can they fabricate cookie data.
This type is only available when the secure feature is enabled.
Implementations§
Source§impl<'a> PrivateJar<'a>
impl<'a> PrivateJar<'a>
Sourcepub fn get(&self, name: &str) -> Option<Cookie<'static>>
pub fn get(&self, name: &str) -> Option<Cookie<'static>>
Returns a reference to the Cookie inside this jar with the name name
and authenticates and decrypts the cookie’s value, returning a Cookie
with the decrypted value. If the cookie cannot be found, or the cookie
fails to authenticate or decrypt, None is returned.
§Example
use requiem_http::cookie::{CookieJar, Cookie, Key};
let key = Key::generate();
let mut jar = CookieJar::new();
let mut private_jar = jar.private(&key);
assert!(private_jar.get("name").is_none());
private_jar.add(Cookie::new("name", "value"));
assert_eq!(private_jar.get("name").unwrap().value(), "value");Sourcepub fn add(&mut self, cookie: Cookie<'static>)
pub fn add(&mut self, cookie: Cookie<'static>)
Adds cookie to the parent jar. The cookie’s value is encrypted with
authenticated encryption assuring confidentiality, integrity, and
authenticity.
§Example
use requiem_http::cookie::{CookieJar, Cookie, Key};
let key = Key::generate();
let mut jar = CookieJar::new();
jar.private(&key).add(Cookie::new("name", "value"));
assert_ne!(jar.get("name").unwrap().value(), "value");
assert_eq!(jar.private(&key).get("name").unwrap().value(), "value");Sourcepub fn add_original(&mut self, cookie: Cookie<'static>)
pub fn add_original(&mut self, cookie: Cookie<'static>)
Adds an “original” cookie to parent jar. The cookie’s value is
encrypted with authenticated encryption assuring confidentiality,
integrity, and authenticity. Adding an original cookie does not affect
the CookieJar::delta()
computation. This method is intended to be used to seed the cookie jar
with cookies received from a client’s HTTP message.
For accurate delta computations, this method should not be called
after calling remove.
§Example
use requiem_http::cookie::{CookieJar, Cookie, Key};
let key = Key::generate();
let mut jar = CookieJar::new();
jar.private(&key).add_original(Cookie::new("name", "value"));
assert_eq!(jar.iter().count(), 1);
assert_eq!(jar.delta().count(), 0);Sourcepub fn remove(&mut self, cookie: Cookie<'static>)
pub fn remove(&mut self, cookie: Cookie<'static>)
Removes cookie from the parent jar.
For correct removal, the passed in cookie must contain the same path
and domain as the cookie that was initially set.
See CookieJar::remove for more details.
§Example
use requiem_http::cookie::{CookieJar, Cookie, Key};
let key = Key::generate();
let mut jar = CookieJar::new();
let mut private_jar = jar.private(&key);
private_jar.add(Cookie::new("name", "value"));
assert!(private_jar.get("name").is_some());
private_jar.remove(Cookie::named("name"));
assert!(private_jar.get("name").is_none());Auto Trait Implementations§
impl<'a> Freeze for PrivateJar<'a>
impl<'a> RefUnwindSafe for PrivateJar<'a>
impl<'a> Send for PrivateJar<'a>
impl<'a> Sync for PrivateJar<'a>
impl<'a> Unpin for PrivateJar<'a>
impl<'a> !UnwindSafe for PrivateJar<'a>
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
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> 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> 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>
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>
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