Skip to content

Commit c18f020

Browse files
author
Boquan Fang
committed
build(deps): update rand requirement except for s2n-quic-sim
1 parent 00e3371 commit c18f020

File tree

12 files changed

+21
-33
lines changed

12 files changed

+21
-33
lines changed

dc/s2n-quic-dc/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ libc = "0.2"
3131
num-rational = { version = "0.4", default-features = false }
3232
once_cell = "1"
3333
pin-project-lite = "0.2"
34-
rand = { version = "0.8", features = ["small_rng"] }
35-
rand_chacha = "0.3"
34+
rand = { version = "0.9", features = ["small_rng"] }
35+
rand_chacha = "0.9"
3636
s2n-codec = { version = "=0.53.0", path = "../../common/s2n-codec", default-features = false }
3737
s2n-quic-core = { version = "=0.53.0", path = "../../quic/s2n-quic-core", default-features = false }
3838
s2n-quic-platform = { version = "=0.53.0", path = "../../quic/s2n-quic-platform" }

dc/s2n-quic-dc/src/path/secret/map/cleaner.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl Cleaner {
6868
let pause = if cfg!(test) {
6969
60
7070
} else {
71-
rand::thread_rng().gen_range(5..60)
71+
rand::rng().random_range(5..60)
7272
};
7373
std::thread::park_timeout(Duration::from_secs(pause));
7474

dc/s2n-quic-dc/src/path/secret/map/entry.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl Entry {
257257
// The goal of rescheduling is to avoid continuously re-handshaking for N (possibly stale)
258258
// peers every cleaner loop, instead we defer handshakes out again. This effectively acts
259259
// as a (slow) retry mechanism.
260-
let delta = rand::thread_rng().gen_range(
260+
let delta = rand::rng().random_range(
261261
std::cmp::min(rehandshake_period.as_secs(), 360)..rehandshake_period.as_secs(),
262262
) as u32;
263263
// This can't practically overflow -- each time we add we push out the next add by at least

dc/s2n-quic-dc/src/path/secret/receiver/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ fn check_delayed_inner(seed: u64, delay: u16) {
197197
// explanation for what guarantees we're actually trying to provide here).
198198
if id % 128 != 0 {
199199
// ...until some random interval no more than WINDOW away.
200-
let insert_before = rng.gen_range(id + 1 + delay..id + WINDOW as u64);
200+
let insert_before = rng.random_range(id + 1 + delay..id + WINDOW as u64);
201201
buffered.push((std::cmp::Reverse(insert_before), id));
202202
} else {
203203
model.insert(id);

dc/s2n-quic-dc/src/random.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use rand::{rngs::adapter::ReseedingRng, RngCore, SeedableRng};
4+
use rand::{rngs::ReseedingRng, RngCore};
55
use rand_chacha::ChaChaCore;
66

77
pub use s2n_quic_core::random::*;
@@ -25,12 +25,7 @@ impl RngCore for AwsLc {
2525

2626
#[inline]
2727
fn fill_bytes(&mut self, dest: &mut [u8]) {
28-
self.try_fill_bytes(dest).unwrap()
29-
}
30-
31-
#[inline]
32-
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand::Error> {
33-
aws_lc_rs::rand::fill(dest).map_err(rand::Error::new)
28+
aws_lc_rs::rand::fill(dest).unwrap()
3429
}
3530
}
3631

@@ -58,10 +53,8 @@ fn build_rng() -> ReseedingRng<ChaChaCore, AwsLc> {
5853
// This value is based on THREAD_RNG_RESEED_THRESHOLD from
5954
// [rand::rngs::thread.rs](https://github.com/rust-random/rand/blob/ef75e56cf5824d33c55622bf84a70ec6e22761ba/src/rngs/thread.rs#L39)
6055
const RESEED_THRESHOLD: u64 = 1024 * 64;
61-
62-
let prng = ChaChaCore::from_rng(AwsLc)
63-
.unwrap_or_else(|err| panic!("could not initialize random generator: {err}"));
64-
ReseedingRng::new(prng, RESEED_THRESHOLD, AwsLc)
56+
ReseedingRng::<ChaChaCore, AwsLc>::new(RESEED_THRESHOLD, AwsLc)
57+
.unwrap_or_else(|err| panic!("could not initialize random generator: {err}"))
6558
}
6659

6760
impl Generator for Random {

quic/s2n-quic-qns/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ futures = "0.3"
2222
http = "1.0"
2323
humansize = "2"
2424
lru = "0.13"
25-
rand = "0.8"
25+
rand = "0.9"
2626
s2n-codec = { path = "../../common/s2n-codec" }
2727
s2n-quic-core = { path = "../s2n-quic-core", features = ["testing"] }
2828
s2n-quic-h3 = { path = "../s2n-quic-h3" }

quic/s2n-quic-qns/src/intercept.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
use lru::LruCache;
5-
use rand::prelude::*;
5+
use rand::{Rng as _, RngCore};
66
use s2n_codec::encoder::scatter;
77
use s2n_quic_core::{
88
event::api::Subject,
@@ -31,7 +31,7 @@ struct Random;
3131

3232
impl havoc::Random for Random {
3333
fn fill(&mut self, bytes: &mut [u8]) {
34-
thread_rng().fill_bytes(bytes);
34+
rand::rng().fill_bytes(bytes);
3535
}
3636

3737
fn gen_range(&mut self, range: std::ops::Range<u64>) -> u64 {
@@ -43,7 +43,7 @@ impl havoc::Random for Random {
4343
return start;
4444
}
4545

46-
thread_rng().gen_range(start..end)
46+
rand::rng().random_range(start..end)
4747
}
4848
}
4949

quic/s2n-quic/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ cuckoofilter = { version = "0.5", optional = true }
6969
futures = { version = "0.3", default-features = false, features = ["std"] }
7070
hash_hasher = { version = "2", optional = true }
7171
humansize = { version = "2", optional = true }
72-
rand = "0.8"
73-
rand_chacha = "0.3"
72+
rand = "0.9"
73+
rand_chacha = "0.9"
7474
s2n-codec = { version = "=0.53.0", path = "../../common/s2n-codec" }
7575
s2n-quic-core = { version = "=0.53.0", path = "../s2n-quic-core" }
7676
s2n-quic-crypto = { version = "=0.53.0", path = "../s2n-quic-crypto", optional = true }

quic/s2n-quic/src/provider/connection_id.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ pub mod default {
143143
fn generate(&mut self, _connection_info: &ConnectionInfo) -> connection::LocalId {
144144
let mut id = [0u8; connection::id::MAX_LEN];
145145
let id = &mut id[..self.len];
146-
rand::thread_rng().fill_bytes(id);
146+
rand::rng().fill_bytes(id);
147147
(&*id).try_into().expect("length already checked")
148148
}
149149

quic/s2n-quic/src/provider/random.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ mod rand {
1919
use core::convert::Infallible;
2020
use rand::{
2121
prelude::*,
22-
rngs::{adapter::ReseedingRng, OsRng},
22+
rngs::{OsRng, ReseedingRng},
2323
};
2424
use rand_chacha::ChaChaCore;
2525
use s2n_quic_core::random;
@@ -71,9 +71,8 @@ mod rand {
7171
// Constructs a `ReseedingRng` with a ChaCha RNG initially seeded from the OS,
7272
// that will reseed from the OS after RESEED_THRESHOLD is exceeded
7373
fn build_rng() -> ReseedingRng<ChaChaCore, OsRng> {
74-
let prng = ChaChaCore::from_rng(OsRng)
75-
.unwrap_or_else(|err| panic!("could not initialize random generator: {err}"));
76-
ReseedingRng::new(prng, RESEED_THRESHOLD, OsRng)
74+
ReseedingRng::<ChaChaCore, OsRng>::new(RESEED_THRESHOLD, OsRng)
75+
.unwrap_or_else(|err| panic!("could not initialize random generator: {err}"))
7776
}
7877

7978
impl random::Generator for Generator {

quic/s2n-quic/src/provider/stateless_reset_token.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ mod random {
8383
// be generated the same for a given `local_connection_id` before and after loss of state.
8484
fn generate(&mut self, _local_connection_id: &[u8]) -> stateless_reset::Token {
8585
let mut token = [0u8; STATELESS_RESET_TOKEN_LEN];
86-
rand::thread_rng().fill_bytes(&mut token);
86+
rand::rng().fill_bytes(&mut token);
8787
token.into()
8888
}
8989
}

quic/s2n-quic/src/tests/setup.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,11 @@ impl havoc::Random for Random {
175175
}
176176

177177
fn gen_range(&mut self, range: std::ops::Range<u64>) -> u64 {
178-
self.inner.gen_range(range)
178+
self.inner.random_range(range)
179179
}
180180
}
181181

182182
impl RngCore for Random {
183-
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand::Error> {
184-
self.inner.try_fill_bytes(dest)
185-
}
186-
187183
fn fill_bytes(&mut self, dest: &mut [u8]) {
188184
self.inner.fill_bytes(dest)
189185
}

0 commit comments

Comments
 (0)