Skip to content

Commit

Permalink
chore(deps): update rand requirement from 0.8 to 0.9 (#1037)
Browse files Browse the repository at this point in the history
* chore(deps): update rand requirement from 0.8 to 0.9

* fmt
  • Loading branch information
chrislearn authored Jan 27, 2025
1 parent 8529d60 commit ef81a22
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
10 changes: 7 additions & 3 deletions crates/core/src/http/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions crates/csrf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -190,7 +190,7 @@ pub trait CsrfCipher: Send + Sync + 'static {

/// Generate a random bytes.
fn random_bytes(&self, len: usize) -> Vec<u8> {
rand::thread_rng().sample_iter(Standard).take(len).collect()
rand::rng().sample_iter(StandardUniform).take(len).collect()
}
}

Expand Down

0 comments on commit ef81a22

Please sign in to comment.