Skip to content

Commit f724dc2

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 7058539 commit f724dc2

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", 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
@@ -3,7 +3,7 @@
33
set -ex
44

55
REPO_DIR=$(git rev-parse --show-toplevel)
6-
FEATURES="bitcoin-hashes global-context lowmemory rand recovery serde std alloc bitcoin-hashes-std rand-std"
6+
FEATURES="bitcoin global-context lowmemory rand recovery serde std alloc hashes-std rand-std"
77

88
cargo --version
99
rustc --version
@@ -62,16 +62,16 @@ if [ "$DO_FEATURE_MATRIX" = true ]; then
6262
fi
6363

6464
# Examples
65-
cargo run --locked --example sign_verify --features=bitcoin-hashes-std
66-
cargo run --locked --example sign_verify_recovery --features=recovery,bitcoin-hashes-std
65+
cargo run --locked --example sign_verify --features=hashes-std
66+
cargo run --locked --example sign_verify_recovery --features=recovery,hashes-std
6767
cargo run --locked --example generate_keys --features=rand-std
6868
fi
6969

7070
if [ "$DO_LINT" = true ]
7171
then
7272
cargo clippy --locked --all-features --all-targets -- -D warnings
73-
cargo clippy --locked --example sign_verify --features=bitcoin-hashes-std -- -D warnings
74-
cargo clippy --locked --example sign_verify_recovery --features=recovery,bitcoin-hashes-std -- -D warnings
73+
cargo clippy --locked --example sign_verify --features=hashes-std -- -D warnings
74+
cargo clippy --locked --example sign_verify_recovery --features=recovery,hashes-std -- -D warnings
7575
cargo clippy --locked --example generate_keys --features=rand-std -- -D warnings
7676
fi
7777

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
@@ -18,7 +18,7 @@ use crate::SECP256K1;
1818
use crate::{
1919
constants, ecdsa, from_hex, schnorr, Message, Scalar, Secp256k1, Signing, Verification,
2020
};
21-
#[cfg(feature = "bitcoin_hashes")]
21+
#[cfg(feature = "hashes")]
2222
use crate::{hashes, ThirtyTwoByteHash};
2323

2424
/// Secret 256-bit key used as `x` in an ECDSA signature.
@@ -255,12 +255,12 @@ impl SecretKey {
255255

256256
/// Constructs a [`SecretKey`] by hashing `data` with hash algorithm `H`.
257257
///
258-
/// Requires the feature `bitcoin_hashes` to be enabled.
258+
/// Requires the feature `hashes` to be enabled.
259259
///
260260
/// # Examples
261261
///
262262
/// ```
263-
/// # #[cfg(feature="bitcoin_hashes")] {
263+
/// # #[cfg(feature="hashes")] {
264264
/// use secp256k1::hashes::{sha256, Hash};
265265
/// use secp256k1::SecretKey;
266266
///
@@ -271,7 +271,7 @@ impl SecretKey {
271271
/// assert_eq!(sk1, sk2);
272272
/// # }
273273
/// ```
274-
#[cfg(feature = "bitcoin_hashes")]
274+
#[cfg(feature = "hashes")]
275275
#[inline]
276276
pub fn from_hashed_data<H: ThirtyTwoByteHash + hashes::Hash>(data: &[u8]) -> Self {
277277
<H as hashes::Hash>::hash(data).into()
@@ -368,7 +368,7 @@ impl SecretKey {
368368
}
369369
}
370370

371-
#[cfg(feature = "bitcoin_hashes")]
371+
#[cfg(feature = "hashes")]
372372
impl<T: ThirtyTwoByteHash> From<T> for SecretKey {
373373
/// Converts a 32-byte hash directly to a secret key without error paths.
374374
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_digest_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
}
@@ -268,12 +269,12 @@ impl Message {
268269

269270
/// Constructs a [`Message`] by hashing `data` with hash algorithm `H`.
270271
///
271-
/// Requires the feature `bitcoin-hashes` to be enabled.
272+
/// Requires the feature `hashes` to be enabled.
272273
///
273274
/// # Examples
274275
///
275276
/// ```
276-
/// # #[cfg(feature = "bitcoin_hashes")] {
277+
/// # #[cfg(feature = "hashes")] {
277278
/// use secp256k1::hashes::{sha256, Hash};
278279
/// use secp256k1::Message;
279280
///
@@ -284,7 +285,7 @@ impl Message {
284285
/// assert_eq!(m1, m2);
285286
/// # }
286287
/// ```
287-
#[cfg(feature = "bitcoin_hashes")]
288+
#[cfg(feature = "hashes")]
288289
pub fn from_hashed_data<H: ThirtyTwoByteHash + hashes::Hash>(data: &[u8]) -> Self {
289290
<H as hashes::Hash>::hash(data).into()
290291
}
@@ -1042,7 +1043,7 @@ mod tests {
10421043
assert!(SECP256K1.verify_ecdsa(&msg, &sig, &pk).is_ok());
10431044
}
10441045

1045-
#[cfg(feature = "bitcoin_hashes")]
1046+
#[cfg(feature = "hashes")]
10461047
#[test]
10471048
fn test_from_hash() {
10481049
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)