Struct cookie::SignedJar [−][src]
pub struct SignedJar<'a> { /* fields omitted */ }
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
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");
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");
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);
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());