Use feature std with rand-std

Recently we fixed a bunch of feature gates to use `rand-std` instead
of `rand` but in doing so did not notice that the same feature gates
were using `alloc` which is meaningless if `std` is enabled.

Feature gate on `std` if we are using `rand-std`.
This commit is contained in:
Tobin Harding 2022-02-11 07:44:16 +00:00
parent df7520e951
commit 806eaca5f1
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
6 changed files with 28 additions and 28 deletions

View File

@ -179,7 +179,7 @@ mod alloc_only {
/// If `rand-std` feature is enabled, context will have been randomized using `thread_rng`.
/// If `rand-std` feature is not enabled please consider randomizing the context as follows:
/// ```
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
/// # use secp256k1::Secp256k1;
/// # use secp256k1::rand::{thread_rng, RngCore};
/// let mut ctx = Secp256k1::new();

View File

@ -27,7 +27,7 @@ use secp256k1_sys::types::{c_int, c_uchar, c_void};
/// # Examples
///
/// ```
/// # #[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))] {
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
/// # use secp256k1::Secp256k1;
/// # use secp256k1::ecdh::SharedSecret;
/// # use secp256k1::rand::thread_rng;
@ -208,7 +208,7 @@ mod tests {
}
#[test]
#[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))]
#[cfg(all(feature="std", feature = "rand-std"))]
fn ecdh_with_hash() {
let s = Secp256k1::signing_only();
let (sk1, pk1) = s.generate_keypair(&mut thread_rng());
@ -222,7 +222,7 @@ mod tests {
}
#[test]
#[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))]
#[cfg(all(feature="std", feature = "rand-std"))]
fn ecdh_with_hash_callback() {
let s = Secp256k1::signing_only();
let (sk1, pk1) = s.generate_keypair(&mut thread_rng());

View File

@ -442,7 +442,7 @@ impl<C: Verification> Secp256k1<C> {
/// verify-capable context.
///
/// ```rust
/// # #[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))] {
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
/// # use secp256k1::rand::rngs::OsRng;
/// # use secp256k1::{Secp256k1, Message, Error};
/// #
@ -471,7 +471,7 @@ impl<C: Verification> Secp256k1<C> {
/// verify-capable context.
///
/// ```rust
/// # #[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))] {
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
/// # use secp256k1::rand::rngs::OsRng;
/// # use secp256k1::{Secp256k1, Message, Error};
/// #

View File

@ -219,7 +219,7 @@ mod tests {
use wasm_bindgen_test::wasm_bindgen_test as test;
#[test]
#[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))]
#[cfg(all(feature="std", feature = "rand-std"))]
fn capabilities() {
let sign = Secp256k1::signing_only();
let vrfy = Secp256k1::verification_only();
@ -253,7 +253,7 @@ mod tests {
#[test]
#[cfg(not(fuzzing))] // fixed sig vectors can't work with fuzz-sigs
#[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))]
#[cfg(all(feature="std", feature = "rand-std"))]
fn sign() {
let mut s = Secp256k1::new();
s.randomize(&mut thread_rng());
@ -277,7 +277,7 @@ mod tests {
}
#[test]
#[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))]
#[cfg(all(feature="std", feature = "rand-std"))]
fn sign_and_verify_fail() {
let mut s = Secp256k1::new();
s.randomize(&mut thread_rng());
@ -301,7 +301,7 @@ mod tests {
}
#[test]
#[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))]
#[cfg(all(feature="std", feature = "rand-std"))]
fn sign_with_recovery() {
let mut s = Secp256k1::new();
s.randomize(&mut thread_rng());
@ -318,7 +318,7 @@ mod tests {
}
#[test]
#[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))]
#[cfg(all(feature="std", feature = "rand-std"))]
fn bad_recovery() {
let mut s = Secp256k1::new();
s.randomize(&mut thread_rng());

View File

@ -40,7 +40,7 @@ use schnorr;
/// Basic usage:
///
/// ```
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
/// use secp256k1::{rand, Secp256k1, SecretKey};
///
/// let secp = Secp256k1::new();
@ -134,7 +134,7 @@ impl SecretKey {
/// # Examples
///
/// ```
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
/// use secp256k1::{rand, SecretKey};
/// let secret_key = SecretKey::new(&mut rand::thread_rng());
/// # }
@ -190,7 +190,7 @@ impl SecretKey {
/// # Examples
///
/// ```
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
/// use secp256k1::{rand, Secp256k1, SecretKey, KeyPair};
///
/// let secp = Secp256k1::new();
@ -342,7 +342,7 @@ impl PublicKey {
/// # Examples
///
/// ```
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
/// use secp256k1::{rand, Secp256k1, SecretKey, PublicKey};
///
/// let secp = Secp256k1::new();
@ -396,7 +396,7 @@ impl PublicKey {
/// # Examples
///
/// ```
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
/// use secp256k1::{rand, Secp256k1, PublicKey, KeyPair};
///
/// let secp = Secp256k1::new();
@ -553,7 +553,7 @@ impl PublicKey {
/// # Examples
///
/// ```
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
/// use secp256k1::{rand, Secp256k1, PublicKey};
///
/// let secp = Secp256k1::new();
@ -669,7 +669,7 @@ impl Ord for PublicKey {
/// Basic usage:
///
/// ```
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
/// use secp256k1::{rand, KeyPair, Secp256k1};
///
/// let secp = Secp256k1::new();
@ -775,7 +775,7 @@ impl KeyPair {
/// # Examples
///
/// ```
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
/// use secp256k1::{rand, Secp256k1, SecretKey, KeyPair};
///
/// let secp = Secp256k1::new();
@ -829,7 +829,7 @@ impl KeyPair {
/// # Examples
///
/// ```
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
/// use secp256k1::{Secp256k1, KeyPair};
/// use secp256k1::rand::{RngCore, thread_rng};
///
@ -961,7 +961,7 @@ impl<'de> ::serde::Deserialize<'de> for KeyPair {
/// Basic usage:
///
/// ```
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
/// use secp256k1::{rand, Secp256k1, KeyPair, XOnlyPublicKey};
///
/// let secp = Secp256k1::new();
@ -1089,7 +1089,7 @@ impl XOnlyPublicKey {
/// # Examples
///
/// ```
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
/// use secp256k1::{Secp256k1, KeyPair};
/// use secp256k1::rand::{RngCore, thread_rng};
///
@ -1154,7 +1154,7 @@ impl XOnlyPublicKey {
/// # Examples
///
/// ```
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
/// use secp256k1::{Secp256k1, KeyPair};
/// use secp256k1::rand::{thread_rng, RngCore};
///

View File

@ -307,7 +307,7 @@ mod tests {
}
#[test]
#[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))]
#[cfg(all(feature = "std", feature = "rand-std"))]
fn test_schnorrsig_sign_with_aux_rand_verify() {
test_schnorrsig_sign_helper(|secp, msg, seckey, rng| {
let mut aux_rand = [0u8; 32];
@ -317,7 +317,7 @@ mod tests {
}
#[test]
#[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))]
#[cfg(all(feature = "std", feature = "rand-std"))]
fn test_schnorrsig_sign_with_rng_verify() {
test_schnorrsig_sign_helper(|secp, msg, seckey, mut rng| {
secp.sign_schnorr_with_rng(msg, seckey, &mut rng)
@ -325,7 +325,7 @@ mod tests {
}
#[test]
#[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))]
#[cfg(all(feature = "std", feature = "rand-std"))]
fn test_schnorrsig_sign_verify() {
test_schnorrsig_sign_helper(|secp, msg, seckey, _| {
secp.sign_schnorr(msg, seckey)
@ -333,14 +333,14 @@ mod tests {
}
#[test]
#[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))]
#[cfg(all(feature = "std", feature = "rand-std"))]
fn test_schnorrsig_sign_no_aux_rand_verify() {
test_schnorrsig_sign_helper(|secp, msg, seckey, _| {
secp.sign_schnorr_no_aux_rand(msg, seckey)
})
}
#[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))]
#[cfg(all(feature = "std", feature = "rand-std"))]
fn test_schnorrsig_sign_helper(
sign: fn(&Secp256k1<All>, &Message, &KeyPair, &mut ThreadRng) -> Signature,
) {