From ef81a221a6a46784b5840fd8d5fce58ec01e7643 Mon Sep 17 00:00:00 2001 From: Chrislearn Young Date: Tue, 28 Jan 2025 07:01:29 +0800 Subject: [PATCH] chore(deps): update rand requirement from 0.8 to 0.9 (#1037) * chore(deps): update rand requirement from 0.8 to 0.9 * fmt --- Cargo.toml | 2 +- crates/core/src/http/form.rs | 10 +++++++--- crates/csrf/src/lib.rs | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a7c016a85..279b3eab5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -96,7 +96,7 @@ proc-macro2-diagnostics = { version = "0.10", default-features = true } proc-macro2 = "1" quinn = { version = "0.11", default-features = false } quote = "1" -rand = "0.8" +rand = "0.9" rcgen = "0.13" regex = "1" reqwest = { version = "0.12", default-features = false, features = ["rustls-tls", "charset", "http2", "macos-system-configuration"] } diff --git a/crates/core/src/http/form.rs b/crates/core/src/http/form.rs index 64733e5da..2d4516573 100644 --- a/crates/core/src/http/form.rs +++ b/crates/core/src/http/form.rs @@ -11,7 +11,7 @@ use mime::Mime; use multer::{Field, Multipart}; use multimap::MultiMap; use rand::rngs::OsRng; -use rand::RngCore; +use rand::TryRngCore; use tempfile::Builder; use tokio::fs::File; use tokio::io::AsyncWriteExt; @@ -213,9 +213,13 @@ fn text_nonce() -> String { Write::write_all(&mut cursor, &secs.to_le_bytes()).expect("write_all failed"); // Get the last bytes from random data - OsRng.fill_bytes(&mut raw[12..BYTE_LEN]); + OsRng + .try_fill_bytes(&mut raw[12..BYTE_LEN]) + .expect("OsRng.try_fill_bytes failed"); } else { - OsRng.fill_bytes(&mut raw[..]); + OsRng + .try_fill_bytes(&mut raw[..]) + .expect("OsRng.try_fill_bytes failed"); } // base64 encode diff --git a/crates/csrf/src/lib.rs b/crates/csrf/src/lib.rs index 45182263d..2ccb5e123 100644 --- a/crates/csrf/src/lib.rs +++ b/crates/csrf/src/lib.rs @@ -17,7 +17,7 @@ mod finder; pub use finder::{CsrfTokenFinder, FormFinder, HeaderFinder, JsonFinder}; -use rand::distributions::Standard; +use rand::distr::StandardUniform; use rand::Rng; use salvo_core::handler::Skipper; use salvo_core::http::{Method, StatusCode}; @@ -190,7 +190,7 @@ pub trait CsrfCipher: Send + Sync + 'static { /// Generate a random bytes. fn random_bytes(&self, len: usize) -> Vec { - rand::thread_rng().sample_iter(Standard).take(len).collect() + rand::rng().sample_iter(StandardUniform).take(len).collect() } }