Skip to content

update rand to the latest version #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ paste = "1.0.6"
serde = { version = "1.0.132", features = ["derive"] }
serde_json = "1.0.73"
url = "2.2.2"
rand = "0.8"
rand = "0.9"
rand_xoshiro = "0.7.0"
hex = "0.4.3"
tempdir = "0.3.7"
Expand Down
2 changes: 1 addition & 1 deletion sqlx-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ memchr = { version = "2.4.1", default-features = false }
num-bigint = { version = "0.4.0", default-features = false, optional = true, features = ["std"] }
once_cell = "1.9.0"
percent-encoding = "2.1.0"
rand = { version = "0.8", default-features = false, optional = true, features = ["std", "std_rng"] }
rand = { version = "0.9", default-features = false, optional = true, features = ["std_rng", "small_rng", "thread_rng"] }
regex = { version = "1.5.5", optional = true }
rsa = { version = "0.9.2", optional = true }
rustls = { version = "0.23", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion sqlx-core/src/postgres/connection/establish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl PgConnection {
transaction_status,
transaction_depth: 0,
pending_ready_for_query_count: 0,
next_statement_id: Oid(rand::thread_rng().gen()),
next_statement_id: Oid(rand::rng().random()),
cache_statement: StatementCache::new(options.statement_cache_capacity),
cache_type_oid: HashMap::new(),
cache_type_info: HashMap::new(),
Expand Down
19 changes: 11 additions & 8 deletions sqlx-core/src/postgres/connection/sasl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,14 @@ pub(crate) async fn authenticate(
};

// nonce = "r=" c-nonce [s-nonce] ;; Second part provided by server.
let nonce = gen_nonce();
let client_nonce = gen_nonce();

// client-first-message-bare = [reserved-mext ","] username "," nonce ["," extensions]
let client_first_message_bare =
format!("{username},{nonce}", username = username, nonce = nonce);
let client_first_message_bare = format!(
"{username},{client_nonce}",
username = username,
client_nonce = client_nonce
);

let client_first_message = format!(
"{gs2_header}{client_first_message_bare}",
Expand Down Expand Up @@ -174,19 +177,19 @@ pub(crate) async fn authenticate(

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

// printable = %x21-2B / %x2D-7E
// ;; Printable ASCII except ",".
// ;; Note that any "printable" is also
// ;; a valid "value".
let nonce: String = std::iter::repeat(())
.map(|()| {
let mut c = rng.gen_range(0x21..0x7F) as u8;
let mut c = rng.random_range(0x21..0x7F) as u8;

while c == 0x2C {
c = rng.gen_range(0x21..0x7F) as u8;
c = rng.random_range(0x21..0x7F) as u8;
}

c
Expand All @@ -195,7 +198,7 @@ fn gen_nonce() -> String {
.map(|c| c as char)
.collect();

rng.gen_range(32..128);
rng.random_range(32..128);
format!("{}={}", NONCE_ATTR, nonce)
}

Expand Down
Loading