Skip to content

Commit 5505e78

Browse files
committed
chore: update rand, crypto crates (2)
1 parent e1ca73d commit 5505e78

9 files changed

Lines changed: 24 additions & 28 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ digest = { version = "0.11.2", default-features = false, features = ["alloc"] }
200200
hkdf = { version = "0.13.0" }
201201
hmac = { version = "0.13.0", default-features = false }
202202
md-5 = { version = "0.11.0", default-features = false }
203-
rsa = { version = "0.9" }
203+
rsa = { version = "0.10.0-rc.18" } # FIXME: when `rsa 0.10` is released
204204
rand = { version = "0.10.1", features = ["thread_rng"], default-features = false }
205205
sha1 = { version = "0.11.0", default-features = false }
206206
sha2 = { version = "0.11.0", default-features = false }

clippy.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
doc-valid-idents = ["SQLite"]
2+
13
[[disallowed-methods]]
24
path = "core::cmp::Ord::min"
35
reason = '''

sqlx-mysql/src/connection/auth.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use bytes::buf::Chain;
22
use bytes::Bytes;
3-
use digest::{Digest, OutputSizeUser};
4-
use generic_array::GenericArray;
3+
use digest::Digest;
54
use sha1::Sha1;
65
use sha2::Sha256;
76

@@ -74,10 +73,7 @@ impl AuthPlugin {
7473
}
7574
}
7675

77-
fn scramble_sha1(
78-
password: &str,
79-
nonce: &Chain<Bytes, Bytes>,
80-
) -> GenericArray<u8, <Sha1 as OutputSizeUser>::OutputSize> {
76+
fn scramble_sha1(password: &str, nonce: &Chain<Bytes, Bytes>) -> Vec<u8> {
8177
// SHA1( password ) ^ SHA1( seed + SHA1( SHA1( password ) ) )
8278
// https://mariadb.com/kb/en/connection/#mysql_native_password-plugin
8379

@@ -99,13 +95,10 @@ fn scramble_sha1(
9995

10096
xor_eq(&mut pw_hash, &pw_seed_hash_hash);
10197

102-
pw_hash
98+
pw_hash.to_vec()
10399
}
104100

105-
fn scramble_sha256(
106-
password: &str,
107-
nonce: &Chain<Bytes, Bytes>,
108-
) -> GenericArray<u8, <Sha256 as OutputSizeUser>::OutputSize> {
101+
fn scramble_sha256(password: &str, nonce: &Chain<Bytes, Bytes>) -> Vec<u8> {
109102
// XOR(SHA256(password), SHA256(SHA256(SHA256(password)), seed))
110103
// Order matches the server-side verification in MySQL's sha2_password
111104
// (generate_sha2_scramble): stage2 digest first, then the nonce.
@@ -127,7 +120,7 @@ fn scramble_sha256(
127120

128121
xor_eq(&mut pw_hash, &pw_seed_hash_hash);
129122

130-
pw_hash
123+
pw_hash.to_vec()
131124
}
132125

133126
async fn encrypt_rsa<'s>(
@@ -185,15 +178,14 @@ fn to_asciz(s: &str) -> Vec<u8> {
185178

186179
#[cfg(feature = "rsa")]
187180
mod rsa_backend {
188-
use rand::thread_rng;
189181
use rsa::{pkcs8::DecodePublicKey, Oaep, RsaPublicKey};
190182

191183
use super::Error;
192184

193185
pub(super) fn encrypt(rsa_pub_key: &[u8], pass: &[u8]) -> Result<Vec<u8>, Error> {
194186
let pkey = parse_rsa_pub_key(rsa_pub_key)?;
195-
let padding = Oaep::new::<sha1::Sha1>();
196-
pkey.encrypt(&mut thread_rng(), padding, pass)
187+
let padding = Oaep::<sha1::Sha1>::new();
188+
pkey.encrypt(&mut rand::rng(), padding, pass)
197189
.map_err(Error::protocol)
198190
}
199191

sqlx-postgres/src/any.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl AnyConnectionBackend for PgConnection {
8383
query: SqlStr,
8484
persistent: bool,
8585
arguments: Option<AnyArguments>,
86-
) -> BoxStream<sqlx_core::Result<Either<AnyQueryResult, AnyRow>>> {
86+
) -> BoxStream<'_, sqlx_core::Result<Either<AnyQueryResult, AnyRow>>> {
8787
let persistent = persistent && arguments.is_some();
8888
let arguments = match arguments.map(AnyArguments::convert_into).transpose() {
8989
Ok(arguments) => arguments,
@@ -109,7 +109,7 @@ impl AnyConnectionBackend for PgConnection {
109109
query: SqlStr,
110110
persistent: bool,
111111
arguments: Option<AnyArguments>,
112-
) -> BoxFuture<sqlx_core::Result<Option<AnyRow>>> {
112+
) -> BoxFuture<'_, sqlx_core::Result<Option<AnyRow>>> {
113113
let persistent = persistent && arguments.is_some();
114114
let arguments = arguments
115115
.map(AnyArguments::convert_into)

sqlx-postgres/src/connection/sasl.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ use crate::message::{Authentication, AuthenticationSasl, SaslInitialResponse, Sa
44
use crate::rt;
55
use crate::PgConnectOptions;
66
use hmac::{Hmac, Mac};
7-
use rand::Rng;
7+
use hmac::{HmacReset, KeyInit};
88
use sha2::{Digest, Sha256};
99
use stringprep::saslprep;
1010

1111
use base64::prelude::{Engine as _, BASE64_STANDARD};
12+
use rand::RngExt;
1213

1314
const GS2_HEADER: &str = "n,,";
1415
const CHANNEL_ATTR: &str = "c";
@@ -172,19 +173,19 @@ pub(crate) async fn authenticate(
172173

173174
// nonce is a sequence of random printable bytes
174175
fn gen_nonce() -> String {
175-
let mut rng = rand::thread_rng();
176-
let count = rng.gen_range(64..128);
176+
let mut rng = rand::rng();
177+
let count = rng.random_range(64..128);
177178

178179
// printable = %x21-2B / %x2D-7E
179180
// ;; Printable ASCII except ",".
180181
// ;; Note that any "printable" is also
181182
// ;; a valid "value".
182183
let nonce: String = std::iter::repeat(())
183184
.map(|()| {
184-
let mut c = rng.gen_range(0x21u8..0x7F);
185+
let mut c = rng.random_range(0x21u8..0x7F);
185186

186187
while c == 0x2C {
187-
c = rng.gen_range(0x21u8..0x7F);
188+
c = rng.random_range(0x21u8..0x7F);
188189
}
189190

190191
c
@@ -193,13 +194,12 @@ fn gen_nonce() -> String {
193194
.map(|c| c as char)
194195
.collect();
195196

196-
rng.gen_range(32..128);
197197
format!("{NONCE_ATTR}={nonce}")
198198
}
199199

200200
// Hi(str, salt, i):
201201
async fn hi<'a>(s: &'a str, salt: &'a [u8], iter_count: u32) -> Result<[u8; 32], Error> {
202-
let mut mac = Hmac::<Sha256>::new_from_slice(s.as_bytes()).map_err(Error::protocol)?;
202+
let mut mac = HmacReset::<Sha256>::new_from_slice(s.as_bytes()).map_err(Error::protocol)?;
203203

204204
mac.update(salt);
205205
mac.update(&1u32.to_be_bytes());

sqlx-postgres/src/message/flush.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::num::Saturating;
88
/// A Flush must be sent after any extended-query command except Sync, if the
99
/// frontend wishes to examine the results of that command before issuing more commands.
1010
#[derive(Debug)]
11+
#[expect(dead_code)]
1112
pub struct Flush;
1213

1314
impl FrontendMessage for Flush {

sqlx-postgres/src/message/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ pub enum FrontendMessageFormat {
7373
CopyFail = b'f',
7474
Describe = b'D',
7575
Execute = b'E',
76+
#[expect(dead_code)]
7677
Flush = b'H',
7778
Parse = b'P',
7879
/// This message format is polymorphic. It's used for:

sqlx-sqlite/src/connection/intmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<V> IntMap<V> {
6565
pub(crate) fn insert(&mut self, idx: i64, value: V) -> Option<V> {
6666
let idx: usize = self.expand(idx);
6767

68-
std::mem::replace(&mut self.0[idx], Some(value))
68+
self.0[idx].replace(value)
6969
}
7070

7171
pub(crate) fn remove(&mut self, idx: &i64) -> Option<V> {

sqlx-sqlite/src/regexp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ unsafe extern "C" fn sqlite3_regexp_func(
6868
}
6969

7070
// arg0: Regex
71-
let Some(regex) = get_regex_from_arg(ctx, *args.offset(0), 0) else {
71+
let Some(regex) = get_regex_from_arg(ctx, *args, 0) else {
7272
return;
7373
};
7474

7575
// arg1: value
76-
let Some(value) = get_text_from_arg(ctx, *args.offset(1)) else {
76+
let Some(value) = get_text_from_arg(ctx, *args.add(1)) else {
7777
return;
7878
};
7979

0 commit comments

Comments
 (0)