Merge rust-bitcoin/rust-secp256k1#563: change bitcoin-hashes feature gates to bitcoin_hashes

1d6a46eb6d change bitcoin-hashes feature gates to bitcoin_hashes (Andrew Poelstra)

Pull request description:

  This leaves `bitcoin-hashes` in place everywhere in the documentation, but changes it to `bitcoin_hashes` on the actual feature gates, to ensure that both flags work.

  It's unfortunately a bit hard to test this because the library will be self-consistent pretty-much no matter what we do ... the issue is if the user enables the wrong flag we want to make sure that all the APIs we intend to be visible are actually visible.

  Fixes #562.

ACKs for top commit:
  tcharding:
    ACK 1d6a46eb6d

Tree-SHA512: 1e060aeb2810ef1e23cf5c956023aca586550ba0287bbf7bc1108dc14091e17d7601aac3f057d0313fafd21351cdda1b08b4250f34ecde917be686d0b739e65a
This commit is contained in:
Andrew Poelstra 2022-12-09 20:38:43 +00:00
commit 4adbbce264
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
3 changed files with 15 additions and 15 deletions

View File

@ -31,7 +31,7 @@ use crate::Error::{self, InvalidPublicKey, InvalidPublicKeySum, InvalidSecretKey
use crate::{constants, from_hex, Scalar, Secp256k1, Signing, Verification}; use crate::{constants, from_hex, Scalar, Secp256k1, Signing, Verification};
#[cfg(feature = "global-context")] #[cfg(feature = "global-context")]
use crate::{ecdsa, Message, SECP256K1}; use crate::{ecdsa, Message, SECP256K1};
#[cfg(feature = "bitcoin-hashes")] #[cfg(feature = "bitcoin_hashes")]
use crate::{hashes, ThirtyTwoByteHash}; use crate::{hashes, ThirtyTwoByteHash};
/// Secret 256-bit key used as `x` in an ECDSA signature. /// Secret 256-bit key used as `x` in an ECDSA signature.
@ -284,7 +284,7 @@ impl SecretKey {
/// assert_eq!(sk1, sk2); /// assert_eq!(sk1, sk2);
/// # } /// # }
/// ``` /// ```
#[cfg(feature = "bitcoin-hashes")] #[cfg(feature = "bitcoin_hashes")]
#[cfg_attr(docsrs, doc(cfg(feature = "bitcoin-hashes")))] #[cfg_attr(docsrs, doc(cfg(feature = "bitcoin-hashes")))]
#[inline] #[inline]
pub fn from_hashed_data<H: ThirtyTwoByteHash + hashes::Hash>(data: &[u8]) -> Self { pub fn from_hashed_data<H: ThirtyTwoByteHash + hashes::Hash>(data: &[u8]) -> Self {
@ -383,7 +383,7 @@ impl SecretKey {
} }
} }
#[cfg(feature = "bitcoin-hashes")] #[cfg(feature = "bitcoin_hashes")]
impl<T: ThirtyTwoByteHash> From<T> for SecretKey { impl<T: ThirtyTwoByteHash> From<T> for SecretKey {
/// Converts a 32-byte hash directly to a secret key without error paths. /// Converts a 32-byte hash directly to a secret key without error paths.
fn from(t: T) -> SecretKey { fn from(t: T) -> SecretKey {

View File

@ -140,8 +140,8 @@
//! * `alloc` - use the `alloc` standard Rust library to provide heap allocations. //! * `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` - use `rand` library to provide random generator (e.g. to generate keys).
//! * `rand-std` - use `rand` library with its `std` feature enabled. (Implies `rand`.) //! * `rand-std` - use `rand` library with its `std` feature enabled. (Implies `rand`.)
//! * `bitcoin-hashes` - use the `bitcoin-hashes` library. //! * `bitcoin-hashes` - use the `bitcoin_hashes` library.
//! * `bitcoin-hashes-std` - use the `bitcoin-hashes` library with its `std` feature enabled (implies `bitcoin-hashes`). //! * `bitcoin-hashes-std` - use the `bitcoin_hashes` library with its `std` feature enabled (implies `bitcoin-hashes`).
//! * `recovery` - enable functions that can compute the public key from signature. //! * `recovery` - enable functions that can compute the public key from signature.
//! * `lowmemory` - optimize the library for low-memory environments. //! * `lowmemory` - optimize the library for low-memory environments.
//! * `global-context` - enable use of global secp256k1 context (implies `std`). //! * `global-context` - enable use of global secp256k1 context (implies `std`).
@ -183,7 +183,7 @@ use core::marker::PhantomData;
use core::ptr::NonNull; use core::ptr::NonNull;
use core::{fmt, mem, str}; use core::{fmt, mem, str};
#[cfg(feature = "bitcoin-hashes")] #[cfg(feature = "bitcoin_hashes")]
#[cfg_attr(docsrs, doc(cfg(feature = "bitcoin-hashes")))] #[cfg_attr(docsrs, doc(cfg(feature = "bitcoin-hashes")))]
pub use bitcoin_hashes as hashes; pub use bitcoin_hashes as hashes;
#[cfg(feature = "global-context")] #[cfg(feature = "global-context")]
@ -200,7 +200,7 @@ pub use serde;
pub use crate::context::*; pub use crate::context::*;
use crate::ffi::types::AlignedType; use crate::ffi::types::AlignedType;
use crate::ffi::CPtr; use crate::ffi::CPtr;
#[cfg(feature = "bitcoin-hashes")] #[cfg(feature = "bitcoin_hashes")]
use crate::hashes::Hash; use crate::hashes::Hash;
pub use crate::key::{PublicKey, SecretKey, *}; pub use crate::key::{PublicKey, SecretKey, *};
pub use crate::scalar::Scalar; pub use crate::scalar::Scalar;
@ -213,19 +213,19 @@ pub trait ThirtyTwoByteHash {
fn into_32(self) -> [u8; 32]; fn into_32(self) -> [u8; 32];
} }
#[cfg(feature = "bitcoin-hashes")] #[cfg(feature = "bitcoin_hashes")]
#[cfg_attr(docsrs, doc(cfg(feature = "bitcoin-hashes")))] #[cfg_attr(docsrs, doc(cfg(feature = "bitcoin-hashes")))]
impl ThirtyTwoByteHash for hashes::sha256::Hash { impl ThirtyTwoByteHash for hashes::sha256::Hash {
fn into_32(self) -> [u8; 32] { self.into_inner() } fn into_32(self) -> [u8; 32] { self.into_inner() }
} }
#[cfg(feature = "bitcoin-hashes")] #[cfg(feature = "bitcoin_hashes")]
#[cfg_attr(docsrs, doc(cfg(feature = "bitcoin-hashes")))] #[cfg_attr(docsrs, doc(cfg(feature = "bitcoin-hashes")))]
impl ThirtyTwoByteHash for hashes::sha256d::Hash { impl ThirtyTwoByteHash for hashes::sha256d::Hash {
fn into_32(self) -> [u8; 32] { self.into_inner() } fn into_32(self) -> [u8; 32] { self.into_inner() }
} }
#[cfg(feature = "bitcoin-hashes")] #[cfg(feature = "bitcoin_hashes")]
#[cfg_attr(docsrs, doc(cfg(feature = "bitcoin-hashes")))] #[cfg_attr(docsrs, doc(cfg(feature = "bitcoin-hashes")))]
impl<T: hashes::sha256t::Tag> ThirtyTwoByteHash for hashes::sha256t::Hash<T> { impl<T: hashes::sha256t::Tag> ThirtyTwoByteHash for hashes::sha256t::Hash<T> {
fn into_32(self) -> [u8; 32] { self.into_inner() } fn into_32(self) -> [u8; 32] { self.into_inner() }
@ -263,7 +263,7 @@ impl Message {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # #[cfg(feature = "bitcoin-hashes")] { /// # #[cfg(feature = "bitcoin_hashes")] {
/// use secp256k1::hashes::{sha256, Hash}; /// use secp256k1::hashes::{sha256, Hash};
/// use secp256k1::Message; /// use secp256k1::Message;
/// ///
@ -274,7 +274,7 @@ impl Message {
/// assert_eq!(m1, m2); /// assert_eq!(m1, m2);
/// # } /// # }
/// ``` /// ```
#[cfg(feature = "bitcoin-hashes")] #[cfg(feature = "bitcoin_hashes")]
#[cfg_attr(docsrs, doc(cfg(feature = "bitcoin-hashes")))] #[cfg_attr(docsrs, doc(cfg(feature = "bitcoin-hashes")))]
pub fn from_hashed_data<H: ThirtyTwoByteHash + hashes::Hash>(data: &[u8]) -> Self { pub fn from_hashed_data<H: ThirtyTwoByteHash + hashes::Hash>(data: &[u8]) -> Self {
<H as hashes::Hash>::hash(data).into() <H as hashes::Hash>::hash(data).into()
@ -1037,7 +1037,7 @@ mod tests {
assert!(SECP256K1.verify_ecdsa(&msg, &sig, &pk).is_ok()); assert!(SECP256K1.verify_ecdsa(&msg, &sig, &pk).is_ok());
} }
#[cfg(feature = "bitcoin-hashes")] #[cfg(feature = "bitcoin_hashes")]
#[test] #[test]
fn test_from_hash() { fn test_from_hash() {
use crate::hashes::{self, Hash}; use crate::hashes::{self, Hash};

View File

@ -45,7 +45,7 @@ macro_rules! impl_display_secret {
} }
} }
#[cfg(all(not(feature = "std"), feature = "bitcoin-hashes"))] #[cfg(all(not(feature = "std"), feature = "bitcoin_hashes"))]
impl ::core::fmt::Debug for $thing { impl ::core::fmt::Debug for $thing {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use crate::hashes::{sha256, Hash, HashEngine}; use crate::hashes::{sha256, Hash, HashEngine};
@ -63,7 +63,7 @@ macro_rules! impl_display_secret {
} }
} }
#[cfg(all(not(feature = "std"), not(feature = "bitcoin-hashes")))] #[cfg(all(not(feature = "std"), not(feature = "bitcoin_hashes")))]
impl ::core::fmt::Debug for $thing { impl ::core::fmt::Debug for $thing {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "<secret requires std or bitcoin_hashes feature to display>") write!(f, "<secret requires std or bitcoin_hashes feature to display>")