Skip to content

Commit ef59aea

Browse files
committed
Merge #404: Fix feature gating
4c9bab9 Remove explicit mention of feature requirements (Tobin Harding) 806eaca 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 4c9bab9 Tree-SHA512: 316303e34dfcf62ffce2aa01742131b9ca6143895110b7e49c9aab376cfeb5cc0573d040504710a7e1bfdd0ab85b2ffa13c79c5d1176b32eecc3713482f6114e
2 parents df7520e + 4c9bab9 commit ef59aea

File tree

6 files changed

+31
-35
lines changed

6 files changed

+31
-35
lines changed

src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ mod alloc_only {
179179
/// If `rand-std` feature is enabled, context will have been randomized using `thread_rng`.
180180
/// If `rand-std` feature is not enabled please consider randomizing the context as follows:
181181
/// ```
182-
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
182+
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
183183
/// # use secp256k1::Secp256k1;
184184
/// # use secp256k1::rand::{thread_rng, RngCore};
185185
/// let mut ctx = Secp256k1::new();

src/ecdh.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use secp256k1_sys::types::{c_int, c_uchar, c_void};
2727
/// # Examples
2828
///
2929
/// ```
30-
/// # #[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))] {
30+
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
3131
/// # use secp256k1::Secp256k1;
3232
/// # use secp256k1::ecdh::SharedSecret;
3333
/// # use secp256k1::rand::thread_rng;
@@ -208,7 +208,7 @@ mod tests {
208208
}
209209

210210
#[test]
211-
#[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))]
211+
#[cfg(all(feature="std", feature = "rand-std"))]
212212
fn ecdh_with_hash() {
213213
let s = Secp256k1::signing_only();
214214
let (sk1, pk1) = s.generate_keypair(&mut thread_rng());
@@ -222,7 +222,7 @@ mod tests {
222222
}
223223

224224
#[test]
225-
#[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))]
225+
#[cfg(all(feature="std", feature = "rand-std"))]
226226
fn ecdh_with_hash_callback() {
227227
let s = Secp256k1::signing_only();
228228
let (sk1, pk1) = s.generate_keypair(&mut thread_rng());

src/ecdsa/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ impl<C: Verification> Secp256k1<C> {
442442
/// verify-capable context.
443443
///
444444
/// ```rust
445-
/// # #[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))] {
445+
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
446446
/// # use secp256k1::rand::rngs::OsRng;
447447
/// # use secp256k1::{Secp256k1, Message, Error};
448448
/// #
@@ -471,7 +471,7 @@ impl<C: Verification> Secp256k1<C> {
471471
/// verify-capable context.
472472
///
473473
/// ```rust
474-
/// # #[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))] {
474+
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
475475
/// # use secp256k1::rand::rngs::OsRng;
476476
/// # use secp256k1::{Secp256k1, Message, Error};
477477
/// #

src/ecdsa/recovery.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ mod tests {
219219
use wasm_bindgen_test::wasm_bindgen_test as test;
220220

221221
#[test]
222-
#[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))]
222+
#[cfg(all(feature="std", feature = "rand-std"))]
223223
fn capabilities() {
224224
let sign = Secp256k1::signing_only();
225225
let vrfy = Secp256k1::verification_only();
@@ -253,7 +253,7 @@ mod tests {
253253

254254
#[test]
255255
#[cfg(not(fuzzing))] // fixed sig vectors can't work with fuzz-sigs
256-
#[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))]
256+
#[cfg(all(feature="std", feature = "rand-std"))]
257257
fn sign() {
258258
let mut s = Secp256k1::new();
259259
s.randomize(&mut thread_rng());
@@ -277,7 +277,7 @@ mod tests {
277277
}
278278

279279
#[test]
280-
#[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))]
280+
#[cfg(all(feature="std", feature = "rand-std"))]
281281
fn sign_and_verify_fail() {
282282
let mut s = Secp256k1::new();
283283
s.randomize(&mut thread_rng());
@@ -301,7 +301,7 @@ mod tests {
301301
}
302302

303303
#[test]
304-
#[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))]
304+
#[cfg(all(feature="std", feature = "rand-std"))]
305305
fn sign_with_recovery() {
306306
let mut s = Secp256k1::new();
307307
s.randomize(&mut thread_rng());
@@ -318,7 +318,7 @@ mod tests {
318318
}
319319

320320
#[test]
321-
#[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))]
321+
#[cfg(all(feature="std", feature = "rand-std"))]
322322
fn bad_recovery() {
323323
let mut s = Secp256k1::new();
324324
s.randomize(&mut thread_rng());

src/key.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use schnorr;
4040
/// Basic usage:
4141
///
4242
/// ```
43-
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
43+
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
4444
/// use secp256k1::{rand, Secp256k1, SecretKey};
4545
///
4646
/// let secp = Secp256k1::new();
@@ -134,7 +134,7 @@ impl SecretKey {
134134
/// # Examples
135135
///
136136
/// ```
137-
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
137+
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
138138
/// use secp256k1::{rand, SecretKey};
139139
/// let secret_key = SecretKey::new(&mut rand::thread_rng());
140140
/// # }
@@ -190,7 +190,7 @@ impl SecretKey {
190190
/// # Examples
191191
///
192192
/// ```
193-
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
193+
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
194194
/// use secp256k1::{rand, Secp256k1, SecretKey, KeyPair};
195195
///
196196
/// let secp = Secp256k1::new();
@@ -342,7 +342,7 @@ impl PublicKey {
342342
/// # Examples
343343
///
344344
/// ```
345-
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
345+
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
346346
/// use secp256k1::{rand, Secp256k1, SecretKey, PublicKey};
347347
///
348348
/// let secp = Secp256k1::new();
@@ -396,7 +396,7 @@ impl PublicKey {
396396
/// # Examples
397397
///
398398
/// ```
399-
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
399+
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
400400
/// use secp256k1::{rand, Secp256k1, PublicKey, KeyPair};
401401
///
402402
/// let secp = Secp256k1::new();
@@ -553,7 +553,7 @@ impl PublicKey {
553553
/// # Examples
554554
///
555555
/// ```
556-
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
556+
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
557557
/// use secp256k1::{rand, Secp256k1, PublicKey};
558558
///
559559
/// let secp = Secp256k1::new();
@@ -669,7 +669,7 @@ impl Ord for PublicKey {
669669
/// Basic usage:
670670
///
671671
/// ```
672-
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
672+
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
673673
/// use secp256k1::{rand, KeyPair, Secp256k1};
674674
///
675675
/// let secp = Secp256k1::new();
@@ -775,7 +775,7 @@ impl KeyPair {
775775
/// # Examples
776776
///
777777
/// ```
778-
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
778+
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
779779
/// use secp256k1::{rand, Secp256k1, SecretKey, KeyPair};
780780
///
781781
/// let secp = Secp256k1::new();
@@ -829,7 +829,7 @@ impl KeyPair {
829829
/// # Examples
830830
///
831831
/// ```
832-
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
832+
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
833833
/// use secp256k1::{Secp256k1, KeyPair};
834834
/// use secp256k1::rand::{RngCore, thread_rng};
835835
///
@@ -961,7 +961,7 @@ impl<'de> ::serde::Deserialize<'de> for KeyPair {
961961
/// Basic usage:
962962
///
963963
/// ```
964-
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
964+
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
965965
/// use secp256k1::{rand, Secp256k1, KeyPair, XOnlyPublicKey};
966966
///
967967
/// let secp = Secp256k1::new();
@@ -1089,7 +1089,7 @@ impl XOnlyPublicKey {
10891089
/// # Examples
10901090
///
10911091
/// ```
1092-
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
1092+
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
10931093
/// use secp256k1::{Secp256k1, KeyPair};
10941094
/// use secp256k1::rand::{RngCore, thread_rng};
10951095
///
@@ -1154,7 +1154,7 @@ impl XOnlyPublicKey {
11541154
/// # Examples
11551155
///
11561156
/// ```
1157-
/// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
1157+
/// # #[cfg(all(feature = "std", feature = "rand-std"))] {
11581158
/// use secp256k1::{Secp256k1, KeyPair};
11591159
/// use secp256k1::rand::{thread_rng, RngCore};
11601160
///

src/schnorr.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ impl<C: Signing> Secp256k1<C> {
128128

129129
/// Create a schnorr signature internally using the ThreadRng random number
130130
/// generator to generate the auxiliary random data.
131-
/// Requires compilation with "rand-std" feature.
132131
#[cfg(any(test, feature = "rand-std"))]
133132
#[cfg_attr(docsrs, doc(cfg(feature = "rand-std")))]
134133
#[deprecated(since = "0.21.0", note = "Use sign_schnorr instead.")]
@@ -138,7 +137,6 @@ impl<C: Signing> Secp256k1<C> {
138137

139138
/// Create a schnorr signature internally using the ThreadRng random number
140139
/// generator to generate the auxiliary random data.
141-
/// Requires compilation with "rand-std" feature.
142140
#[cfg(any(test, feature = "rand-std"))]
143141
#[cfg_attr(docsrs, doc(cfg(feature = "rand-std")))]
144142
pub fn sign_schnorr(&self, msg: &Message, keypair: &KeyPair) -> Signature {
@@ -191,8 +189,7 @@ impl<C: Signing> Secp256k1<C> {
191189
}
192190

193191
/// Create a schnorr signature using the given random number generator to
194-
/// generate the auxiliary random data. Requires compilation with "rand"
195-
/// feature.
192+
/// generate the auxiliary random data.
196193
#[cfg(any(test, feature = "rand"))]
197194
#[cfg_attr(docsrs, doc(cfg(feature = "rand")))]
198195
#[deprecated(since = "0.21.0", note = "Use sign_schnorr_with_rng instead.")]
@@ -206,8 +203,7 @@ impl<C: Signing> Secp256k1<C> {
206203
}
207204

208205
/// Create a schnorr signature using the given random number generator to
209-
/// generate the auxiliary random data. Requires compilation with "rand"
210-
/// feature.
206+
/// generate the auxiliary random data.
211207
#[cfg(any(test, feature = "rand"))]
212208
#[cfg_attr(docsrs, doc(cfg(feature = "rand")))]
213209
pub fn sign_schnorr_with_rng<R: Rng + CryptoRng>(
@@ -262,7 +258,7 @@ impl <C: Signing> Secp256k1<C> {
262258
/// Generates a random Schnorr `KeyPair` and its associated Schnorr `XOnlyPublicKey`.
263259
///
264260
/// Convenience function for [KeyPair::new] and [KeyPair::public_key].
265-
/// Requires a signing-capable context and requires compilation with the "rand" feature.
261+
/// Requires a signing-capable context.
266262
#[inline]
267263
#[cfg(any(test, feature = "rand"))]
268264
#[cfg_attr(docsrs, doc(cfg(feature = "rand")))]
@@ -307,7 +303,7 @@ mod tests {
307303
}
308304

309305
#[test]
310-
#[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))]
306+
#[cfg(all(feature = "std", feature = "rand-std"))]
311307
fn test_schnorrsig_sign_with_aux_rand_verify() {
312308
test_schnorrsig_sign_helper(|secp, msg, seckey, rng| {
313309
let mut aux_rand = [0u8; 32];
@@ -317,30 +313,30 @@ mod tests {
317313
}
318314

319315
#[test]
320-
#[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))]
316+
#[cfg(all(feature = "std", feature = "rand-std"))]
321317
fn test_schnorrsig_sign_with_rng_verify() {
322318
test_schnorrsig_sign_helper(|secp, msg, seckey, mut rng| {
323319
secp.sign_schnorr_with_rng(msg, seckey, &mut rng)
324320
})
325321
}
326322

327323
#[test]
328-
#[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))]
324+
#[cfg(all(feature = "std", feature = "rand-std"))]
329325
fn test_schnorrsig_sign_verify() {
330326
test_schnorrsig_sign_helper(|secp, msg, seckey, _| {
331327
secp.sign_schnorr(msg, seckey)
332328
})
333329
}
334330

335331
#[test]
336-
#[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))]
332+
#[cfg(all(feature = "std", feature = "rand-std"))]
337333
fn test_schnorrsig_sign_no_aux_rand_verify() {
338334
test_schnorrsig_sign_helper(|secp, msg, seckey, _| {
339335
secp.sign_schnorr_no_aux_rand(msg, seckey)
340336
})
341337
}
342338

343-
#[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))]
339+
#[cfg(all(feature = "std", feature = "rand-std"))]
344340
fn test_schnorrsig_sign_helper(
345341
sign: fn(&Secp256k1<All>, &Message, &KeyPair, &mut ThreadRng) -> Signature,
346342
) {

0 commit comments

Comments
 (0)