Skip to content

Commit f1c5c4f

Browse files
authored
Merge pull request #1205 from kristof-mattei/fix-rand-0.9-deprecations
fix rand 0.9 deprecations
2 parents c104b23 + 0d18b95 commit f1c5c4f

File tree

6 files changed

+11
-9
lines changed

6 files changed

+11
-9
lines changed

Diff for: .github/workflows/ci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ jobs:
7373
path: target
7474
key: check-wasm32-target-${{ runner.os }}-${{ steps.rust-version.outputs.version }}-${{ hashFiles('Cargo.lock') }}
7575
- run: cargo check --target wasm32-unknown-unknown --manifest-path tokio-postgres/Cargo.toml --no-default-features --features js
76+
env:
77+
RUSTFLAGS: --cfg getrandom_backend="wasm_js"
7678

7779
test:
7880
name: test

Diff for: postgres-protocol/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ readme = "../README.md"
1010

1111
[features]
1212
default = []
13-
js = ["getrandom/js"]
13+
js = ["getrandom/wasm_js"]
1414

1515
[dependencies]
1616
base64 = "0.22"
@@ -20,7 +20,7 @@ fallible-iterator = "0.2"
2020
hmac = "0.12"
2121
md-5 = "0.10"
2222
memchr = "2.0"
23-
rand = "0.8"
23+
rand = "0.9"
2424
sha2 = "0.10"
2525
stringprep = "0.1"
26-
getrandom = { version = "0.2", optional = true }
26+
getrandom = { version = "0.3", optional = true }

Diff for: postgres-protocol/src/authentication/sasl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ impl ScramSha256 {
136136
/// Constructs a new instance which will use the provided password for authentication.
137137
pub fn new(password: &[u8], channel_binding: ChannelBinding) -> ScramSha256 {
138138
// rand 0.5's ThreadRng is cryptographically secure
139-
let mut rng = rand::thread_rng();
139+
let mut rng = rand::rng();
140140
let nonce = (0..NONCE_LENGTH)
141141
.map(|_| {
142-
let mut v = rng.gen_range(0x21u8..0x7e);
142+
let mut v = rng.random_range(0x21u8..0x7e);
143143
if v == 0x2c {
144144
v = 0x7e
145145
}

Diff for: postgres-protocol/src/password/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const SCRAM_DEFAULT_SALT_LEN: usize = 16;
2828
/// special characters that would require escaping in an SQL command.
2929
pub fn scram_sha_256(password: &[u8]) -> String {
3030
let mut salt: [u8; SCRAM_DEFAULT_SALT_LEN] = [0; SCRAM_DEFAULT_SALT_LEN];
31-
let mut rng = rand::thread_rng();
31+
let mut rng = rand::rng();
3232
rng.fill_bytes(&mut salt);
3333
scram_sha_256_salt(password, salt)
3434
}

Diff for: tokio-postgres/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ postgres-protocol = { version = "0.6.7", path = "../postgres-protocol" }
5959
postgres-types = { version = "0.2.8", path = "../postgres-types" }
6060
tokio = { version = "1.27", features = ["io-util"] }
6161
tokio-util = { version = "0.7", features = ["codec"] }
62-
rand = "0.8.5"
62+
rand = "0.9.0"
6363
whoami = "1.4.1"
6464

6565
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]

Diff for: tokio-postgres/src/connect.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ where
4444

4545
let mut indices = (0..num_hosts).collect::<Vec<_>>();
4646
if config.load_balance_hosts == LoadBalanceHosts::Random {
47-
indices.shuffle(&mut rand::thread_rng());
47+
indices.shuffle(&mut rand::rng());
4848
}
4949

5050
let mut error = None;
@@ -101,7 +101,7 @@ where
101101
.collect::<Vec<_>>();
102102

103103
if config.load_balance_hosts == LoadBalanceHosts::Random {
104-
addrs.shuffle(&mut rand::thread_rng());
104+
addrs.shuffle(&mut rand::rng());
105105
}
106106

107107
let mut last_err = None;

0 commit comments

Comments
 (0)