http_types::cookies

Struct SignedJar

Source
pub struct SignedJar<'a> { /* private fields */ }
Available on crate feature signed only.
Expand description

A child cookie jar that authenticates its cookies.

A signed child jar signs all the cookies added to it and verifies cookies retrieved from it. Any cookies stored in a SignedJar are provided integrity and authenticity. In other words, clients cannot tamper with the contents of a cookie nor can they fabricate cookie values, but the data is visible in plaintext.

Implementations§

Source§

impl<'a> SignedJar<'a>

Source

pub fn get(&self, name: &str) -> Option<Cookie<'static>>

Returns a reference to the Cookie inside this jar with the name name and verifies the authenticity and integrity of the cookie’s value, returning a Cookie with the authenticated value. If the cookie cannot be found, or the cookie fails to verify, None is returned.

§Example
use cookie::{CookieJar, Cookie, Key};

let key = Key::generate();
let mut jar = CookieJar::new();
let mut signed_jar = jar.signed(&key);
assert!(signed_jar.get("name").is_none());

signed_jar.add(Cookie::new("name", "value"));
assert_eq!(signed_jar.get("name").unwrap().value(), "value");
Source

pub fn add(&mut self, cookie: Cookie<'static>)

Adds cookie to the parent jar. The cookie’s value is signed assuring integrity and authenticity.

§Example
use cookie::{CookieJar, Cookie, Key};

let key = Key::generate();
let mut jar = CookieJar::new();
jar.signed(&key).add(Cookie::new("name", "value"));

assert_ne!(jar.get("name").unwrap().value(), "value");
assert!(jar.get("name").unwrap().value().contains("value"));
assert_eq!(jar.signed(&key).get("name").unwrap().value(), "value");
Source

pub fn add_original(&mut self, cookie: Cookie<'static>)

Adds an “original” cookie to this jar. The cookie’s value is signed assuring 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 cookie::{CookieJar, Cookie, Key};

let key = Key::generate();
let mut jar = CookieJar::new();
jar.signed(&key).add_original(Cookie::new("name", "value"));

assert_eq!(jar.iter().count(), 1);
assert_eq!(jar.delta().count(), 0);
Source

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 cookie::{CookieJar, Cookie, Key};

let key = Key::generate();
let mut jar = CookieJar::new();
let mut signed_jar = jar.signed(&key);

signed_jar.add(Cookie::new("name", "value"));
assert!(signed_jar.get("name").is_some());

signed_jar.remove(Cookie::named("name"));
assert!(signed_jar.get("name").is_none());

Auto Trait Implementations§

§

impl<'a> Freeze for SignedJar<'a>

§

impl<'a> RefUnwindSafe for SignedJar<'a>

§

impl<'a> Send for SignedJar<'a>

§

impl<'a> Sync for SignedJar<'a>

§

impl<'a> Unpin for SignedJar<'a>

§

impl<'a> !UnwindSafe for SignedJar<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T