diff --git a/Cargo.toml b/Cargo.toml index b1d19441..6add9580 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "cookie" version = "0.18.1" authors = ["Sergio Benitez ", "Alex Crichton "] -edition = "2018" +edition = "2024" license = "MIT OR Apache-2.0" repository = "https://github.com/SergioBenitez/cookie-rs" documentation = "https://docs.rs/cookie" @@ -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 } diff --git a/src/jar.rs b/src/jar.rs index 29953103..b61201fd 100644 --- a/src/jar.rs +++ b/src/jar.rs @@ -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) } @@ -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) } @@ -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) } @@ -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) } diff --git a/src/lib.rs b/src/lib.rs index f666d2c3..1f34ef94 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; @@ -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) -> Result, ParseError> where S: Into> { @@ -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(string: S) -> SplitCookies<'c> where S: Into> @@ -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) @@ -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 diff --git a/src/secure/key.rs b/src/secure/key.rs index 8b62a933..a94c755b 100644 --- a/src/secure/key.rs +++ b/src/secure/key.rs @@ -1,3 +1,4 @@ +use rand::TryRngCore; use std::convert::TryFrom; const SIGNING_KEY_LEN: usize = 32; @@ -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 */]); @@ -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()); @@ -137,9 +138,7 @@ impl Key { /// let key = Key::try_generate(); /// ``` pub fn try_generate() -> Option { - 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) @@ -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 { diff --git a/src/secure/mod.rs b/src/secure/mod.rs index d88f940f..364aaf50 100644 --- a/src/secure/mod.rs +++ b/src/secure/mod.rs @@ -1,5 +1,3 @@ -extern crate rand; - mod base64 { use base64::{DecodeError, Engine, prelude::BASE64_STANDARD}; diff --git a/src/secure/private.rs b/src/secure/private.rs index 8caf86e5..d5c5e93a 100644 --- a/src/secure/private.rs +++ b/src/secure/private.rs @@ -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. @@ -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 { parent: J, key: [u8; KEY_LEN] @@ -50,7 +50,7 @@ impl PrivateJar { 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); diff --git a/src/secure/signed.rs b/src/secure/signed.rs index 9dbb732f..0633a21c 100644 --- a/src/secure/signed.rs +++ b/src/secure/signed.rs @@ -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 { parent: J, key: [u8; KEY_LEN],