Skip to content

Commit dbf92db

Browse files
committed
Use rand-std instead of rand feature
Much of our usage of the `rand` crate uses `thread_rng`, this is only available if `std` feature is enabled on `rand` dependency. We have a feature that enables `rand` with `std`, its called `rand-std`. So, technically anytime we use `thread_rng` we should be conditionally compiling on `rand-std` not `rand`.
1 parent 3d33f24 commit dbf92db

File tree

5 files changed

+31
-31
lines changed

5 files changed

+31
-31
lines changed

src/ecdh.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ mod tests {
179179
use rand::thread_rng;
180180

181181
#[cfg(all(feature = "rand-std", any(features = "alloc", feature = "std")))]
182-
use super::super::Secp256k1;
182+
use Secp256k1;
183183

184184
#[test]
185185
#[cfg(all(feature = "rand-std", any(features = "alloc", feature = "std")))]

src/ecdsa/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ impl<C: Verification> Secp256k1<C> {
431431
/// verify-capable context.
432432
///
433433
/// ```rust
434-
/// # #[cfg(all(feature="rand", any(feature = "alloc", feature = "std")))] {
434+
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
435435
/// # use secp256k1::rand::rngs::OsRng;
436436
/// # use secp256k1::{Secp256k1, Message, Error};
437437
/// #
@@ -460,7 +460,7 @@ impl<C: Verification> Secp256k1<C> {
460460
/// verify-capable context.
461461
///
462462
/// ```rust
463-
/// # #[cfg(all(feature="rand", any(feature = "alloc", feature = "std")))] {
463+
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
464464
/// # use secp256k1::rand::rngs::OsRng;
465465
/// # use secp256k1::{Secp256k1, Message, Error};
466466
/// #

src/key.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use ffi::{self, CPtr};
3535
/// Basic usage:
3636
///
3737
/// ```
38-
/// # #[cfg(all(feature="rand", any(feature = "alloc", feature = "std")))] {
38+
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
3939
/// use secp256k1::{rand, Secp256k1, SecretKey};
4040
///
4141
/// let secp = Secp256k1::new_randomize();
@@ -129,7 +129,7 @@ impl SecretKey {
129129
/// # Examples
130130
///
131131
/// ```
132-
/// # #[cfg(feature="rand")] {
132+
/// # #[cfg(feature = "rand-std")] {
133133
/// use secp256k1::{rand, SecretKey};
134134
/// let secret_key = SecretKey::new(&mut rand::thread_rng());
135135
/// # }
@@ -185,7 +185,7 @@ impl SecretKey {
185185
/// # Examples
186186
///
187187
/// ```
188-
/// # #[cfg(all(feature="rand", any(feature = "alloc", feature = "std")))] {
188+
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
189189
/// use secp256k1::{rand, Secp256k1, SecretKey, KeyPair};
190190
///
191191
/// let secp = Secp256k1::new_randomize();
@@ -329,7 +329,7 @@ impl PublicKey {
329329
/// # Examples
330330
///
331331
/// ```
332-
/// # #[cfg(all(feature="rand", any(feature = "alloc", feature = "std")))] {
332+
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
333333
/// use secp256k1::{rand, Secp256k1, SecretKey, PublicKey};
334334
///
335335
/// let secp = Secp256k1::new_randomize();
@@ -377,7 +377,7 @@ impl PublicKey {
377377
/// # Examples
378378
///
379379
/// ```
380-
/// # #[cfg(all(feature="rand", any(feature = "alloc", feature = "std")))] {
380+
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
381381
/// use secp256k1::{rand, Secp256k1, PublicKey, KeyPair};
382382
///
383383
/// let secp = Secp256k1::new_randomize();
@@ -508,7 +508,7 @@ impl PublicKey {
508508
/// # Examples
509509
///
510510
/// ```
511-
/// # #[cfg(all(feature="rand", any(feature = "alloc", feature = "std")))] {
511+
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
512512
/// use secp256k1::{rand, Secp256k1};
513513
///
514514
/// let secp = Secp256k1::new_randomize();
@@ -534,7 +534,7 @@ impl PublicKey {
534534
/// # Examples
535535
///
536536
/// ```
537-
/// # #[cfg(all(feature="rand", any(feature = "alloc", feature = "std")))] {
537+
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
538538
/// use secp256k1::{rand, Secp256k1, PublicKey};
539539
///
540540
/// let secp = Secp256k1::new_randomize();
@@ -650,7 +650,7 @@ impl Ord for PublicKey {
650650
/// Basic usage:
651651
///
652652
/// ```
653-
/// # #[cfg(all(feature="rand", any(feature = "alloc", feature = "std")))] {
653+
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
654654
/// use secp256k1::{rand, KeyPair, Secp256k1};
655655
///
656656
/// let secp = Secp256k1::new_randomize();
@@ -744,7 +744,7 @@ impl KeyPair {
744744
/// # Examples
745745
///
746746
/// ```
747-
/// # #[cfg(all(feature="rand", any(feature = "alloc", feature = "std")))] {
747+
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
748748
/// use secp256k1::{rand, Secp256k1, SecretKey, KeyPair};
749749
///
750750
/// let secp = Secp256k1::new_randomize();
@@ -790,7 +790,7 @@ impl KeyPair {
790790
/// # Examples
791791
///
792792
/// ```
793-
/// # #[cfg(all(feature="rand", any(feature = "alloc", feature = "std")))] {
793+
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
794794
/// use secp256k1::{Secp256k1, KeyPair};
795795
/// use secp256k1::rand::{RngCore, thread_rng};
796796
///
@@ -914,7 +914,7 @@ impl<'de> ::serde::Deserialize<'de> for KeyPair {
914914
/// Basic usage:
915915
///
916916
/// ```
917-
/// # #[cfg(all(feature="rand", any(feature = "alloc", feature = "std")))] {
917+
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
918918
/// use secp256k1::{rand, Secp256k1, KeyPair, XOnlyPublicKey};
919919
///
920920
/// let secp = Secp256k1::new_randomize();
@@ -1042,7 +1042,7 @@ impl XOnlyPublicKey {
10421042
/// # Examples
10431043
///
10441044
/// ```
1045-
/// # #[cfg(all(feature="rand", any(feature = "alloc", feature = "std")))] {
1045+
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
10461046
/// use secp256k1::{Secp256k1, KeyPair};
10471047
/// use secp256k1::rand::{RngCore, thread_rng};
10481048
///
@@ -1107,7 +1107,7 @@ impl XOnlyPublicKey {
11071107
/// # Examples
11081108
///
11091109
/// ```
1110-
/// # #[cfg(all(feature="rand", any(feature = "alloc", feature = "std")))] {
1110+
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
11111111
/// use secp256k1::{Secp256k1, KeyPair};
11121112
/// use secp256k1::rand::{thread_rng, RngCore};
11131113
///
@@ -1394,7 +1394,7 @@ mod test {
13941394
}
13951395

13961396
#[test]
1397-
#[cfg(all(feature = "rand", any(features = "alloc", feature = "std")))]
1397+
#[cfg(all(feature = "rand-std", any(features = "alloc", feature = "std")))]
13981398
fn keypair_slice_round_trip() {
13991399
let s = Secp256k1::new_randomize();
14001400

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
//! trigger any assertion failures in the upstream library.
4242
//!
4343
//! ```rust
44-
//! # #[cfg(all(feature="rand", feature="bitcoin_hashes"))] {
44+
//! # #[cfg(all(feature = "rand-std", feature = "bitcoin_hashes"))] {
4545
//! use secp256k1::rand::rngs::OsRng;
4646
//! use secp256k1::{Secp256k1, Message};
4747
//! use secp256k1::hashes::sha256;
@@ -654,7 +654,7 @@ mod tests {
654654
}
655655

656656
#[test]
657-
#[cfg(all(feature = "rand", any(features = "alloc", feature = "std")))]
657+
#[cfg(all(feature = "rand-std", any(features = "alloc", feature = "std")))]
658658
fn signature_serialize_roundtrip() {
659659
let s = Secp256k1::new_randomize();
660660

@@ -740,7 +740,7 @@ mod tests {
740740
}
741741

742742
#[test]
743-
#[cfg(all(feature = "rand", any(features = "alloc", feature = "std")))]
743+
#[cfg(all(feature = "rand-std", any(features = "alloc", feature = "std")))]
744744
fn sign_and_verify_ecdsa() {
745745
let s = Secp256k1::new_randomize();
746746

@@ -804,7 +804,7 @@ mod tests {
804804
}
805805

806806
#[test]
807-
#[cfg(all(feature = "rand", any(features = "alloc", feature = "std")))]
807+
#[cfg(all(feature = "rand-std", any(features = "alloc", feature = "std")))]
808808
fn sign_and_verify_fail() {
809809
let s = Secp256k1::new_randomize();
810810

src/schnorr.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,12 @@ mod tests {
275275
use std::iter;
276276
use std::str::FromStr;
277277

278-
#[cfg(feature = "rand")]
278+
#[cfg(feature = "rand-std")]
279279
use rand_core::impls;
280-
#[cfg(feature = "rand")]
280+
#[cfg(feature = "rand-std")]
281281
use rand::{rngs::ThreadRng, thread_rng, Error, ErrorKind, RngCore};
282282

283-
#[cfg(all(feature = "rand", any(feature = "alloc", feature = "std")))]
283+
#[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))]
284284
use super::super::All;
285285

286286
#[cfg(target_arch = "wasm32")]
@@ -296,7 +296,7 @@ mod tests {
296296
}
297297

298298
#[test]
299-
#[cfg(all(feature = "rand", any(feature = "alloc", feature = "std")))]
299+
#[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))]
300300
fn test_schnorrsig_sign_with_aux_rand_verify() {
301301
test_schnorrsig_sign_helper(|secp, msg, seckey, rng| {
302302
let mut aux_rand = [0u8; 32];
@@ -306,30 +306,30 @@ mod tests {
306306
}
307307

308308
#[test]
309-
#[cfg(all(feature = "rand", any(feature = "alloc", feature = "std")))]
309+
#[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))]
310310
fn test_schnorrsig_sign_with_rng_verify() {
311311
test_schnorrsig_sign_helper(|secp, msg, seckey, mut rng| {
312312
secp.sign_schnorr_with_rng(msg, seckey, &mut rng)
313313
})
314314
}
315315

316316
#[test]
317-
#[cfg(all(feature = "rand", any(feature = "alloc", feature = "std")))]
317+
#[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))]
318318
fn test_schnorrsig_sign_verifya() {
319319
test_schnorrsig_sign_helper(|secp, msg, seckey, _| {
320320
secp.sign_schnorr(msg, seckey)
321321
})
322322
}
323323

324324
#[test]
325-
#[cfg(all(feature = "rand", any(feature = "alloc", feature = "std")))]
325+
#[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))]
326326
fn test_schnorrsig_sign_no_aux_rand_verify() {
327327
test_schnorrsig_sign_helper(|secp, msg, seckey, _| {
328328
secp.sign_schnorr_no_aux_rand(msg, seckey)
329329
})
330330
}
331331

332-
#[cfg(all(feature = "rand", any(feature = "alloc", feature = "std")))]
332+
#[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))]
333333
fn test_schnorrsig_sign_helper(
334334
sign: fn(&Secp256k1<All>, &Message, &KeyPair, &mut ThreadRng) -> Signature,
335335
) {
@@ -403,7 +403,7 @@ mod tests {
403403
}
404404

405405
#[test]
406-
#[cfg(all(feature = "rand", any(feature = "alloc", feature = "std")))]
406+
#[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))]
407407
fn test_pubkey_serialize_roundtrip() {
408408
let secp = Secp256k1::new_randomize();
409409
let kp = KeyPair::new(&secp, &mut thread_rng());
@@ -512,7 +512,7 @@ mod tests {
512512
// In fuzzing mode secret->public key derivation is different, so
513513
// this test will never correctly derive the static pubkey.
514514
#[cfg(not(fuzzing))]
515-
#[cfg(all(feature = "rand", any(feature = "alloc", feature = "std")))]
515+
#[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))]
516516
fn test_pubkey_serialize() {
517517
struct DumbRng(u32);
518518
impl RngCore for DumbRng {

0 commit comments

Comments
 (0)