Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "cookie"
version = "0.18.1"
authors = ["Sergio Benitez <[email protected]>", "Alex Crichton <[email protected]>"]
edition = "2018"
edition = "2024"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit too aggressive. Why bump MSRV to 1.85 when you're not benefiting from it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! We want to keep the MSRV as low as possible.

license = "MIT OR Apache-2.0"
repository = "https://github.com/SergioBenitez/cookie-rs"
documentation = "https://docs.rs/cookie"
Expand All @@ -29,7 +29,7 @@ aes-gcm = { version = "0.10.0", optional = true }
hmac = { version = "0.12.0", optional = true }
sha2 = { version = "0.10.0", optional = true }
base64 = { version = "0.22", optional = true }
rand = { version = "0.8", optional = true }
rand = { version = "0.9", optional = true }
hkdf = { version = "0.12.0", optional = true }
subtle = { version = "2.3", optional = true }

Expand Down
8 changes: 4 additions & 4 deletions src/jar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ impl CookieJar {
/// assert!(jar.get("private").is_some());
/// ```
#[cfg(feature = "private")]
#[cfg_attr(all(nightly, doc), doc(cfg(feature = "private")))]
#[cfg_attr(doc, doc(cfg(feature = "private")))]
pub fn private<'a>(&'a self, key: &Key) -> PrivateJar<&'a Self> {
PrivateJar::new(self, key)
}
Expand Down Expand Up @@ -438,7 +438,7 @@ impl CookieJar {
/// jar.private_mut(&key).remove("private");
/// ```
#[cfg(feature = "private")]
#[cfg_attr(all(nightly, doc), doc(cfg(feature = "private")))]
#[cfg_attr(doc, doc(cfg(feature = "private")))]
pub fn private_mut<'a>(&'a mut self, key: &Key) -> PrivateJar<&'a mut Self> {
PrivateJar::new(self, key)
}
Expand Down Expand Up @@ -473,7 +473,7 @@ impl CookieJar {
/// assert!(jar.get("signed").is_some());
/// ```
#[cfg(feature = "signed")]
#[cfg_attr(all(nightly, doc), doc(cfg(feature = "signed")))]
#[cfg_attr(doc, doc(cfg(feature = "signed")))]
pub fn signed<'a>(&'a self, key: &Key) -> SignedJar<&'a Self> {
SignedJar::new(self, key)
}
Expand All @@ -500,7 +500,7 @@ impl CookieJar {
/// jar.signed_mut(&key).remove("signed");
/// ```
#[cfg(feature = "signed")]
#[cfg_attr(all(nightly, doc), doc(cfg(feature = "signed")))]
#[cfg_attr(doc, doc(cfg(feature = "signed")))]
pub fn signed_mut<'a>(&'a mut self, key: &Key) -> SignedJar<&'a mut Self> {
SignedJar::new(self, key)
}
Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@
//! features = ["secure", "percent-encode"]
//! ```

#![cfg_attr(all(nightly, doc), feature(doc_cfg))]
#![cfg_attr(doc, feature(doc_cfg))]

#![deny(missing_docs)]
#![deny(warnings, missing_docs)]

pub use time;

