diff --git a/CHANGELOG.md b/CHANGELOG.md index d60912ce1..bdc62e859 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ -# Unreleased +# 0.28.0 - 202-08-09 -* Bump MSRV to 1.48 +* Depend on recent release of `bitcoin_hashes` v0.13.0 [#621](https://github.com/rust-bitcoin/rust-secp256k1/pull/621) +* Add a verify function to `PublicKey` [#618](https://github.com/rust-bitcoin/rust-secp256k1/pull/618) +* Add serialize function for schnorr::Signature [#607](https://github.com/rust-bitcoin/rust-secp256k1/pull/607) +* Bump MSRV to 1.48 [#595](https://github.com/rust-bitcoin/rust-secp256k1/pull/595) * Remove implementations of `PartialEq`, `Eq`, `PartialOrd`, `Ord`, and `Hash` from the `impl_array_newtype` macro. Users will now need to derive these traits if they are wanted. diff --git a/contrib/Cargo.minimal.lock b/Cargo-minimal.lock similarity index 96% rename from contrib/Cargo.minimal.lock rename to Cargo-minimal.lock index 134cc67ec..0c2ca1718 100644 --- a/contrib/Cargo.minimal.lock +++ b/Cargo-minimal.lock @@ -18,18 +18,18 @@ dependencies = [ ] [[package]] -name = "bitcoin-private" -version = "0.1.0" +name = "bitcoin-internals" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73290177011694f38ec25e165d0387ab7ea749a4b81cd4c80dae5988229f7a57" +checksum = "9425c3bf7089c983facbae04de54513cce73b41c7f9ff8c845b54e7bc64ebbfb" [[package]] name = "bitcoin_hashes" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d7066118b13d4b20b23645932dfb3a81ce7e29f95726c2036fa33cd7b092501" +version = "0.13.0" +source = "git+https://github.com/tcharding/rust-bitcoin?rev=37d1d288a67fe7e0cd53962f66faa854621bade0#37d1d288a67fe7e0cd53962f66faa854621bade0" dependencies = [ - "bitcoin-private", + "bitcoin-internals", + "hex-conservative", ] [[package]] @@ -103,6 +103,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee6c0438de3ca4d8cac2eec62b228e2f8865cfe9ebefea720406774223fa2d2e" +[[package]] +name = "hex-conservative" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30ed443af458ccb6d81c1e7e661545f94d3176752fb1df2f543b902a1e0f51e2" + [[package]] name = "itoa" version = "0.3.0" @@ -250,7 +256,7 @@ checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" [[package]] name = "secp256k1" -version = "0.27.0" +version = "0.28.0" dependencies = [ "bincode", "bitcoin_hashes", diff --git a/contrib/Cargo.latest.lock b/Cargo-recent.lock similarity index 94% rename from contrib/Cargo.latest.lock rename to Cargo-recent.lock index 72882b8eb..a176e436e 100644 --- a/contrib/Cargo.latest.lock +++ b/Cargo-recent.lock @@ -12,18 +12,18 @@ dependencies = [ ] [[package]] -name = "bitcoin-private" -version = "0.1.0" +name = "bitcoin-internals" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73290177011694f38ec25e165d0387ab7ea749a4b81cd4c80dae5988229f7a57" +checksum = "9425c3bf7089c983facbae04de54513cce73b41c7f9ff8c845b54e7bc64ebbfb" [[package]] name = "bitcoin_hashes" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d7066118b13d4b20b23645932dfb3a81ce7e29f95726c2036fa33cd7b092501" +version = "0.13.0" +source = "git+https://github.com/tcharding/rust-bitcoin?rev=37d1d288a67fe7e0cd53962f66faa854621bade0#37d1d288a67fe7e0cd53962f66faa854621bade0" dependencies = [ - "bitcoin-private", + "bitcoin-internals", + "hex-conservative", ] [[package]] @@ -79,6 +79,12 @@ version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" +[[package]] +name = "hex-conservative" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30ed443af458ccb6d81c1e7e661545f94d3176752fb1df2f543b902a1e0f51e2" + [[package]] name = "js-sys" version = "0.3.61" @@ -171,7 +177,7 @@ checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" [[package]] name = "secp256k1" -version = "0.27.0" +version = "0.28.0" dependencies = [ "bincode", "bitcoin_hashes", diff --git a/Cargo.toml b/Cargo.toml index 0f265559c..d5704d357 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "secp256k1" -version = "0.27.0" +version = "0.28.0" authors = [ "Dawid Ciężarkiewicz ", "Andrew Poelstra " ] license = "CC0-1.0" @@ -21,8 +21,7 @@ default = ["std"] std = ["alloc", "secp256k1-sys/std"] # allow use of Secp256k1::new and related API that requires an allocator alloc = ["secp256k1-sys/alloc"] -bitcoin-hashes = ["bitcoin_hashes"] # Feature alias because of the underscore. -bitcoin-hashes-std = ["std", "bitcoin_hashes", "bitcoin_hashes/std"] +hashes-std = ["std", "hashes/std"] rand-std = ["std", "rand", "rand/std", "rand/std_rng"] recovery = ["secp256k1-sys/recovery"] lowmemory = ["secp256k1-sys/lowmemory"] @@ -40,8 +39,8 @@ secp256k1-sys = { version = "0.8.1", default-features = false, path = "./secp256 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., bitcoin-hashes-std -bitcoin_hashes = { version = "0.12", default-features = false, optional = true } +# the respective -std feature e.g., hashes-std +hashes = { package = "bitcoin_hashes", version = "0.13.0", default-features = false, optional = true } rand = { version = "0.8", default-features = false, optional = true } [dev-dependencies] @@ -57,11 +56,11 @@ getrandom = { version = "0.2", features = ["js"] } [[example]] name = "sign_verify_recovery" -required-features = ["recovery", "bitcoin-hashes-std"] +required-features = ["recovery", "hashes-std"] [[example]] name = "sign_verify" -required-features = ["bitcoin-hashes-std"] +required-features = ["hashes-std"] [[example]] name = "generate_keys" @@ -70,3 +69,12 @@ required-features = ["rand-std"] [workspace] members = ["secp256k1-sys"] exclude = ["no_std_test"] + +# TODO: Remove this when hashes v.0.13.0 is released. +[patch.crates-io.bitcoin_hashes] +git = "https://github.com/tcharding/rust-bitcoin" +# source branch: tharding/06-20-hashes-release +# rust-bicoin PR: #1917 +# One commit back from branch tip. +# commit: `hashes: Bump version to 0.13.0` +rev = "37d1d288a67fe7e0cd53962f66faa854621bade0" diff --git a/contrib/_test.sh b/contrib/_test.sh new file mode 100755 index 000000000..1b1bbdccd --- /dev/null +++ b/contrib/_test.sh @@ -0,0 +1,120 @@ +#!/bin/sh + +set -ex + +FEATURES="hashes global-context lowmemory rand recovery serde std alloc hashes-std rand-std" + +cargo --version +rustc --version + +# Work out if we are using a nightly toolchain. +NIGHTLY=false +if cargo --version | grep nightly; then + NIGHTLY=true +fi + +# Pin dependencies as required if we are using MSRV toolchain. +if cargo --version | grep "1\.48"; then + cargo update -p wasm-bindgen-test --precise 0.3.34 + cargo update -p serde --precise 1.0.156 +fi + +# Test if panic in C code aborts the process (either with a real panic or with SIGILL) +cargo test --locked -- --ignored --exact 'tests::test_panic_raw_ctx_should_terminate_abnormally' 2>&1 | tee /dev/stderr | grep "SIGILL\\|panicked at '\[libsecp256k1\]" + +# Make all cargo invocations verbose +export CARGO_TERM_VERBOSE=true + +# Defaults / sanity checks +cargo build --locked --all +cargo test --locked --all + +if [ "$DO_FEATURE_MATRIX" = true ]; then + cargo build --locked --all --no-default-features + cargo test --locked --all --no-default-features + + # All features + cargo build --locked --all --no-default-features --features="$FEATURES" + cargo test --locked --all --no-default-features --features="$FEATURES" + # Single features + for feature in ${FEATURES} + do + cargo build --locked --all --no-default-features --features="$feature" + cargo test --locked --all --no-default-features --features="$feature" + done + # Features tested with 'std' feature enabled. + for feature in ${FEATURES} + do + cargo build --locked --all --no-default-features --features="std,$feature" + cargo test --locked --all --no-default-features --features="std,$feature" + done + # Other combos + RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --locked --all + RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --locked --all --features="$FEATURES" + cargo test --locked --all --features="rand serde" + + if [ "$NIGHTLY" = true ]; then + cargo test --locked --all --all-features + RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --locked --all --all-features + 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 +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 +fi + +# Build the docs if told to (this only works with the nightly toolchain) +if [ "$DO_DOCSRS" = true ]; then + RUSTDOCFLAGS="--cfg docsrs -D warnings -D rustdoc::broken-intra-doc-links" cargo +nightly doc --all-features +fi + +# Build the docs with a stable toolchain, in unison with the DO_DOCSRS command +# above this checks that we feature guarded docs imports correctly. +if [ "$DO_DOCS" = true ]; then + RUSTDOCFLAGS="-D warnings" cargo +stable doc --all-features +fi + +# Address Sanitizer +if [ "$DO_ASAN" = true ]; then + clang --version + cargo clean + CC='clang -fsanitize=address -fno-omit-frame-pointer' \ + RUSTFLAGS='-Zsanitizer=address -Clinker=clang -Cforce-frame-pointers=yes' \ + ASAN_OPTIONS='detect_leaks=1 detect_invalid_pointer_pairs=1 detect_stack_use_after_return=1' \ + cargo test --lib --all --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu + cargo clean + # The -Cllvm-args=-msan-eager-checks=0 flag was added to overcome this issue: + # https://github.com/rust-bitcoin/rust-secp256k1/pull/573#issuecomment-1399465995 + CC='clang -fsanitize=memory -fno-omit-frame-pointer' \ + RUSTFLAGS='-Zsanitizer=memory -Zsanitizer-memory-track-origins -Cforce-frame-pointers=yes -Cllvm-args=-msan-eager-checks=0' \ + cargo test --lib --all --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu + cargo run --release --manifest-path=./no_std_test/Cargo.toml | grep -q "Verified Successfully" + cargo run --release --features=alloc --manifest-path=./no_std_test/Cargo.toml | grep -q "Verified alloc Successfully" +fi + +# Run formatter if told to. +if [ "$DO_FMT" = true ]; then + if [ "$NIGHTLY" = false ]; then + echo "DO_FMT requires a nightly toolchain (consider using RUSTUP_TOOLCHAIN)" + exit 1 + fi + rustup component add rustfmt + cargo fmt --check || exit 1 +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 +fi + +exit 0 diff --git a/contrib/test.sh b/contrib/test.sh index e76c193fd..b5031a8e3 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -2,128 +2,20 @@ set -ex -FEATURES="bitcoin-hashes global-context lowmemory rand recovery serde std alloc bitcoin-hashes-std rand-std" - -cargo --version -rustc --version - -# Work out if we are using a nightly toolchain. -NIGHTLY=false -if cargo --version | grep nightly; then - NIGHTLY=true -fi - -# Pin dependencies as required if we are using MSRV toolchain. -if cargo --version | grep "1\.48"; then - cargo update -p wasm-bindgen-test --precise 0.3.34 - cargo update -p serde --precise 1.0.156 -fi - -# Test if panic in C code aborts the process (either with a real panic or with SIGILL) -cargo test -- --ignored --exact 'tests::test_panic_raw_ctx_should_terminate_abnormally' 2>&1 | tee /dev/stderr | grep "SIGILL\\|panicked at '\[libsecp256k1\]" - -# Make all cargo invocations verbose -export CARGO_TERM_VERBOSE=true - -# Defaults / sanity checks -cargo build --all -cargo test --all - -if [ "$DO_FEATURE_MATRIX" = true ]; then - cargo build --all --no-default-features - cargo test --all --no-default-features - - # All features - cargo build --all --no-default-features --features="$FEATURES" - cargo test --all --no-default-features --features="$FEATURES" - # Single features - for feature in ${FEATURES} - do - cargo build --all --no-default-features --features="$feature" - cargo test --all --no-default-features --features="$feature" - done - # Features tested with 'std' feature enabled. - for feature in ${FEATURES} - do - cargo build --all --no-default-features --features="std,$feature" - cargo test --all --no-default-features --features="std,$feature" - done - # Other combos - RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --all - RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --all --features="$FEATURES" - cargo test --all --features="rand serde" - - if [ "$NIGHTLY" = true ]; then - cargo test --all --all-features - RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --all --all-features - fi - - # Examples - cargo run --example sign_verify --features=bitcoin-hashes-std - cargo run --example sign_verify_recovery --features=recovery,bitcoin-hashes-std - cargo run --example generate_keys --features=rand-std -fi - -if [ "$DO_LINT" = true ] -then - cargo clippy --all-features --all-targets -- -D warnings - cargo clippy --example sign_verify --features=bitcoin-hashes-std -- -D warnings - cargo clippy --example sign_verify_recovery --features=recovery,bitcoin-hashes-std -- -D warnings - cargo clippy --example generate_keys --features=rand-std -- -D warnings -fi - -# Build the docs if told to (this only works with the nightly toolchain) -if [ "$DO_DOCSRS" = true ]; then - RUSTDOCFLAGS="--cfg docsrs -D warnings -D rustdoc::broken-intra-doc-links" cargo +nightly doc --all-features -fi - -# Build the docs with a stable toolchain, in unison with the DO_DOCSRS command -# above this checks that we feature guarded docs imports correctly. -if [ "$DO_DOCS" = true ]; then - RUSTDOCFLAGS="-D warnings" cargo +stable doc --all-features -fi +REPO_DIR=$(git rev-parse --show-toplevel) # Webassembly stuff +# +# The wasm-pack command does not correctly pass args to cargo so we cannot use --locked and test +# with per-commited lockfiles (recent/minimal). Just run the WASM tests from here instead. if [ "$DO_WASM" = true ]; then clang --version CARGO_TARGET_DIR=wasm cargo install --force wasm-pack printf '\n[lib]\ncrate-type = ["cdylib", "rlib"]\n' >> Cargo.toml CC=clang wasm-pack build CC=clang wasm-pack test --node -fi - -# Address Sanitizer -if [ "$DO_ASAN" = true ]; then - clang --version - cargo clean - CC='clang -fsanitize=address -fno-omit-frame-pointer' \ - RUSTFLAGS='-Zsanitizer=address -Clinker=clang -Cforce-frame-pointers=yes' \ - ASAN_OPTIONS='detect_leaks=1 detect_invalid_pointer_pairs=1 detect_stack_use_after_return=1' \ - cargo test --lib --all --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu - cargo clean - # The -Cllvm-args=-msan-eager-checks=0 flag was added to overcome this issue: - # https://github.com/rust-bitcoin/rust-secp256k1/pull/573#issuecomment-1399465995 - CC='clang -fsanitize=memory -fno-omit-frame-pointer' \ - RUSTFLAGS='-Zsanitizer=memory -Zsanitizer-memory-track-origins -Cforce-frame-pointers=yes -Cllvm-args=-msan-eager-checks=0' \ - cargo test --lib --all --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu - cargo run --release --manifest-path=./no_std_test/Cargo.toml | grep -q "Verified Successfully" - cargo run --release --features=alloc --manifest-path=./no_std_test/Cargo.toml | grep -q "Verified alloc Successfully" -fi - -# Run formatter if told to. -if [ "$DO_FMT" = true ]; then - if [ "$NIGHTLY" = false ]; then - echo "DO_FMT requires a nightly toolchain (consider using RUSTUP_TOOLCHAIN)" - exit 1 - fi - rustup component add rustfmt - cargo fmt --check || exit 1 -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 + exit 0 fi -exit 0 +$REPO_DIR/contrib/_test.sh diff --git a/examples/sign_verify.rs b/examples/sign_verify.rs index 081d1b062..6087c1a16 100644 --- a/examples/sign_verify.rs +++ b/examples/sign_verify.rs @@ -1,7 +1,7 @@ -extern crate bitcoin_hashes; +extern crate hashes; extern crate secp256k1; -use bitcoin_hashes::{sha256, Hash}; +use hashes::{sha256, Hash}; use secp256k1::{ecdsa, Error, Message, PublicKey, Secp256k1, SecretKey, Signing, Verification}; fn verify( diff --git a/examples/sign_verify_recovery.rs b/examples/sign_verify_recovery.rs index edcc7b3bc..09baaabd0 100644 --- a/examples/sign_verify_recovery.rs +++ b/examples/sign_verify_recovery.rs @@ -1,7 +1,7 @@ -extern crate bitcoin_hashes; +extern crate hashes; extern crate secp256k1; -use bitcoin_hashes::{sha256, Hash}; +use hashes::{sha256, Hash}; use secp256k1::{ecdsa, Error, Message, PublicKey, Secp256k1, SecretKey, Signing, Verification}; fn recover( diff --git a/no_std_test/src/main.rs b/no_std_test/src/main.rs index d98276c67..2e2a3bd62 100644 --- a/no_std_test/src/main.rs +++ b/no_std_test/src/main.rs @@ -27,7 +27,6 @@ //! * Requires linking with `libc` for calling `printf`. //! -#![feature(lang_items)] #![feature(start)] #![feature(core_intrinsics)] #![feature(panic_info_message)] diff --git a/src/ecdh.rs b/src/ecdh.rs index e01366e53..e53dd79dd 100644 --- a/src/ecdh.rs +++ b/src/ecdh.rs @@ -110,7 +110,7 @@ impl AsRef<[u8]> for SharedSecret { /// /// # Examples /// ``` -/// # #[cfg(all(feature = "bitcoin-hashes-std", feature = "rand-std"))] { +/// # #[cfg(all(feature = "hashes-std", feature = "rand-std"))] { /// # use secp256k1::{ecdh, rand, Secp256k1, PublicKey, SecretKey}; /// # use secp256k1::hashes::{Hash, sha512}; /// @@ -225,9 +225,9 @@ mod tests { #[test] #[cfg(not(secp256k1_fuzz))] - #[cfg(all(feature = "bitcoin-hashes-std", feature = "rand-std"))] - fn bitcoin_hashes_and_sys_generate_same_secret() { - use bitcoin_hashes::{sha256, Hash, HashEngine}; + #[cfg(all(feature = "hashes-std", feature = "rand-std"))] + fn hashes_and_sys_generate_same_secret() { + use hashes::{sha256, Hash, HashEngine}; use crate::ecdh::shared_secret_point; diff --git a/src/key.rs b/src/key.rs index 0eb747e55..651eb5e72 100644 --- a/src/key.rs +++ b/src/key.rs @@ -16,7 +16,7 @@ use crate::Error::{self, InvalidPublicKey, InvalidPublicKeySum, InvalidSecretKey use crate::{constants, from_hex, schnorr, Message, Scalar, Secp256k1, Signing, Verification}; #[cfg(feature = "global-context")] use crate::{ecdsa, SECP256K1}; -#[cfg(feature = "bitcoin_hashes")] +#[cfg(feature = "hashes")] use crate::{hashes, ThirtyTwoByteHash}; /// Secret 256-bit key used as `x` in an ECDSA signature. @@ -253,12 +253,12 @@ impl SecretKey { /// Constructs a [`SecretKey`] by hashing `data` with hash algorithm `H`. /// - /// Requires the feature `bitcoin_hashes` to be enabled. + /// Requires the feature `hashes` to be enabled. /// /// # Examples /// /// ``` - /// # #[cfg(feature="bitcoin_hashes")] { + /// # #[cfg(feature="hashes")] { /// use secp256k1::hashes::{sha256, Hash}; /// use secp256k1::SecretKey; /// @@ -269,7 +269,7 @@ impl SecretKey { /// assert_eq!(sk1, sk2); /// # } /// ``` - #[cfg(feature = "bitcoin_hashes")] + #[cfg(feature = "hashes")] #[inline] pub fn from_hashed_data(data: &[u8]) -> Self { ::hash(data).into() @@ -366,7 +366,7 @@ impl SecretKey { } } -#[cfg(feature = "bitcoin_hashes")] +#[cfg(feature = "hashes")] impl From for SecretKey { /// Converts a 32-byte hash directly to a secret key without error paths. fn from(t: T) -> SecretKey { @@ -1036,6 +1036,8 @@ impl serde::Serialize for KeyPair { } #[cfg(feature = "serde")] +#[allow(unused_variables)] // For `data` under some feature combinations (the unconditional panic below). +#[allow(unreachable_code)] // For `KeyPair::from_seckey_slice` after unconditional panic. impl<'de> serde::Deserialize<'de> for KeyPair { fn deserialize>(d: D) -> Result { if d.is_human_readable() { @@ -1051,7 +1053,7 @@ impl<'de> serde::Deserialize<'de> for KeyPair { let ctx = Secp256k1::signing_only(); #[cfg(not(any(feature = "global-context", feature = "alloc")))] - let ctx: Secp256k1 = panic!("The previous implementation was panicking too, please enable the global-context feature of rust-secp256k1"); + let ctx: Secp256k1 = panic!("cannot deserialize key pair without a context (please enable either the global-context or alloc feature)"); #[allow(clippy::needless_borrow)] KeyPair::from_seckey_slice(&ctx, data) diff --git a/src/lib.rs b/src/lib.rs index 14d65f224..69f72b6dd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,7 +28,7 @@ //! trigger any assertion failures in the upstream library. //! //! ```rust -//! # #[cfg(all(feature = "rand-std", feature = "bitcoin-hashes-std"))] { +//! # #[cfg(all(feature = "rand-std", feature = "hashes-std"))] { //! use secp256k1::rand::rngs::OsRng; //! use secp256k1::{Secp256k1, Message}; //! use secp256k1::hashes::sha256; @@ -45,7 +45,7 @@ //! If the "global-context" feature is enabled you have access to an alternate API. //! //! ```rust -//! # #[cfg(all(feature = "global-context", feature = "bitcoin-hashes-std", feature = "rand-std"))] { +//! # #[cfg(all(feature = "global-context", feature = "hashes-std", feature = "rand-std"))] { //! use secp256k1::{generate_keypair, Message}; //! use secp256k1::hashes::sha256; //! @@ -57,7 +57,7 @@ //! # } //! ``` //! -//! The above code requires `rust-secp256k1` to be compiled with the `rand-std` and `bitcoin-hashes-std` +//! The above code requires `rust-secp256k1` to be compiled with the `rand-std` and `hashes-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 //! @@ -69,7 +69,7 @@ //! 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 `bitcoin-hashes-std`. +//! // See the above example for how to use this library together with `hashes-std`. //! let message = Message::from_slice(&[0xab; 32]).expect("32 bytes"); //! //! let sig = secp.sign_ecdsa(&message, &secret_key); @@ -127,8 +127,8 @@ //! * `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`.) -//! * `bitcoin-hashes` - use the `bitcoin_hashes` library. -//! * `bitcoin-hashes-std` - use the `bitcoin_hashes` library with its `std` feature enabled (implies `bitcoin-hashes`). +//! * `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`). @@ -151,6 +151,9 @@ extern crate core; #[cfg(bench)] extern crate test; +#[cfg(feature = "hashes")] +pub extern crate hashes; + #[macro_use] mod macros; #[macro_use] @@ -170,10 +173,10 @@ use core::marker::PhantomData; use core::ptr::NonNull; use core::{fmt, mem, str}; -#[cfg(feature = "bitcoin_hashes")] -pub use bitcoin_hashes as hashes; #[cfg(feature = "global-context")] pub use context::global::SECP256K1; +#[cfg(feature = "hashes")] +use hashes::Hash; #[cfg(feature = "rand")] pub use rand; pub use secp256k1_sys as ffi; @@ -183,8 +186,6 @@ pub use serde; pub use crate::context::*; use crate::ffi::types::AlignedType; use crate::ffi::CPtr; -#[cfg(feature = "bitcoin_hashes")] -use crate::hashes::Hash; pub use crate::key::{PublicKey, SecretKey, *}; pub use crate::scalar::Scalar; @@ -196,17 +197,17 @@ pub trait ThirtyTwoByteHash { fn into_32(self) -> [u8; 32]; } -#[cfg(feature = "bitcoin_hashes")] +#[cfg(feature = "hashes")] impl ThirtyTwoByteHash for hashes::sha256::Hash { fn into_32(self) -> [u8; 32] { self.to_byte_array() } } -#[cfg(feature = "bitcoin_hashes")] +#[cfg(feature = "hashes")] impl ThirtyTwoByteHash for hashes::sha256d::Hash { fn into_32(self) -> [u8; 32] { self.to_byte_array() } } -#[cfg(feature = "bitcoin_hashes")] +#[cfg(feature = "hashes")] impl ThirtyTwoByteHash for hashes::sha256t::Hash { fn into_32(self) -> [u8; 32] { self.to_byte_array() } } @@ -238,12 +239,12 @@ impl Message { /// Constructs a [`Message`] by hashing `data` with hash algorithm `H`. /// - /// Requires the feature `bitcoin-hashes` to be enabled. + /// Requires the feature `hashes` to be enabled. /// /// # Examples /// /// ``` - /// # #[cfg(feature = "bitcoin_hashes")] { + /// # #[cfg(feature = "hashes")] { /// use secp256k1::hashes::{sha256, Hash}; /// use secp256k1::Message; /// @@ -254,7 +255,7 @@ impl Message { /// assert_eq!(m1, m2); /// # } /// ``` - #[cfg(feature = "bitcoin_hashes")] + #[cfg(feature = "hashes")] pub fn from_hashed_data(data: &[u8]) -> Self { ::hash(data).into() } @@ -1012,19 +1013,19 @@ mod tests { assert!(SECP256K1.verify_ecdsa(&msg, &sig, &pk).is_ok()); } - #[cfg(feature = "bitcoin_hashes")] + #[cfg(feature = "hashes")] #[test] fn test_from_hash() { - use crate::hashes::{self, Hash}; + use hashes::{sha256, sha256d, Hash}; let test_bytes = "Hello world!".as_bytes(); - let hash = hashes::sha256::Hash::hash(test_bytes); + let hash = sha256::Hash::hash(test_bytes); let msg = Message::from(hash); assert_eq!(msg.0, hash.to_byte_array()); assert_eq!(msg, Message::from_hashed_data::(test_bytes)); - let hash = hashes::sha256d::Hash::hash(test_bytes); + let hash = sha256d::Hash::hash(test_bytes); let msg = Message::from(hash); assert_eq!(msg.0, hash.to_byte_array()); assert_eq!(msg, Message::from_hashed_data::(test_bytes)); diff --git a/src/secret.rs b/src/secret.rs index cec8a2f33..fa460d6ad 100644 --- a/src/secret.rs +++ b/src/secret.rs @@ -32,10 +32,10 @@ macro_rules! impl_display_secret { } } - #[cfg(all(not(feature = "std"), feature = "bitcoin_hashes"))] + #[cfg(all(not(feature = "std"), feature = "hashes"))] impl ::core::fmt::Debug for $thing { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { - use crate::hashes::{sha256, Hash, HashEngine}; + use hashes::{sha256, Hash, HashEngine}; let tag = "rust-secp256k1DEBUG"; @@ -50,10 +50,10 @@ macro_rules! impl_display_secret { } } - #[cfg(all(not(feature = "std"), not(feature = "bitcoin_hashes")))] + #[cfg(all(not(feature = "std"), not(feature = "hashes")))] impl ::core::fmt::Debug for $thing { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { - write!(f, "") + write!(f, "") } } };