4c9bab9f6e Remove explicit mention of feature requirements (Tobin Harding)
806eaca5f1 Use feature std with rand-std (Tobin Harding)

Pull request description:

  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.

  - Patch 1: Feature gate on `std` if we are using `rand-std`.
  - Patch 2: Remove redundant docs related to feature gating.

ACKs for top commit:
  apoelstra:
    ACK 4c9bab9f6e

Tree-SHA512: 316303e34dfcf62ffce2aa01742131b9ca6143895110b7e49c9aab376cfeb5cc0573d040504710a7e1bfdd0ab85b2ffa13c79c5d1176b32eecc3713482f6114e
This commit is contained in:
Andrew Poelstra 2022-02-14 20:49:22 +00:00
commit ef59aea888
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
6 changed files with 31 additions and 35 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 enabled, context will have been randomized using `thread_rng`.
/// If `rand-std` feature is not enabled please consider randomizing the context as follows: /// 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::Secp256k1;
/// # use secp256k1::rand::{thread_rng, RngCore}; /// # use secp256k1::rand::{thread_rng, RngCore};
/// let mut ctx = Secp256k1::new(); /// let mut ctx = Secp256k1::new();

View File

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

View File

@ -442,7 +442,7 @@ impl<C: Verification> Secp256k1<C> {
/// verify-capable context. /// verify-capable context.
/// ///
/// ```rust /// ```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::rand::rngs::OsRng;
/// # use secp256k1::{Secp256k1, Message, Error}; /// # use secp256k1::{Secp256k1, Message, Error};
/// # /// #
@ -471,7 +471,7 @@ impl<C: Verification> Secp256k1<C> {
/// verify-capable context. /// verify-capable context.
/// ///
/// ```rust /// ```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::rand::rngs::OsRng;
/// # use secp256k1::{Secp256k1, Message, Error}; /// # use secp256k1::{Secp256k1, Message, Error};
/// # /// #

View File

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

View File

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

View File

@ -128,7 +128,6 @@ impl<C: Signing> Secp256k1<C> {
/// Create a schnorr signature internally using the ThreadRng random number /// Create a schnorr signature internally using the ThreadRng random number
/// generator to generate the auxiliary random data. /// generator to generate the auxiliary random data.
/// Requires compilation with "rand-std" feature.
#[cfg(any(test, feature = "rand-std"))] #[cfg(any(test, feature = "rand-std"))]
#[cfg_attr(docsrs, doc(cfg(feature = "rand-std")))] #[cfg_attr(docsrs, doc(cfg(feature = "rand-std")))]
#[deprecated(since = "0.21.0", note = "Use sign_schnorr instead.")] #[deprecated(since = "0.21.0", note = "Use sign_schnorr instead.")]
@ -138,7 +137,6 @@ impl<C: Signing> Secp256k1<C> {
/// Create a schnorr signature internally using the ThreadRng random number /// Create a schnorr signature internally using the ThreadRng random number
/// generator to generate the auxiliary random data. /// generator to generate the auxiliary random data.
/// Requires compilation with "rand-std" feature.
#[cfg(any(test, feature = "rand-std"))] #[cfg(any(test, feature = "rand-std"))]
#[cfg_attr(docsrs, doc(cfg(feature = "rand-std")))] #[cfg_attr(docsrs, doc(cfg(feature = "rand-std")))]
pub fn sign_schnorr(&self, msg: &Message, keypair: &KeyPair) -> Signature { pub fn sign_schnorr(&self, msg: &Message, keypair: &KeyPair) -> Signature {
@ -191,8 +189,7 @@ impl<C: Signing> Secp256k1<C> {
} }
/// Create a schnorr signature using the given random number generator to /// Create a schnorr signature using the given random number generator to
/// generate the auxiliary random data. Requires compilation with "rand" /// generate the auxiliary random data.
/// feature.
#[cfg(any(test, feature = "rand"))] #[cfg(any(test, feature = "rand"))]
#[cfg_attr(docsrs, doc(cfg(feature = "rand")))] #[cfg_attr(docsrs, doc(cfg(feature = "rand")))]
#[deprecated(since = "0.21.0", note = "Use sign_schnorr_with_rng instead.")] #[deprecated(since = "0.21.0", note = "Use sign_schnorr_with_rng instead.")]
@ -206,8 +203,7 @@ impl<C: Signing> Secp256k1<C> {
} }
/// Create a schnorr signature using the given random number generator to /// Create a schnorr signature using the given random number generator to
/// generate the auxiliary random data. Requires compilation with "rand" /// generate the auxiliary random data.
/// feature.
#[cfg(any(test, feature = "rand"))] #[cfg(any(test, feature = "rand"))]
#[cfg_attr(docsrs, doc(cfg(feature = "rand")))] #[cfg_attr(docsrs, doc(cfg(feature = "rand")))]
pub fn sign_schnorr_with_rng<R: Rng + CryptoRng>( pub fn sign_schnorr_with_rng<R: Rng + CryptoRng>(
@ -262,7 +258,7 @@ impl <C: Signing> Secp256k1<C> {
/// Generates a random Schnorr `KeyPair` and its associated Schnorr `XOnlyPublicKey`. /// Generates a random Schnorr `KeyPair` and its associated Schnorr `XOnlyPublicKey`.
/// ///
/// Convenience function for [KeyPair::new] and [KeyPair::public_key]. /// Convenience function for [KeyPair::new] and [KeyPair::public_key].
/// Requires a signing-capable context and requires compilation with the "rand" feature. /// Requires a signing-capable context.
#[inline] #[inline]
#[cfg(any(test, feature = "rand"))] #[cfg(any(test, feature = "rand"))]
#[cfg_attr(docsrs, doc(cfg(feature = "rand")))] #[cfg_attr(docsrs, doc(cfg(feature = "rand")))]
@ -307,7 +303,7 @@ mod tests {
} }
#[test] #[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() { fn test_schnorrsig_sign_with_aux_rand_verify() {
test_schnorrsig_sign_helper(|secp, msg, seckey, rng| { test_schnorrsig_sign_helper(|secp, msg, seckey, rng| {
let mut aux_rand = [0u8; 32]; let mut aux_rand = [0u8; 32];
@ -317,7 +313,7 @@ mod tests {
} }
#[test] #[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() { fn test_schnorrsig_sign_with_rng_verify() {
test_schnorrsig_sign_helper(|secp, msg, seckey, mut rng| { test_schnorrsig_sign_helper(|secp, msg, seckey, mut rng| {
secp.sign_schnorr_with_rng(msg, seckey, &mut rng) secp.sign_schnorr_with_rng(msg, seckey, &mut rng)
@ -325,7 +321,7 @@ mod tests {
} }
#[test] #[test]
#[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] #[cfg(all(feature = "std", feature = "rand-std"))]
fn test_schnorrsig_sign_verify() { fn test_schnorrsig_sign_verify() {
test_schnorrsig_sign_helper(|secp, msg, seckey, _| { test_schnorrsig_sign_helper(|secp, msg, seckey, _| {
secp.sign_schnorr(msg, seckey) secp.sign_schnorr(msg, seckey)
@ -333,14 +329,14 @@ mod tests {
} }
#[test] #[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() { fn test_schnorrsig_sign_no_aux_rand_verify() {
test_schnorrsig_sign_helper(|secp, msg, seckey, _| { test_schnorrsig_sign_helper(|secp, msg, seckey, _| {
secp.sign_schnorr_no_aux_rand(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( fn test_schnorrsig_sign_helper(
sign: fn(&Secp256k1<All>, &Message, &KeyPair, &mut ThreadRng) -> Signature, sign: fn(&Secp256k1<All>, &Message, &KeyPair, &mut ThreadRng) -> Signature,
) { ) {