Expand Down Expand Up @@ -362,7 +362,7 @@ impl<'c> Cookie<'c> {
/// assert_eq!(c.secure(), None);
/// ```
#[cfg(feature = "percent-encode")]
#[cfg_attr(all(nightly, doc), doc(cfg(feature = "percent-encode")))]
#[cfg_attr(doc, doc(cfg(feature = "percent-encode")))]
pub fn parse_encoded<S>(s: S) -> Result<Cookie<'c>, ParseError>
where S: Into<Cow<'c, str>>
{
Expand Down Expand Up @@ -437,7 +437,7 @@ impl<'c> Cookie<'c> {
/// }
/// ```
#[cfg(feature = "percent-encode")]
#[cfg_attr(all(nightly, doc), doc(cfg(feature = "percent-encode")))]
#[cfg_attr(doc, doc(cfg(feature = "percent-encode")))]
#[inline(always)]
pub fn split_parse_encoded<S>(string: S) -> SplitCookies<'c>
where S: Into<Cow<'c, str>>
Expand Down Expand Up @@ -1386,7 +1386,7 @@ impl<'c> Cookie<'c> {
/// assert_eq!(&c.encoded().stripped().to_string(), "my%20name=this%3B%20value%3F");
/// ```
#[cfg(feature = "percent-encode")]
#[cfg_attr(all(nightly, doc), doc(cfg(feature = "percent-encode")))]
#[cfg_attr(doc, doc(cfg(feature = "percent-encode")))]
#[inline(always)]
pub fn encoded<'a>(&'a self) -> Display<'a, 'c> {
Display::new_encoded(self)
Expand Down Expand Up @@ -1565,7 +1565,7 @@ impl<'a, 'c> Display<'a, 'c> {
/// Percent-encode the name and value pair.
#[inline]
#[cfg(feature = "percent-encode")]
#[cfg_attr(all(nightly, doc), doc(cfg(feature = "percent-encode")))]
#[cfg_attr(doc, doc(cfg(feature = "percent-encode")))]
pub fn encoded(mut self) -> Self {
self.encode = true;
self
Expand Down
11 changes: 5 additions & 6 deletions src/secure/key.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use rand::TryRngCore;
use std::convert::TryFrom;

const SIGNING_KEY_LEN: usize = 32;
Expand All @@ -16,7 +17,7 @@ const_assert!(crate::secure::private::KEY_LEN == ENCRYPTION_KEY_LEN);
/// [`PrivateJar`](crate::PrivateJar) and [`SignedJar`](crate::SignedJar). A
/// single instance of a `Key` can be used for both a `PrivateJar` and a
/// `SignedJar` simultaneously with no notable security implications.
#[cfg_attr(all(nightly, doc), doc(cfg(any(feature = "private", feature = "signed"))))]
#[cfg_attr(doc, doc(cfg(any(feature = "private", feature = "signed"))))]
#[derive(Clone)]
pub struct Key([u8; COMBINED_KEY_LENGTH /* SIGNING | ENCRYPTION */]);

Expand Down Expand Up @@ -92,7 +93,7 @@ impl Key {
/// let key = Key::derive_from(master_key);
/// ```
#[cfg(feature = "key-expansion")]
#[cfg_attr(all(nightly, doc), doc(cfg(feature = "key-expansion")))]
#[cfg_attr(doc, doc(cfg(feature = "key-expansion")))]
pub fn derive_from(master_key: &[u8]) -> Self {
if master_key.len() < 32 {
panic!("bad master key length: expected >= 32 bytes, found {}", master_key.len());
Expand Down Expand Up @@ -137,9 +138,7 @@ impl Key {
/// let key = Key::try_generate();
/// ```
pub fn try_generate() -> Option<Key> {
use crate::secure::rand::RngCore;

let mut rng = crate::secure::rand::thread_rng();
let mut rng = rand::rng();
let mut key = Key::zero();
rng.try_fill_bytes(&mut key.0).ok()?;
Some(key)
Expand Down Expand Up @@ -192,7 +191,7 @@ impl Key {
}

/// An error indicating an issue with generating or constructing a key.
#[cfg_attr(all(nightly, doc), doc(cfg(any(feature = "private", feature = "signed"))))]
#[cfg_attr(doc, doc(cfg(any(feature = "private", feature = "signed"))))]
#[derive(Debug)]
#[non_exhaustive]
pub enum KeyError {
Expand Down
2 changes: 0 additions & 2 deletions src/secure/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate rand;

mod base64 {
use base64::{DecodeError, Engine, prelude::BASE64_STANDARD};

Expand Down
8 changes: 4 additions & 4 deletions src/secure/private.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
extern crate aes_gcm;

use rand::TryRngCore;
use std::convert::TryInto;
use std::borrow::{Borrow, BorrowMut};

use crate::secure::{base64, rand, Key};
use crate::secure::{base64, Key};
use crate::{Cookie, CookieJar};

use self::aes_gcm::aead::{generic_array::GenericArray, Aead, AeadInPlace, KeyInit, Payload};
use self::aes_gcm::Aes256Gcm;
use self::rand::RngCore;

// Keep these in sync, and keep the key len synced with the `private` docs as
// well as the `KEYS_INFO` const in secure::Key.
Expand All @@ -23,7 +23,7 @@ pub(crate) const KEY_LEN: usize = 32;
/// `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.
#[cfg_attr(all(nightly, doc), doc(cfg(feature = "private")))]
#[cfg_attr(doc, doc(cfg(feature = "private")))]
pub struct PrivateJar<J> {
parent: J,
key: [u8; KEY_LEN]
Expand All @@ -50,7 +50,7 @@ impl<J> PrivateJar<J> {
in_out.copy_from_slice(cookie_val);

// Fill nonce piece with random data.
let mut rng = self::rand::thread_rng();
let mut rng = rand::rng();
rng.try_fill_bytes(nonce).expect("couldn't random fill nonce");
let nonce = GenericArray::clone_from_slice(nonce);

Expand Down
2 changes: 1 addition & 1 deletion src/secure/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub(crate) const KEY_LEN: usize = 32;
/// 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.
#[cfg_attr(all(nightly, doc), doc(cfg(feature = "signed")))]
#[cfg_attr(doc, doc(cfg(feature = "signed")))]
pub struct SignedJar<J> {
parent: J,
key: [u8; KEY_LEN],
Expand Down