From 709624c1fefdedc72869b4e117a872f4249c3d49 Mon Sep 17 00:00:00 2001 From: Petri Lehtinen Date: Thu, 9 Jun 2022 21:00:41 +0300 Subject: [PATCH] Fix returned lifetime in Signed/PrivateCookies::get() --- src/private.rs | 7 +++---- src/signed.rs | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/private.rs b/src/private.rs index 75c1dd3..80bb220 100644 --- a/src/private.rs +++ b/src/private.rs @@ -25,7 +25,7 @@ impl<'a> PrivateCookies<'a> { } /// Returns `Cookie` with the `name` and decrypted contents. - pub fn get(&self, name: &str) -> Option { + pub fn get(&self, name: &str) -> Option> { let mut inner = self.cookies.inner.lock(); inner.jar().private(self.key).get(name) } @@ -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()); } diff --git a/src/signed.rs b/src/signed.rs index 6157cf0..c91afe1 100644 --- a/src/signed.rs +++ b/src/signed.rs @@ -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 { + pub fn get(&self, name: &str) -> Option> { let mut inner = self.cookies.inner.lock(); inner.jar().signed(self.key).get(name) } @@ -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()); }