28
28
//! trigger any assertion failures in the upstream library.
29
29
//!
30
30
//! ```rust
31
- //! # #[cfg(all(feature = "rand-std", feature = "bitcoin- hashes-std"))] {
31
+ //! # #[cfg(all(feature = "rand-std", feature = "hashes-std"))] {
32
32
//! use secp256k1::rand::rngs::OsRng;
33
33
//! use secp256k1::{Secp256k1, Message};
34
34
//! use secp256k1::hashes::sha256;
45
45
//! If the "global-context" feature is enabled you have access to an alternate API.
46
46
//!
47
47
//! ```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"))] {
49
49
//! use secp256k1::{generate_keypair, Message};
50
50
//! use secp256k1::hashes::sha256;
51
51
//!
57
57
//! # }
58
58
//! ```
59
59
//!
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`
61
61
//! feature enabled, to get access to [`generate_keypair`](struct.Secp256k1.html#method.generate_keypair)
62
62
//! Alternately, keys and messages can be parsed from slices, like
63
63
//!
69
69
//! let secret_key = SecretKey::from_slice(&[0xcd; 32]).expect("32 bytes, within curve order");
70
70
//! let public_key = PublicKey::from_secret_key(&secp, &secret_key);
71
71
//! // 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`.
73
73
//! let message = Message::from_digest_slice(&[0xab; 32]).expect("32 bytes");
74
74
//!
75
75
//! let sig = secp.sign_ecdsa(&message, &secret_key);
127
127
//! * `alloc` - use the `alloc` standard Rust library to provide heap allocations.
128
128
//! * `rand` - use `rand` library to provide random generator (e.g. to generate keys).
129
129
//! * `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`).
132
132
//! * `recovery` - enable functions that can compute the public key from signature.
133
133
//! * `lowmemory` - optimize the library for low-memory environments.
134
134
//! * `global-context` - enable use of global secp256k1 context (implies `std`).
@@ -151,6 +151,9 @@ extern crate core;
151
151
#[ cfg( bench) ]
152
152
extern crate test;
153
153
154
+ #[ cfg( feature = "hashes" ) ]
155
+ pub extern crate hashes;
156
+
154
157
#[ macro_use]
155
158
mod macros;
156
159
#[ macro_use]
@@ -170,10 +173,10 @@ use core::marker::PhantomData;
170
173
use core:: ptr:: NonNull ;
171
174
use core:: { fmt, mem, str} ;
172
175
173
- #[ cfg( feature = "bitcoin_hashes" ) ]
174
- pub use bitcoin_hashes as hashes;
175
176
#[ cfg( feature = "global-context" ) ]
176
177
pub use context:: global:: SECP256K1 ;
178
+ #[ cfg( feature = "hashes" ) ]
179
+ use hashes:: Hash ;
177
180
#[ cfg( feature = "rand" ) ]
178
181
pub use rand;
179
182
pub use secp256k1_sys as ffi;
@@ -183,8 +186,6 @@ pub use serde;
183
186
pub use crate :: context:: * ;
184
187
use crate :: ffi:: types:: AlignedType ;
185
188
use crate :: ffi:: CPtr ;
186
- #[ cfg( feature = "bitcoin_hashes" ) ]
187
- use crate :: hashes:: Hash ;
188
189
pub use crate :: key:: { PublicKey , SecretKey , * } ;
189
190
pub use crate :: scalar:: Scalar ;
190
191
@@ -196,17 +197,17 @@ pub trait ThirtyTwoByteHash {
196
197
fn into_32 ( self ) -> [ u8 ; 32 ] ;
197
198
}
198
199
199
- #[ cfg( feature = "bitcoin_hashes " ) ]
200
+ #[ cfg( feature = "hashes " ) ]
200
201
impl ThirtyTwoByteHash for hashes:: sha256:: Hash {
201
202
fn into_32 ( self ) -> [ u8 ; 32 ] { self . to_byte_array ( ) }
202
203
}
203
204
204
- #[ cfg( feature = "bitcoin_hashes " ) ]
205
+ #[ cfg( feature = "hashes " ) ]
205
206
impl ThirtyTwoByteHash for hashes:: sha256d:: Hash {
206
207
fn into_32 ( self ) -> [ u8 ; 32 ] { self . to_byte_array ( ) }
207
208
}
208
209
209
- #[ cfg( feature = "bitcoin_hashes " ) ]
210
+ #[ cfg( feature = "hashes " ) ]
210
211
impl < T : hashes:: sha256t:: Tag > ThirtyTwoByteHash for hashes:: sha256t:: Hash < T > {
211
212
fn into_32 ( self ) -> [ u8 ; 32 ] { self . to_byte_array ( ) }
212
213
}
@@ -268,12 +269,12 @@ impl Message {
268
269
269
270
/// Constructs a [`Message`] by hashing `data` with hash algorithm `H`.
270
271
///
271
- /// Requires the feature `bitcoin- hashes` to be enabled.
272
+ /// Requires the feature `hashes` to be enabled.
272
273
///
273
274
/// # Examples
274
275
///
275
276
/// ```
276
- /// # #[cfg(feature = "bitcoin_hashes ")] {
277
+ /// # #[cfg(feature = "hashes ")] {
277
278
/// use secp256k1::hashes::{sha256, Hash};
278
279
/// use secp256k1::Message;
279
280
///
@@ -284,7 +285,7 @@ impl Message {
284
285
/// assert_eq!(m1, m2);
285
286
/// # }
286
287
/// ```
287
- #[ cfg( feature = "bitcoin_hashes " ) ]
288
+ #[ cfg( feature = "hashes " ) ]
288
289
pub fn from_hashed_data < H : ThirtyTwoByteHash + hashes:: Hash > ( data : & [ u8 ] ) -> Self {
289
290
<H as hashes:: Hash >:: hash ( data) . into ( )
290
291
}
@@ -1042,19 +1043,19 @@ mod tests {
1042
1043
assert ! ( SECP256K1 . verify_ecdsa( & msg, & sig, & pk) . is_ok( ) ) ;
1043
1044
}
1044
1045
1045
- #[ cfg( feature = "bitcoin_hashes " ) ]
1046
+ #[ cfg( feature = "hashes " ) ]
1046
1047
#[ test]
1047
1048
fn test_from_hash ( ) {
1048
- use crate :: hashes:: { self , Hash } ;
1049
+ use hashes:: { sha256 , sha256d , Hash } ;
1049
1050
1050
1051
let test_bytes = "Hello world!" . as_bytes ( ) ;
1051
1052
1052
- let hash = hashes :: sha256:: Hash :: hash ( test_bytes) ;
1053
+ let hash = sha256:: Hash :: hash ( test_bytes) ;
1053
1054
let msg = Message :: from ( hash) ;
1054
1055
assert_eq ! ( msg. 0 , hash. to_byte_array( ) ) ;
1055
1056
assert_eq ! ( msg, Message :: from_hashed_data:: <hashes:: sha256:: Hash >( test_bytes) ) ;
1056
1057
1057
- let hash = hashes :: sha256d:: Hash :: hash ( test_bytes) ;
1058
+ let hash = sha256d:: Hash :: hash ( test_bytes) ;
1058
1059
let msg = Message :: from ( hash) ;
1059
1060
assert_eq ! ( msg. 0 , hash. to_byte_array( ) ) ;
1060
1061
assert_eq ! ( msg, Message :: from_hashed_data:: <hashes:: sha256d:: Hash >( test_bytes) ) ;
0 commit comments