Skip to content

Commit

Permalink
Fix returned lifetime in Signed/PrivateCookies::get()
Browse files Browse the repository at this point in the history
  • Loading branch information
akheron committed Jun 9, 2022
1 parent 3530030 commit 709624c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl<'a> PrivateCookies<'a> {
}

/// Returns `Cookie` with the `name` and decrypted contents.
pub fn get(&self, name: &str) -> Option<Cookie> {
pub fn get(&self, name: &str) -> Option<Cookie<'static>> {
let mut inner = self.cookies.inner.lock();
inner.jar().private(self.key).get(name)
}
Expand Down Expand Up @@ -90,10 +90,9 @@ mod tests {
fn remove() {
let key = Key::generate();
let cookies = Cookies::new(vec![]);
let cookie = Cookie::new("foo", "bar");
let private = cookies.private(&key);
private.add(cookie.clone());
assert!(private.get("foo").is_some());
private.add(Cookie::new("foo", "bar"));
let cookie = private.get("foo").unwrap();
private.remove(cookie);
assert!(private.get("foo").is_none());
}
Expand Down
7 changes: 3 additions & 4 deletions src/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl<'a> SignedCookies<'a> {
/// Returns `Cookie` with the `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.
pub fn get(&self, name: &str) -> Option<Cookie> {
pub fn get(&self, name: &str) -> Option<Cookie<'static>> {
let mut inner = self.cookies.inner.lock();
inner.jar().signed(self.key).get(name)
}
Expand Down Expand Up @@ -97,10 +97,9 @@ mod tests {
fn remove() {
let key = Key::generate();
let cookies = Cookies::new(vec![]);
let cookie = Cookie::new("foo", "bar");
let signed = cookies.signed(&key);
signed.add(cookie.clone());
assert!(signed.get("foo").is_some());
signed.add(Cookie::new("foo", "bar"));
let cookie = signed.get("foo").unwrap();
signed.remove(cookie);
assert!(signed.get("foo").is_none());
}
Expand Down

0 comments on commit 709624c

Please sign in to comment.