From 55c2efc3203417be91c6d1db9258b430e4fe8b82 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Wed, 24 Jul 2024 14:44:48 +0200 Subject: [PATCH] Bump MSRV to 1.63 The version 1.63 satisfies our requirements for MSRV and provides significant benefits so this commit bumps it. This commit also starts using weak dependencies. --- .github/workflows/rust.yml | 4 ++-- Cargo.toml | 16 +++++-------- clippy.toml | 2 +- contrib/_test.sh | 16 ++++++------- githooks/pre-commit | 2 +- secp256k1-sys/Cargo.toml | 2 +- src/context.rs | 47 +++++++++++++++++++++++-------------- src/ecdh.rs | 10 ++++---- src/ecdsa/mod.rs | 2 +- src/ecdsa/recovery.rs | 16 ++++++------- src/key.rs | 48 +++++++++++++++++++------------------- src/lib.rs | 29 +++++++++++------------ src/scalar.rs | 2 +- src/schnorr.rs | 16 ++++++------- 14 files changed, 108 insertions(+), 104 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index bbe07b19d..0ef8230dd 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -57,7 +57,7 @@ jobs: run: ./contrib/test.sh MSRV: - name: Test - 1.56.1 toolchain + name: Test - MSRV toolchain runs-on: ubuntu-latest strategy: fail-fast: false @@ -65,7 +65,7 @@ jobs: - name: Checkout Crate uses: actions/checkout@v3 - name: Checkout Toolchain - uses: dtolnay/rust-toolchain@1.56.1 + uses: dtolnay/rust-toolchain@1.63.0 - name: Running test script env: DO_FEATURE_MATRIX: true diff --git a/Cargo.toml b/Cargo.toml index 7a3403864..d36fba9b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ description = "Rust wrapper library for Pieter Wuille's `libsecp256k1`. Implemen keywords = [ "crypto", "ECDSA", "secp256k1", "libsecp256k1", "bitcoin" ] readme = "README.md" edition = "2021" -rust-version = "1.56.1" +rust-version = "1.63.0" [package.metadata.docs.rs] all-features = true @@ -19,18 +19,16 @@ rustdoc-args = ["--cfg", "docsrs"] [features] default = ["std"] -std = ["alloc", "secp256k1-sys/std"] +std = ["alloc", "secp256k1-sys/std", "rand?/std", "rand?/std_rng", "hashes?/std"] # allow use of Secp256k1::new and related API that requires an allocator alloc = ["secp256k1-sys/alloc"] -hashes-std = ["std", "hashes/std"] -rand-std = ["std", "rand", "rand/std", "rand/std_rng"] recovery = ["secp256k1-sys/recovery"] lowmemory = ["secp256k1-sys/lowmemory"] global-context = ["std"] # disable re-randomization of the global context, which provides some # defense-in-depth against sidechannel attacks. You should only use # this feature if you expect the `rand` crate's thread_rng to panic. -# (If you are sure the `rand-std` feature will not be enabled, e.g. +# (If you are sure the `rand` and `std` features will not be enabled, e.g. # if you are doing a no-std build, then this feature does nothing # and is not necessary.) global-context-less-secure = ["global-context"] @@ -39,8 +37,6 @@ global-context-less-secure = ["global-context"] secp256k1-sys = { version = "0.10.0", default-features = false, path = "./secp256k1-sys" } serde = { version = "1.0.103", default-features = false, optional = true } -# You likely only want to enable these if you explicitly do not want to use "std", otherwise enable -# the respective -std feature e.g., hashes-std hashes = { package = "bitcoin_hashes", version = ">= 0.12, <= 0.14", default-features = false, optional = true } rand = { version = "0.8", default-features = false, optional = true } @@ -59,15 +55,15 @@ unexpected_cfgs = { level = "deny", check-cfg = ['cfg(bench)', 'cfg(secp256k1_fu [[example]] name = "sign_verify_recovery" -required-features = ["recovery", "hashes-std"] +required-features = ["recovery", "hashes", "std"] [[example]] name = "sign_verify" -required-features = ["hashes-std"] +required-features = ["hashes", "std"] [[example]] name = "generate_keys" -required-features = ["rand-std"] +required-features = ["rand", "std"] [workspace] members = ["secp256k1-sys"] diff --git a/clippy.toml b/clippy.toml index 56ce04e44..b3c3a24c9 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1 +1 @@ -msrv = "1.56.1" +msrv = "1.63.0" diff --git a/contrib/_test.sh b/contrib/_test.sh index d415b5689..d44b9507e 100755 --- a/contrib/_test.sh +++ b/contrib/_test.sh @@ -3,7 +3,7 @@ set -ex REPO_DIR=$(git rev-parse --show-toplevel) -FEATURES="hashes global-context lowmemory rand recovery serde std alloc hashes-std rand-std" +FEATURES="hashes global-context lowmemory rand recovery serde std alloc" cargo --version rustc --version @@ -62,17 +62,17 @@ if [ "$DO_FEATURE_MATRIX" = true ]; then fi # Examples - cargo run --locked --example sign_verify --features=hashes-std - cargo run --locked --example sign_verify_recovery --features=recovery,hashes-std - cargo run --locked --example generate_keys --features=rand-std + cargo run --locked --example sign_verify --features=hashes,std + cargo run --locked --example sign_verify_recovery --features=recovery,hashes,std + cargo run --locked --example generate_keys --features=rand,std fi if [ "$DO_LINT" = true ] then cargo clippy --locked --all-features --all-targets -- -D warnings - cargo clippy --locked --example sign_verify --features=hashes-std -- -D warnings - cargo clippy --locked --example sign_verify_recovery --features=recovery,hashes-std -- -D warnings - cargo clippy --locked --example generate_keys --features=rand-std -- -D warnings + cargo clippy --locked --example sign_verify --features=hashes,std -- -D warnings + cargo clippy --locked --example sign_verify_recovery --features=recovery,hashes,std -- -D warnings + cargo clippy --locked --example generate_keys --features=rand,std -- -D warnings fi # Build the docs if told to (this only works with the nightly toolchain) @@ -120,7 +120,7 @@ fi # Bench if told to, only works with non-stable toolchain (nightly, beta). if [ "$DO_BENCH" = true ] then - RUSTFLAGS='--cfg=bench' cargo bench --features=recovery,rand-std + RUSTFLAGS='--cfg=bench' cargo bench --features=recovery,rand,std fi exit 0 diff --git a/githooks/pre-commit b/githooks/pre-commit index 1a964bbd4..8c45989f4 100755 --- a/githooks/pre-commit +++ b/githooks/pre-commit @@ -47,7 +47,7 @@ fi git diff-index --check --cached $against -- || exit 1 # Check that code lints cleanly. -cargo clippy --features=rand-std,recovery,lowmemory,global-context --all-targets -- -D warnings || exit 1 +cargo clippy --features=rand,std,recovery,lowmemory,global-context --all-targets -- -D warnings || exit 1 # Check that there are no formatting issues. cargo +nightly fmt --check || exit 1 diff --git a/secp256k1-sys/Cargo.toml b/secp256k1-sys/Cargo.toml index 1ca432045..850467496 100644 --- a/secp256k1-sys/Cargo.toml +++ b/secp256k1-sys/Cargo.toml @@ -14,7 +14,7 @@ readme = "README.md" build = "build.rs" links = "rustsecp256k1_v0_10_0" edition = "2021" -rust-version = "1.56.1" +rust-version = "1.63.0" [package.metadata.docs.rs] all-features = true diff --git a/src/context.rs b/src/context.rs index 7383e6274..6ad7addcf 100644 --- a/src/context.rs +++ b/src/context.rs @@ -27,10 +27,11 @@ pub mod global { /// A global static context to avoid repeatedly creating contexts. /// - /// If `rand-std` feature is enabled, context will have been randomized using `thread_rng`. + /// If `rand` and `std` feature is enabled, context will have been randomized using + /// `thread_rng`. /// /// ``` - /// # #[cfg(all(feature = "global-context", feature = "rand-std"))] { + /// # #[cfg(all(feature = "global-context", feature = "rand", feature = "std"))] { /// use secp256k1::{PublicKey, SECP256K1}; /// let _ = SECP256K1.generate_keypair(&mut rand::thread_rng()); /// # } @@ -40,7 +41,7 @@ pub mod global { impl Deref for GlobalContext { type Target = Secp256k1; - #[allow(unused_mut)] // Unused when `rand-std` is not enabled. + #[allow(unused_mut)] // Unused when `rand` + `std` is not enabled. fn deref(&self) -> &Self::Target { static ONCE: Once = Once::new(); static mut CONTEXT: Option> = None; @@ -48,7 +49,8 @@ pub mod global { let mut ctx = Secp256k1::new(); #[cfg(all( not(target_arch = "wasm32"), - feature = "rand-std", + feature = "rand", + feature = "std", not(feature = "global-context-less-secure") ))] { @@ -181,10 +183,12 @@ mod alloc_only { impl Secp256k1 { /// Lets you create a context in a generic manner (sign/verify/all). /// - /// 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` and `std` feature is enabled, context will have been randomized using + /// `thread_rng`. + /// If `rand` or `std` feature is not enabled please consider randomizing the context as + /// follows: /// ``` - /// # #[cfg(feature = "rand-std")] { + /// # #[cfg(all(feature = "rand", feature = "std"))] { /// # use secp256k1::Secp256k1; /// # use secp256k1::rand::{thread_rng, RngCore}; /// let mut ctx = Secp256k1::new(); @@ -195,7 +199,10 @@ mod alloc_only { /// ctx.seeded_randomize(&seed); /// # } /// ``` - #[cfg_attr(not(feature = "rand-std"), allow(clippy::let_and_return, unused_mut))] + #[cfg_attr( + not(all(feature = "rand", feature = "std")), + allow(clippy::let_and_return, unused_mut) + )] pub fn gen_new() -> Secp256k1 { #[cfg(target_arch = "wasm32")] ffi::types::sanity_checks_for_wasm(); @@ -214,7 +221,8 @@ mod alloc_only { #[cfg(all( not(target_arch = "wasm32"), - feature = "rand-std", + feature = "rand", + feature = "std", not(feature = "global-context-less-secure") ))] { @@ -229,27 +237,30 @@ mod alloc_only { impl Secp256k1 { /// Creates a new Secp256k1 context with all capabilities. /// - /// 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 (see docs - /// for `Secp256k1::gen_new()`). + /// If `rand` and `std` feature is enabled, context will have been randomized using + /// `thread_rng`. + /// If `rand` or `std` feature is not enabled please consider randomizing the context (see + /// docs for `Secp256k1::gen_new()`). pub fn new() -> Secp256k1 { Secp256k1::gen_new() } } impl Secp256k1 { /// Creates a new Secp256k1 context that can only be used for signing. /// - /// 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 (see docs - /// for `Secp256k1::gen_new()`). + /// If `rand` and `std` feature is enabled, context will have been randomized using + /// `thread_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 { Secp256k1::gen_new() } } impl Secp256k1 { /// Creates a new Secp256k1 context that can only be used for verification. /// - /// * 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 (see docs - /// for `Secp256k1::gen_new()`). + /// If `rand` and `std` feature is enabled, context will have been randomized using + /// `thread_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 { Secp256k1::gen_new() } } diff --git a/src/ecdh.rs b/src/ecdh.rs index e53dd79dd..f897beff0 100644 --- a/src/ecdh.rs +++ b/src/ecdh.rs @@ -20,7 +20,7 @@ const SHARED_SECRET_SIZE: usize = constants::SECRET_KEY_SIZE; /// # Examples /// /// ``` -/// # #[cfg(feature = "rand-std")] { +/// # #[cfg(all(feature = "rand", feature = "std"))] { /// # use secp256k1::{rand, Secp256k1}; /// # use secp256k1::ecdh::SharedSecret; /// let s = Secp256k1::new(); @@ -110,7 +110,7 @@ impl AsRef<[u8]> for SharedSecret { /// /// # Examples /// ``` -/// # #[cfg(all(feature = "hashes-std", feature = "rand-std"))] { +/// # #[cfg(all(feature = "hashes", feature = "rand", feature = "std"))] { /// # use secp256k1::{ecdh, rand, Secp256k1, PublicKey, SecretKey}; /// # use secp256k1::hashes::{Hash, sha512}; /// @@ -193,7 +193,7 @@ mod tests { use crate::Secp256k1; #[test] - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] fn ecdh() { let s = Secp256k1::signing_only(); let (sk1, pk1) = s.generate_keypair(&mut rand::thread_rng()); @@ -225,7 +225,7 @@ mod tests { #[test] #[cfg(not(secp256k1_fuzz))] - #[cfg(all(feature = "hashes-std", feature = "rand-std"))] + #[cfg(all(feature = "hashes", feature = "rand", feature = "std"))] fn hashes_and_sys_generate_same_secret() { use hashes::{sha256, Hash, HashEngine}; @@ -275,7 +275,7 @@ mod tests { } #[cfg(bench)] -#[cfg(feature = "rand-std")] // Currently only a single bench that requires "rand-std". +#[cfg(all(feature = "rand", feature = "std"))] // Currently only a single bench that requires "rand" + "std". mod benches { use test::{black_box, Bencher}; diff --git a/src/ecdsa/mod.rs b/src/ecdsa/mod.rs index 10f49e37e..6de255622 100644 --- a/src/ecdsa/mod.rs +++ b/src/ecdsa/mod.rs @@ -365,7 +365,7 @@ impl Secp256k1 { /// verify-capable context. /// /// ```rust - /// # #[cfg(feature = "rand-std")] { + /// # #[cfg(all(feature = "rand", feature = "std"))] { /// # use secp256k1::{rand, Secp256k1, Message, Error}; /// # /// # let secp = Secp256k1::new(); diff --git a/src/ecdsa/recovery.rs b/src/ecdsa/recovery.rs index adc3d8010..3d91216aa 100644 --- a/src/ecdsa/recovery.rs +++ b/src/ecdsa/recovery.rs @@ -219,7 +219,7 @@ mod tests { use crate::{Error, Message, Secp256k1, SecretKey}; #[test] - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] fn capabilities() { let sign = Secp256k1::signing_only(); let vrfy = Secp256k1::verification_only(); @@ -251,7 +251,7 @@ mod tests { #[test] #[cfg(not(secp256k1_fuzz))] // fixed sig vectors can't work with fuzz-sigs - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] #[rustfmt::skip] fn sign() { let mut s = Secp256k1::new(); @@ -276,7 +276,7 @@ mod tests { #[test] #[cfg(not(secp256k1_fuzz))] // fixed sig vectors can't work with fuzz-sigs - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] #[rustfmt::skip] fn sign_with_noncedata() { let mut s = Secp256k1::new(); @@ -301,7 +301,7 @@ mod tests { } #[test] - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] fn sign_and_verify_fail() { let mut s = Secp256k1::new(); s.randomize(&mut rand::thread_rng()); @@ -323,7 +323,7 @@ mod tests { } #[test] - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] fn sign_with_recovery() { let mut s = Secp256k1::new(); s.randomize(&mut rand::thread_rng()); @@ -339,7 +339,7 @@ mod tests { } #[test] - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] fn sign_with_recovery_and_noncedata() { let mut s = Secp256k1::new(); s.randomize(&mut rand::thread_rng()); @@ -357,7 +357,7 @@ mod tests { } #[test] - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] fn bad_recovery() { let mut s = Secp256k1::new(); s.randomize(&mut rand::thread_rng()); @@ -423,7 +423,7 @@ mod tests { } #[cfg(bench)] -#[cfg(feature = "rand-std")] // Currently only a single bench that requires "rand-std". +#[cfg(all(feature = "rand", feature = "std"))] // Currently only a single bench that requires "rand" + "std". mod benches { use test::{black_box, Bencher}; diff --git a/src/key.rs b/src/key.rs index 781a8ed79..3e59b0149 100644 --- a/src/key.rs +++ b/src/key.rs @@ -44,7 +44,7 @@ use crate::{ /// Basic usage: /// /// ``` -/// # #[cfg(feature = "rand-std")] { +/// # #[cfg(all(feature = "rand", feature = "std"))] { /// use secp256k1::{rand, Secp256k1, SecretKey}; /// /// let secp = Secp256k1::new(); @@ -182,7 +182,7 @@ impl SecretKey { /// # Examples /// /// ``` - /// # #[cfg(all(feature = "std", feature = "rand-std"))] { + /// # #[cfg(all(feature = "std", feature = "rand"))] { /// use secp256k1::{rand, SecretKey}; /// let secret_key = SecretKey::new(&mut rand::thread_rng()); /// # } @@ -235,7 +235,7 @@ impl SecretKey { /// # Examples /// /// ``` - /// # #[cfg(feature = "rand-std")] { + /// # #[cfg(all(feature = "rand", feature = "std"))] { /// use secp256k1::{rand, Secp256k1, SecretKey, Keypair}; /// /// let secp = Secp256k1::new(); @@ -409,7 +409,7 @@ impl PublicKey { /// # Examples /// /// ``` - /// # #[cfg(feature = "rand-std")] { + /// # #[cfg(all(feature = "rand", feature = "std"))] { /// use secp256k1::{rand, Secp256k1, SecretKey, PublicKey}; /// /// let secp = Secp256k1::new(); @@ -467,7 +467,7 @@ impl PublicKey { /// # Examples /// /// ``` - /// # #[cfg(feature = "rand-std")] { + /// # #[cfg(all(feature = "rand", feature = "std"))] { /// use secp256k1::{rand, Secp256k1, PublicKey, Keypair}; /// /// let secp = Secp256k1::new(); @@ -600,7 +600,7 @@ impl PublicKey { /// # Examples /// /// ``` - /// # #[cfg(feature = "rand-std")] { + /// # #[cfg(all(feature = "rand", feature = "std"))] { /// use secp256k1::{rand, Secp256k1}; /// /// let secp = Secp256k1::new(); @@ -626,7 +626,7 @@ impl PublicKey { /// # Examples /// /// ``` - /// # #[cfg(feature = "rand-std")] { + /// # #[cfg(all(feature = "rand", feature = "std"))] { /// use secp256k1::{rand, Secp256k1, PublicKey}; /// /// let secp = Secp256k1::new(); @@ -760,7 +760,7 @@ impl<'de> serde::Deserialize<'de> for PublicKey { /// Basic usage: /// /// ``` -/// # #[cfg(feature = "rand-std")] { +/// # #[cfg(all(feature = "rand", feature = "std"))] { /// use secp256k1::{rand, Keypair, Secp256k1}; /// /// let secp = Secp256k1::new(); @@ -857,7 +857,7 @@ impl Keypair { /// # Examples /// /// ``` - /// # #[cfg(feature = "rand-std")] { + /// # #[cfg(all(feature = "rand", feature = "std"))] { /// use secp256k1::{rand, Secp256k1, SecretKey, Keypair}; /// /// let secp = Secp256k1::new(); @@ -904,7 +904,7 @@ impl Keypair { /// # Examples /// /// ``` - /// # #[cfg(feature = "rand-std")] { + /// # #[cfg(all(feature = "rand", feature = "std"))] { /// use secp256k1::{Secp256k1, Keypair, Scalar}; /// /// let secp = Secp256k1::new(); @@ -957,7 +957,7 @@ impl Keypair { /// Constructs an schnorr signature for `msg` using the global [`SECP256K1`] context. #[inline] - #[cfg(all(feature = "global-context", feature = "rand-std"))] + #[cfg(all(feature = "global-context", feature = "rand", feature = "std"))] pub fn sign_schnorr(&self, msg: &[u8]) -> schnorr::Signature { SECP256K1.sign_schnorr(msg, self) } @@ -1078,7 +1078,7 @@ impl CPtr for Keypair { /// Basic usage: /// /// ``` -/// # #[cfg(feature = "rand-std")] { +/// # #[cfg(all(feature = "rand", feature = "std"))] { /// use secp256k1::{rand, Secp256k1, Keypair, XOnlyPublicKey}; /// /// let secp = Secp256k1::new(); @@ -1210,7 +1210,7 @@ impl XOnlyPublicKey { /// # Examples /// /// ``` - /// # #[cfg(feature = "rand-std")] { + /// # #[cfg(all(feature = "rand", feature = "std"))] { /// use secp256k1::{Secp256k1, Keypair, Scalar, XOnlyPublicKey}; /// /// let secp = Secp256k1::new(); @@ -1270,7 +1270,7 @@ impl XOnlyPublicKey { /// # Examples /// /// ``` - /// # #[cfg(feature = "rand-std")] { + /// # #[cfg(all(feature = "rand", feature = "std"))] { /// use secp256k1::{Secp256k1, Keypair, Scalar}; /// /// let secp = Secp256k1::new(); @@ -1576,7 +1576,7 @@ mod test { } #[test] - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] fn keypair_slice_round_trip() { let s = Secp256k1::new(); @@ -1856,7 +1856,7 @@ mod test { } #[test] - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] fn tweak_add_arbitrary_data() { let s = Secp256k1::new(); @@ -1875,7 +1875,7 @@ mod test { } #[test] - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] fn tweak_add_zero() { let s = Secp256k1::new(); @@ -1890,7 +1890,7 @@ mod test { } #[test] - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] fn tweak_mul_arbitrary_data() { let s = Secp256k1::new(); @@ -1909,7 +1909,7 @@ mod test { } #[test] - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] fn tweak_mul_zero() { let s = Secp256k1::new(); let (sk, _) = s.generate_keypair(&mut rand::thread_rng()); @@ -1919,7 +1919,7 @@ mod test { } #[test] - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] fn test_negation() { let s = Secp256k1::new(); @@ -1941,7 +1941,7 @@ mod test { } #[test] - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] fn pubkey_hash() { use std::collections::hash_map::DefaultHasher; use std::collections::HashSet; @@ -2024,7 +2024,7 @@ mod test { } #[test] - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] fn create_pubkey_combine() { let s = Secp256k1::new(); @@ -2134,7 +2134,7 @@ mod test { } #[test] - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] fn test_tweak_add_then_tweak_add_check() { let s = Secp256k1::new(); @@ -2393,7 +2393,7 @@ mod test { } #[test] - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] fn test_keypair_from_str() { let ctx = crate::Secp256k1::new(); let keypair = Keypair::new(&ctx, &mut rand::thread_rng()); diff --git a/src/lib.rs b/src/lib.rs index 20ff5d44e..4e5dc7168 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,7 +7,7 @@ //! //! To minimize dependencies, some functions are feature-gated. To generate //! random keys or to re-randomize a context object, compile with the -//! `rand-std` feature. If you are willing to use the `rand-std` feature, we +//! `rand` and `std` features. If you are willing to use these features, we //! have enabled an additional defense-in-depth sidechannel protection for //! our context objects, which re-blinds certain operations on secret key //! data. To de/serialize objects with serde, compile with "serde". @@ -28,7 +28,7 @@ //! trigger any assertion failures in the upstream library. //! //! ```rust -//! # #[cfg(all(feature = "rand-std", feature = "hashes-std"))] { +//! # #[cfg(all(feature = "rand", feature = "hashes", feature = "std"))] { //! use secp256k1::rand::rngs::OsRng; //! use secp256k1::{Secp256k1, Message}; //! use secp256k1::hashes::{sha256, Hash}; @@ -46,7 +46,7 @@ //! If the "global-context" feature is enabled you have access to an alternate API. //! //! ```rust -//! # #[cfg(all(feature = "global-context", feature = "hashes-std", feature = "rand-std"))] { +//! # #[cfg(all(feature = "global-context", feature = "hashes", feature = "rand", feature = "std"))] { //! use secp256k1::{generate_keypair, Message}; //! use secp256k1::hashes::{sha256, Hash}; //! @@ -59,7 +59,7 @@ //! # } //! ``` //! -//! The above code requires `rust-secp256k1` to be compiled with the `rand-std` and `hashes-std` +//! The above code requires `rust-secp256k1` to be compiled with the `rand`, `hashes`, and `std` //! feature enabled, to get access to [`generate_keypair`](struct.Secp256k1.html#method.generate_keypair) //! Alternately, keys and messages can be parsed from slices, like //! @@ -71,7 +71,6 @@ //! let secret_key = SecretKey::from_slice(&[0xcd; 32]).expect("32 bytes, within curve order"); //! let public_key = PublicKey::from_secret_key(&secp, &secret_key); //! // This is unsafe unless the supplied byte slice is the output of a cryptographic hash function. -//! // See the above example for how to use this library together with `hashes-std`. //! let message = Message::from_digest_slice(&[0xab; 32]).expect("32 bytes"); //! //! let sig = secp.sign_ecdsa(&message, &secret_key); @@ -128,9 +127,7 @@ //! * `std` - use standard Rust library, enabled by default. //! * `alloc` - use the `alloc` standard Rust library to provide heap allocations. //! * `rand` - use `rand` library to provide random generator (e.g. to generate keys). -//! * `rand-std` - use `rand` library with its `std` feature enabled. (Implies `rand`.) //! * `hashes` - use the `hashes` library. -//! * `hashes-std` - use the `hashes` library with its `std` feature enabled (implies `hashes`). //! * `recovery` - enable functions that can compute the public key from signature. //! * `lowmemory` - optimize the library for low-memory environments. //! * `global-context` - enable use of global secp256k1 context (implies `std`). @@ -525,7 +522,7 @@ mod tests { } #[test] - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] // In rustc 1.72 this Clippy lint was pulled out of clippy and into rustc, and // was made deny-by-default, breaking compilation of this test. Aside from this // breaking change, which there is no point in bugging, the rename was done so @@ -597,7 +594,7 @@ mod tests { } #[test] - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] fn test_preallocation() { use crate::ffi::types::AlignedType; @@ -624,7 +621,7 @@ mod tests { } #[test] - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] fn capabilities() { let sign = Secp256k1::signing_only(); let vrfy = Secp256k1::verification_only(); @@ -653,7 +650,7 @@ mod tests { } #[test] - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] fn signature_serialize_roundtrip() { let mut s = Secp256k1::new(); s.randomize(&mut rand::thread_rng()); @@ -743,7 +740,7 @@ mod tests { } #[test] - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] fn sign_and_verify_ecdsa() { let mut s = Secp256k1::new(); s.randomize(&mut rand::thread_rng()); @@ -777,7 +774,7 @@ mod tests { } #[test] - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] fn sign_and_verify_extreme() { let mut s = Secp256k1::new(); s.randomize(&mut rand::thread_rng()); @@ -811,7 +808,7 @@ mod tests { } #[test] - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] fn sign_and_verify_fail() { let mut s = Secp256k1::new(); s.randomize(&mut rand::thread_rng()); @@ -852,7 +849,7 @@ mod tests { } #[test] - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] fn test_hex() { use rand::RngCore; @@ -1009,7 +1006,7 @@ mod tests { } #[cfg(bench)] -#[cfg(feature = "rand-std")] +#[cfg(all(feature = "rand", feature = "std"))] mod benches { use rand::rngs::mock::StepRng; use test::{black_box, Bencher}; diff --git a/src/scalar.rs b/src/scalar.rs index 56adfb320..4bd4d55f4 100644 --- a/src/scalar.rs +++ b/src/scalar.rs @@ -41,7 +41,7 @@ impl Scalar { pub const MAX: Scalar = Scalar(MAX_RAW); /// Generates a random scalar - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] pub fn random() -> Self { Self::random_custom(rand::thread_rng()) } /// Generates a random scalar using supplied RNG diff --git a/src/schnorr.rs b/src/schnorr.rs index 4451d92a1..45516bc7a 100644 --- a/src/schnorr.rs +++ b/src/schnorr.rs @@ -127,7 +127,7 @@ impl Secp256k1 { /// Creates a schnorr signature internally using the [`rand::rngs::ThreadRng`] random number /// generator to generate the auxiliary random data. - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] pub fn sign_schnorr(&self, msg: &[u8], keypair: &Keypair) -> Signature { self.sign_schnorr_with_rng(msg, keypair, &mut rand::thread_rng()) } @@ -193,7 +193,7 @@ impl Secp256k1 { mod tests { use core::str::FromStr; - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] use rand::rngs::ThreadRng; #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::wasm_bindgen_test as test; @@ -213,7 +213,7 @@ mod tests { } #[test] - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] fn schnorr_sign_with_aux_rand_verify() { sign_helper(|secp, msg, seckey, rng| { let aux_rand = crate::random_32_bytes(rng); @@ -222,22 +222,22 @@ mod tests { } #[test] - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] fn schnor_sign_with_rng_verify() { sign_helper(|secp, msg, seckey, rng| secp.sign_schnorr_with_rng(msg, seckey, rng)) } #[test] - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] fn schnorr_sign_verify() { sign_helper(|secp, msg, seckey, _| secp.sign_schnorr(msg, seckey)) } #[test] - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] fn schnorr_sign_no_aux_rand_verify() { sign_helper(|secp, msg, seckey, _| secp.sign_schnorr_no_aux_rand(msg, seckey)) } - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] fn sign_helper(sign: fn(&Secp256k1, &[u8], &Keypair, &mut ThreadRng) -> Signature) { let secp = Secp256k1::new(); @@ -317,7 +317,7 @@ mod tests { } #[test] - #[cfg(feature = "rand-std")] + #[cfg(all(feature = "rand", feature = "std"))] fn test_pubkey_serialize_roundtrip() { let secp = Secp256k1::new(); let kp = Keypair::new(&secp, &mut rand::thread_rng());