Skip to content

Update rand to 0.9.x #788

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

Merged
merged 1 commit into from
Apr 16, 2025
Merged
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
372 changes: 106 additions & 266 deletions Cargo-minimal.lock

Large diffs are not rendered by default.

120 changes: 88 additions & 32 deletions Cargo-recent.lock
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ dependencies = [
"hex-conservative",
]

[[package]]
name = "bitflags"
version = "2.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd"

[[package]]
name = "bumpalo"
version = "3.12.0"
Expand Down Expand Up @@ -69,13 +75,14 @@ dependencies = [

[[package]]
name = "getrandom"
version = "0.2.8"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0"
dependencies = [
"cfg-if",
"js-sys",
"libc",
"r-efi",
"wasi",
"wasm-bindgen",
]
Expand Down Expand Up @@ -103,18 +110,19 @@ checksum = "3011d1213f159867b13cfd6ac92d2cd5f1345762c63be3554e84092d85a50bbd"

[[package]]
name = "js-sys"
version = "0.3.61"
version = "0.3.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730"
checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f"
dependencies = [
"once_cell",
"wasm-bindgen",
]

[[package]]
name = "libc"
version = "0.2.140"
version = "0.2.171"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c"
checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6"

[[package]]
name = "log"
Expand All @@ -139,52 +147,64 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"

[[package]]
name = "proc-macro2"
version = "1.0.52"
version = "1.0.94"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224"
checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84"
dependencies = [
"unicode-ident",
]

[[package]]
name = "quote"
version = "1.0.26"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc"
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
dependencies = [
"proc-macro2",
]

[[package]]
name = "r-efi"
version = "5.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5"

[[package]]
name = "rand"
version = "0.8.5"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
"zerocopy",
]

[[package]]
name = "rand_chacha"
version = "0.3.1"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
dependencies = [
"ppv-lite86",
"rand_core",
]

[[package]]
name = "rand_core"
version = "0.6.4"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
dependencies = [
"getrandom",
]

[[package]]
name = "rustversion"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2"

