Skip to content

Commit 79155ed

Browse files
committed
Use hashes instead of bitcoin_hashes
Use the more terse `hashes` by way of the `package` field in the manifest. Allows us to remove the ugly feature alias "bitcoin-hashes" -> "bitcoin_hashes" and removes all the bother with the underscore. Why did we not think of this 2 years ago?
1 parent 2420933 commit 79155ed

File tree

8 files changed

+43
-43
lines changed

8 files changed

+43
-43
lines changed

Cargo.toml

+5-6
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ default = ["std"]
2121
std = ["alloc", "secp256k1-sys/std"]
2222
# allow use of Secp256k1::new and related API that requires an allocator
2323
alloc = ["secp256k1-sys/alloc"]
24-
bitcoin-hashes = ["bitcoin_hashes"] # Feature alias because of the underscore.
25-
bitcoin-hashes-std = ["std", "bitcoin_hashes", "bitcoin_hashes/std"]
24+
hashes-std = ["std", "hashes/std"]
2625
rand-std = ["std", "rand", "rand/std", "rand/std_rng"]
2726
recovery = ["secp256k1-sys/recovery"]
2827
lowmemory = ["secp256k1-sys/lowmemory"]
@@ -40,8 +39,8 @@ secp256k1-sys = { version = "0.8.1", default-features = false, path = "./secp256
4039
serde = { version = "1.0.103", default-features = false, optional = true }
4140

4241
# You likely only want to enable these if you explicitly do not want to use "std", otherwise enable
43-
# the respective -std feature e.g., bitcoin-hashes-std
44-
bitcoin_hashes = { version = "0.12", default-features = false, optional = true }
42+
# the respective -std feature e.g., hashes-std
43+
hashes = { package = "bitcoin_hashes", version = "0.12.0", default-features = false, optional = true }
4544
rand = { version = "0.8", default-features = false, optional = true }
4645

4746
[dev-dependencies]
@@ -57,11 +56,11 @@ getrandom = { version = "0.2", features = ["js"] }
5756

5857
[[example]]
5958
name = "sign_verify_recovery"
60-
required-features = ["recovery", "bitcoin-hashes-std"]
59+
required-features = ["recovery", "hashes-std"]
6160

6261
[[example]]
6362
name = "sign_verify"
64-
required-features = ["bitcoin-hashes-std"]
63+
required-features = ["hashes-std"]
6564

6665
[[example]]
6766
name = "generate_keys"

contrib/_test.sh

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -ex
44

5-
FEATURES="bitcoin-hashes global-context lowmemory rand recovery serde std alloc bitcoin-hashes-std rand-std"
5+
FEATURES="hashes global-context lowmemory rand recovery serde std alloc hashes-std rand-std"
66

77
cargo --version
88
rustc --version
@@ -59,16 +59,16 @@ if [ "$DO_FEATURE_MATRIX" = true ]; then
5959
fi
6060

6161
# Examples
62-
cargo run --locked --example sign_verify --features=bitcoin-hashes-std
63-
cargo run --locked --example sign_verify_recovery --features=recovery,bitcoin-hashes-std
62+
cargo run --locked --example sign_verify --features=hashes-std
63+
cargo run --locked --example sign_verify_recovery --features=recovery,hashes-std
6464
cargo run --locked --example generate_keys --features=rand-std
6565
fi
6666

6767
if [ "$DO_LINT" = true ]
6868
then
6969
cargo clippy --locked --all-features --all-targets -- -D warnings
70-
cargo clippy --locked --example sign_verify --features=bitcoin-hashes-std -- -D warnings
71-
cargo clippy --locked --example sign_verify_recovery --features=recovery,bitcoin-hashes-std -- -D warnings
70+
cargo clippy --locked --example sign_verify --features=hashes-std -- -D warnings
71+
cargo clippy --locked --example sign_verify_recovery --features=recovery,hashes-std -- -D warnings
7272
cargo clippy --locked --example generate_keys --features=rand-std -- -D warnings
7373
fi
7474

examples/sign_verify.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
extern crate bitcoin_hashes;
1+
extern crate hashes;
22
extern crate secp256k1;
33

4-
use bitcoin_hashes::{sha256, Hash};
4+
use hashes::{sha256, Hash};
55
use secp256k1::{ecdsa, Error, Message, PublicKey, Secp256k1, SecretKey, Signing, Verification};
66

77
fn verify<C: Verification>(

examples/sign_verify_recovery.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
extern crate bitcoin_hashes;
1+
extern crate hashes;
22
extern crate secp256k1;
33

4-
use bitcoin_hashes::{sha256, Hash};
4+
use hashes::{sha256, Hash};
55
use secp256k1::{ecdsa, Error, Message, PublicKey, Secp256k1, SecretKey, Signing, Verification};
66

77
fn recover<C: Verification>(

src/ecdh.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl AsRef<[u8]> for SharedSecret {
110110
///
111111
/// # Examples
112112
/// ```
113-
/// # #[cfg(all(feature = "bitcoin-hashes-std", feature = "rand-std"))] {
113+
/// # #[cfg(all(feature = "hashes-std", feature = "rand-std"))] {
114114
/// # use secp256k1::{ecdh, rand, Secp256k1, PublicKey, SecretKey};
115115
/// # use secp256k1::hashes::{Hash, sha512};
116116
///
@@ -225,9 +225,9 @@ mod tests {
225225

226226
#[test]
227227
#[cfg(not(secp256k1_fuzz))]
228-
#[cfg(all(feature = "bitcoin-hashes-std", feature = "rand-std"))]
229-
fn bitcoin_hashes_and_sys_generate_same_secret() {
230-
use bitcoin_hashes::{sha256, Hash, HashEngine};
228+
#[cfg(all(feature = "hashes-std", feature = "rand-std"))]
229+
fn hashes_and_sys_generate_same_secret() {
230+
use hashes::{sha256, Hash, HashEngine};
231231

232232
use crate::ecdh::shared_secret_point;
233233

src/key.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::Error::{self, InvalidPublicKey, InvalidPublicKeySum, InvalidSecretKey
1616
use crate::{constants, from_hex, schnorr, Message, Scalar, Secp256k1, Signing, Verification};
1717
#[cfg(feature = "global-context")]
1818
use crate::{ecdsa, SECP256K1};
19-
#[cfg(feature = "bitcoin_hashes")]
19+
#[cfg(feature = "hashes")]
2020
use crate::{hashes, ThirtyTwoByteHash};
2121

2222
/// Secret 256-bit key used as `x` in an ECDSA signature.
@@ -253,12 +253,12 @@ impl SecretKey {
253253

254254
/// Constructs a [`SecretKey`] by hashing `data` with hash algorithm `H`.
255255
///
256-
/// Requires the feature `bitcoin_hashes` to be enabled.
256+
/// Requires the feature `hashes` to be enabled.
257257
///
258258
/// # Examples
259259
///
260260
/// ```
261-
/// # #[cfg(feature="bitcoin_hashes")] {
261+
/// # #[cfg(feature="hashes")] {
262262
/// use secp256k1::hashes::{sha256, Hash};
263263
/// use secp256k1::SecretKey;
264264
///
@@ -269,7 +269,7 @@ impl SecretKey {
269269
/// assert_eq!(sk1, sk2);
270270
/// # }
271271
/// ```
272-
#[cfg(feature = "bitcoin_hashes")]
272+
#[cfg(feature = "hashes")]
273273
#[inline]
274274
pub fn from_hashed_data<H: ThirtyTwoByteHash + hashes::Hash>(data: &[u8]) -> Self {
275275
<H as hashes::Hash>::hash(data).into()
@@ -366,7 +366,7 @@ impl SecretKey {
366366
}
367367
}
368368

369-
#[cfg(feature = "bitcoin_hashes")]
369+
#[cfg(feature = "hashes")]
370370
impl<T: ThirtyTwoByteHash> From<T> for SecretKey {
371371
/// Converts a 32-byte hash directly to a secret key without error paths.
372372
fn from(t: T) -> SecretKey {

src/lib.rs

+17-16
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
//! trigger any assertion failures in the upstream library.
2929
//!
3030
//! ```rust
31-
//! # #[cfg(all(feature = "rand-std", feature = "bitcoin-hashes-std"))] {
31+
//! # #[cfg(all(feature = "rand-std", feature = "hashes-std"))] {
3232
//! use secp256k1::rand::rngs::OsRng;
3333
//! use secp256k1::{Secp256k1, Message};
3434
//! use secp256k1::hashes::sha256;
@@ -45,7 +45,7 @@
4545
//! If the "global-context" feature is enabled you have access to an alternate API.
4646
//!
4747
//! ```rust
48-
//! # #[cfg(all(feature = "global-context", feature = "bitcoin-hashes-std", feature = "rand-std"))] {
48+
//! # #[cfg(all(feature = "global-context", feature = "hashes-std", feature = "rand-std"))] {
4949
//! use secp256k1::{generate_keypair, Message};
5050
//! use secp256k1::hashes::sha256;
5151
//!
@@ -57,7 +57,7 @@
5757
//! # }
5858
//! ```
5959
//!
60-
//! The above code requires `rust-secp256k1` to be compiled with the `rand-std` and `bitcoin-hashes-std`
60+
//! The above code requires `rust-secp256k1` to be compiled with the `rand-std` and `hashes-std`
6161
//! feature enabled, to get access to [`generate_keypair`](struct.Secp256k1.html#method.generate_keypair)
6262
//! Alternately, keys and messages can be parsed from slices, like
6363
//!
@@ -69,7 +69,7 @@
6969
//! let secret_key = SecretKey::from_slice(&[0xcd; 32]).expect("32 bytes, within curve order");
7070
//! let public_key = PublicKey::from_secret_key(&secp, &secret_key);
7171
//! // This is unsafe unless the supplied byte slice is the output of a cryptographic hash function.
72-
//! // See the above example for how to use this library together with `bitcoin-hashes-std`.
72+
//! // See the above example for how to use this library together with `hashes-std`.
7373
//! let message = Message::from_slice(&[0xab; 32]).expect("32 bytes");
7474
//!
7575
//! let sig = secp.sign_ecdsa(&message, &secret_key);
@@ -127,8 +127,8 @@
127127
//! * `alloc` - use the `alloc` standard Rust library to provide heap allocations.
128128
//! * `rand` - use `rand` library to provide random generator (e.g. to generate keys).
129129
//! * `rand-std` - use `rand` library with its `std` feature enabled. (Implies `rand`.)
130-
//! * `bitcoin-hashes` - use the `bitcoin_hashes` library.
131-
//! * `bitcoin-hashes-std` - use the `bitcoin_hashes` library with its `std` feature enabled (implies `bitcoin-hashes`).
130+
//! * `hashes` - use the `hashes` library.
131+
//! * `hashes-std` - use the `hashes` library with its `std` feature enabled (implies `hashes`).
132132
//! * `recovery` - enable functions that can compute the public key from signature.
133133
//! * `lowmemory` - optimize the library for low-memory environments.
134134
//! * `global-context` - enable use of global secp256k1 context (implies `std`).
@@ -151,6 +151,9 @@ extern crate core;
151151
#[cfg(bench)]
152152
extern crate test;
153153

154+
#[cfg(feature = "hashes")]
155+
pub extern crate hashes;
156+
154157
#[macro_use]
155158
mod macros;
156159
#[macro_use]
@@ -170,8 +173,6 @@ use core::marker::PhantomData;
170173
use core::ptr::NonNull;
171174
use core::{fmt, mem, str};
172175

173-
#[cfg(feature = "bitcoin_hashes")]
174-
pub use bitcoin_hashes as hashes;
175176
#[cfg(feature = "global-context")]
176177
pub use context::global::SECP256K1;
177178
#[cfg(feature = "rand")]
@@ -183,7 +184,7 @@ pub use serde;
183184
pub use crate::context::*;
184185
use crate::ffi::types::AlignedType;
185186
use crate::ffi::CPtr;
186-
#[cfg(feature = "bitcoin_hashes")]
187+
#[cfg(feature = "hashes")]
187188
use crate::hashes::Hash;
188189
pub use crate::key::{PublicKey, SecretKey, *};
189190
pub use crate::scalar::Scalar;
@@ -196,17 +197,17 @@ pub trait ThirtyTwoByteHash {
196197
fn into_32(self) -> [u8; 32];
197198
}
198199

199-
#[cfg(feature = "bitcoin_hashes")]
200+
#[cfg(feature = "hashes")]
200201
impl ThirtyTwoByteHash for hashes::sha256::Hash {
201202
fn into_32(self) -> [u8; 32] { self.to_byte_array() }
202203
}
203204

204-
#[cfg(feature = "bitcoin_hashes")]
205+
#[cfg(feature = "hashes")]
205206
impl ThirtyTwoByteHash for hashes::sha256d::Hash {
206207
fn into_32(self) -> [u8; 32] { self.to_byte_array() }
207208
}
208209

209-
#[cfg(feature = "bitcoin_hashes")]
210+
#[cfg(feature = "hashes")]
210211
impl<T: hashes::sha256t::Tag> ThirtyTwoByteHash for hashes::sha256t::Hash<T> {
211212
fn into_32(self) -> [u8; 32] { self.to_byte_array() }
212213
}
@@ -238,12 +239,12 @@ impl Message {
238239

239240
/// Constructs a [`Message`] by hashing `data` with hash algorithm `H`.
240241
///
241-
/// Requires the feature `bitcoin-hashes` to be enabled.
242+
/// Requires the feature `hashes` to be enabled.
242243
///
243244
/// # Examples
244245
///
245246
/// ```
246-
/// # #[cfg(feature = "bitcoin_hashes")] {
247+
/// # #[cfg(feature = "hashes")] {
247248
/// use secp256k1::hashes::{sha256, Hash};
248249
/// use secp256k1::Message;
249250
///
@@ -254,7 +255,7 @@ impl Message {
254255
/// assert_eq!(m1, m2);
255256
/// # }
256257
/// ```
257-
#[cfg(feature = "bitcoin_hashes")]
258+
#[cfg(feature = "hashes")]
258259
pub fn from_hashed_data<H: ThirtyTwoByteHash + hashes::Hash>(data: &[u8]) -> Self {
259260
<H as hashes::Hash>::hash(data).into()
260261
}
@@ -1012,7 +1013,7 @@ mod tests {
10121013
assert!(SECP256K1.verify_ecdsa(&msg, &sig, &pk).is_ok());
10131014
}
10141015

1015-
#[cfg(feature = "bitcoin_hashes")]
1016+
#[cfg(feature = "hashes")]
10161017
#[test]
10171018
fn test_from_hash() {
10181019
use crate::hashes::{self, Hash};

src/secret.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ macro_rules! impl_display_secret {
3232
}
3333
}
3434

35-
#[cfg(all(not(feature = "std"), feature = "bitcoin_hashes"))]
35+
#[cfg(all(not(feature = "std"), feature = "hashes"))]
3636
impl ::core::fmt::Debug for $thing {
3737
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3838
use crate::hashes::{sha256, Hash, HashEngine};
@@ -50,10 +50,10 @@ macro_rules! impl_display_secret {
5050
}
5151
}
5252

53-
#[cfg(all(not(feature = "std"), not(feature = "bitcoin_hashes")))]
53+
#[cfg(all(not(feature = "std"), not(feature = "hashes")))]
5454
impl ::core::fmt::Debug for $thing {
5555
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
56-
write!(f, "<secret requires std or bitcoin_hashes feature to display>")
56+
write!(f, "<secret requires std or hashes feature to display>")
5757
}
5858
}
5959
};

0 commit comments

Comments
 (0)