[[package]]
name = "scoped-tls"
version = "1.0.1"
Expand Down Expand Up @@ -244,9 +264,9 @@ dependencies = [

[[package]]
name = "syn"
version = "1.0.109"
version = "2.0.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0"
dependencies = [
"proc-macro2",
"quote",
Expand All @@ -261,29 +281,33 @@ checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"

[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
version = "0.14.2+wasi-0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3"
dependencies = [
"wit-bindgen-rt",
]

[[package]]
name = "wasm-bindgen"
version = "0.2.84"
version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b"
checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5"
dependencies = [
"cfg-if",
"once_cell",
"rustversion",
"wasm-bindgen-macro",
]

[[package]]
name = "wasm-bindgen-backend"
version = "0.2.84"
version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9"
checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6"
dependencies = [
"bumpalo",
"log",
"once_cell",
"proc-macro2",
"quote",
"syn",
Expand All @@ -304,19 +328,19 @@ dependencies = [

[[package]]
name = "wasm-bindgen-macro"
version = "0.2.84"
version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5"
checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]

[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.84"
version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6"
checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de"
dependencies = [
"proc-macro2",
"quote",
Expand All @@ -327,9 +351,12 @@ dependencies = [

[[package]]
name = "wasm-bindgen-shared"
version = "0.2.84"
version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d"
checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d"
dependencies = [
"unicode-ident",
]

[[package]]
name = "wasm-bindgen-test"
Expand Down Expand Up @@ -364,3 +391,32 @@ dependencies = [
"js-sys",
"wasm-bindgen",
]

[[package]]
name = "wit-bindgen-rt"
version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1"
dependencies = [
"bitflags",
]

[[package]]
name = "zerocopy"
version = "0.8.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2586fea28e186957ef732a5f8b3be2da217d65c5969d4b1e17f973ebbe876879"
dependencies = [
"zerocopy-derive",
]

[[package]]
name = "zerocopy-derive"
version = "0.8.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a996a8f63c5c4448cd959ac1bab0aaa3306ccfd060472f85943ee0750f0169be"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["std"]
std = ["alloc", "secp256k1-sys/std", "rand?/std", "rand?/std_rng", "hashes?/std"]
std = ["alloc", "secp256k1-sys/std", "rand?/std", "rand?/std_rng", "rand?/thread_rng", "hashes?/std"]
# allow use of Secp256k1::new and related API that requires an allocator
alloc = ["secp256k1-sys/alloc"]
recovery = ["secp256k1-sys/recovery"]
Expand All @@ -37,19 +37,19 @@ global-context-less-secure = ["global-context"]
secp256k1-sys = { version = "0.11.0", default-features = false, path = "./secp256k1-sys" }

hashes = { package = "bitcoin_hashes", version = "0.14", default-features = false, optional = true }
rand = { version = "0.8", default-features = false, optional = true }
rand = { version = "0.9", default-features = false, optional = true }
serde = { version = "1.0.103", default-features = false, optional = true }

[dev-dependencies]
rand_core = "0.6"
rand_core = "0.9"
serde_cbor = "0.10.0"
serde_test = "1.0.19"
bincode = "1.3.3"
hex_lit = "0.1.1"

[target.wasm32-unknown-unknown.dev-dependencies]
wasm-bindgen-test = "0.3"
getrandom = { version = "0.2", features = ["js"] }
getrandom = { version = "0.3", features = ["wasm_js"] }

[lints.rust]
unexpected_cfgs = { level = "deny", check-cfg = ['cfg(bench)', 'cfg(secp256k1_fuzz)', 'cfg(rust_secp_no_symbol_renaming)'] }
Expand Down
2 changes: 1 addition & 1 deletion examples/generate_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use secp256k1::{PublicKey, Secp256k1, SecretKey};

fn main() {
let secp = Secp256k1::new();
let mut rng = rand::thread_rng();
let mut rng = rand::rng();
// First option:
let (seckey, pubkey) = secp.generate_keypair(&mut rng);

Expand Down
6 changes: 1 addition & 5 deletions no_std_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,10 @@ impl RngCore for FakeRng {
fn next_u64(&mut self) -> u64 {
57
}
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand::Error> {
fn fill_bytes(&mut self, dest: &mut [u8]) {
for i in dest {
*i = 57;
}
Ok(())
}
fn fill_bytes(&mut self, dest: &mut [u8]) {
self.try_fill_bytes(dest).unwrap();
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ pub mod global {
/// A global static context to avoid repeatedly creating contexts.
///
/// If `rand` and `std` feature is enabled, context will have been randomized using
/// `thread_rng`.
/// `rng`.
///
/// ```
/// # #[cfg(all(feature = "global-context", feature = "rand", feature = "std"))] {
/// use secp256k1::{PublicKey, SECP256K1};
/// let _ = SECP256K1.generate_keypair(&mut rand::thread_rng());
/// let _ = SECP256K1.generate_keypair(&mut rand::rng());
/// # }
/// ```
pub static SECP256K1: &GlobalContext = &GlobalContext { __private: () };
Expand Down Expand Up @@ -174,15 +174,15 @@ mod alloc_only {
/// Lets you create a context in a generic manner (sign/verify/all).
///
/// If `rand` and `std` feature is enabled, context will have been randomized using
/// `thread_rng`.
/// `rng`.
/// If `rand` or `std` feature is not enabled please consider randomizing the context as
/// follows:
/// ```
/// # #[cfg(all(feature = "rand", feature = "std"))] {
/// # use secp256k1::Secp256k1;
/// # use secp256k1::rand::{thread_rng, RngCore};
/// # use secp256k1::rand::{rng, RngCore};
/// let mut ctx = Secp256k1::new();
/// # let mut rng = thread_rng();
/// # let mut rng = rng();
/// # let mut seed = [0u8; 32];
/// # rng.fill_bytes(&mut seed);
/// // let seed = <32 bytes of random data>
Expand Down Expand Up @@ -216,7 +216,7 @@ mod alloc_only {
not(feature = "global-context-less-secure")
))]
{
ctx.randomize(&mut rand::thread_rng());
ctx.randomize(&mut rand::rng());
}

#[allow(clippy::let_and_return)] // as for unusted_mut
Expand All @@ -228,7 +228,7 @@ mod alloc_only {
/// Creates a new Secp256k1 context with all capabilities.
///
/// If `rand` and `std` feature is enabled, context will have been randomized using
/// `thread_rng`.
/// `rng`.
/// If `rand` or `std` feature is not enabled please consider randomizing the context (see
/// docs for `Secp256k1::gen_new()`).
pub fn new() -> Secp256k1<All> { Secp256k1::gen_new() }
Expand All @@ -238,7 +238,7 @@ mod alloc_only {
/// Creates a new Secp256k1 context that can only be used for signing.
///
/// If `rand` and `std` feature is enabled, context will have been randomized using
/// `thread_rng`.
/// `rng`.
/// If `rand` or `std` feature is not enabled please consider randomizing the context (see
/// docs for `Secp256k1::gen_new()`).
pub fn signing_only() -> Secp256k1<SignOnly> { Secp256k1::gen_new() }
Expand All @@ -248,7 +248,7 @@ mod alloc_only {
/// Creates a new Secp256k1 context that can only be used for verification.
///
/// If `rand` and `std` feature is enabled, context will have been randomized using
/// `thread_rng`.
/// `rng`.
/// If `rand` or `std` feature is not enabled please consider randomizing the context (see
/// docs for `Secp256k1::gen_new()`).
pub fn verification_only() -> Secp256k1<VerifyOnly> { Secp256k1::gen_new() }
Expand Down
Loading
Loading