3131//! # #[cfg(all(feature = "rand-std", feature = "hashes-std"))] {
3232//! use secp256k1::rand::rngs::OsRng;
3333//! use secp256k1::{Secp256k1, Message};
34- //! use secp256k1::hashes::sha256;
34+ //! use secp256k1::hashes::{ sha256, Hash} ;
3535//!
3636//! let secp = Secp256k1::new();
3737//! let (secret_key, public_key) = secp.generate_keypair(&mut OsRng);
38- //! let message = Message::from_hashed_data::<sha256::Hash>("Hello World!".as_bytes());
38+ //! let digest = sha256::Hash::hash("Hello World!".as_bytes());
39+ //! let message = Message::from_digest(digest.to_byte_array());
3940//!
4041//! let sig = secp.sign_ecdsa(&message, &secret_key);
4142//! assert!(secp.verify_ecdsa(&message, &sig, &public_key).is_ok());
4748//! ```rust
4849//! # #[cfg(all(feature = "global-context", feature = "hashes-std", feature = "rand-std"))] {
4950//! use secp256k1::{generate_keypair, Message};
50- //! use secp256k1::hashes::sha256;
51+ //! use secp256k1::hashes::{ sha256, Hash} ;
5152//!
5253//! let (secret_key, public_key) = generate_keypair(&mut rand::thread_rng());
53- //! let message = Message::from_hashed_data::<sha256::Hash>("Hello World!".as_bytes());
54+ //! let digest = sha256::Hash::hash("Hello World!".as_bytes());
55+ //! let message = Message::from_digest(digest.to_byte_array());
5456//!
5557//! let sig = secret_key.sign_ecdsa(message);
5658//! assert!(sig.verify(&message, &public_key).is_ok());
@@ -176,8 +178,6 @@ use core::{fmt, mem, str};
176178
177179#[ cfg( all( feature = "global-context" , feature = "std" ) ) ]
178180pub use context:: global:: { self , SECP256K1 } ;
179- #[ cfg( feature = "hashes" ) ]
180- use hashes:: Hash ;
181181#[ cfg( feature = "rand" ) ]
182182pub use rand;
183183pub use secp256k1_sys as ffi;
@@ -198,34 +198,23 @@ pub use crate::scalar::Scalar;
198198/// Trait describing something that promises to be a 32-byte random number; in particular,
199199/// it has negligible probability of being zero or overflowing the group order. Such objects
200200/// may be converted to `Message`s without any error paths.
201+ #[ deprecated(
202+ since = "0.29.0" ,
203+ note = "Please see v0.29.0 rust-secp256k1/CHANGELOG.md for suggestion"
204+ ) ]
201205pub trait ThirtyTwoByteHash {
202206 /// Converts the object into a 32-byte array
203207 fn into_32 ( self ) -> [ u8 ; 32 ] ;
204208}
205209
206- #[ cfg( feature = "hashes" ) ]
207- impl ThirtyTwoByteHash for hashes:: sha256:: Hash {
208- fn into_32 ( self ) -> [ u8 ; 32 ] { self . to_byte_array ( ) }
209- }
210-
211- #[ cfg( feature = "hashes" ) ]
212- impl ThirtyTwoByteHash for hashes:: sha256d:: Hash {
213- fn into_32 ( self ) -> [ u8 ; 32 ] { self . to_byte_array ( ) }
214- }
215-
216- #[ cfg( feature = "hashes" ) ]
217- impl < T : hashes:: sha256t:: Tag > ThirtyTwoByteHash for hashes:: sha256t:: Hash < T > {
218- fn into_32 ( self ) -> [ u8 ; 32 ] { self . to_byte_array ( ) }
219- }
220-
221210/// A (hashed) message input to an ECDSA signature.
222211#[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
223212pub struct Message ( [ u8 ; constants:: MESSAGE_SIZE ] ) ;
224213impl_array_newtype ! ( Message , u8 , constants:: MESSAGE_SIZE ) ;
225214impl_pretty_debug ! ( Message ) ;
226215
227216impl Message {
228- /// **If you just want to sign an arbitrary message use `Message::from_hashed_data` instead.**
217+ /// Creates a [`Message`] from a 32 byte slice `digest`.
229218 ///
230219 /// Converts a `MESSAGE_SIZE`-byte slice to a message object. **WARNING:** the slice has to be a
231220 /// cryptographically secure hash of the actual message that's going to be signed. Otherwise
@@ -239,8 +228,6 @@ impl Message {
239228
240229 /// Creates a [`Message`] from a `digest`.
241230 ///
242- /// **If you just want to sign an arbitrary message use `Message::from_hashed_data` instead.**
243- ///
244231 /// The `digest` array has to be a cryptographically secure hash of the actual message that's
245232 /// going to be signed. Otherwise the result of signing isn't a [secure signature].
246233 ///
@@ -250,8 +237,6 @@ impl Message {
250237
251238 /// Creates a [`Message`] from a 32 byte slice `digest`.
252239 ///
253- /// **If you just want to sign an arbitrary message use `Message::from_hashed_data` instead.**
254- ///
255240 /// The slice has to be 32 bytes long and be a cryptographically secure hash of the actual
256241 /// message that's going to be signed. Otherwise the result of signing isn't a [secure
257242 /// signature].
@@ -272,31 +257,9 @@ impl Message {
272257 _ => Err ( Error :: InvalidMessage ) ,
273258 }
274259 }
275-
276- /// Constructs a [`Message`] by hashing `data` with hash algorithm `H`.
277- ///
278- /// Requires the feature `hashes` to be enabled.
279- ///
280- /// # Examples
281- ///
282- /// ```
283- /// # #[cfg(feature = "hashes")] {
284- /// use secp256k1::hashes::{sha256, Hash};
285- /// use secp256k1::Message;
286- ///
287- /// let m1 = Message::from_hashed_data::<sha256::Hash>("Hello world!".as_bytes());
288- /// // is equivalent to
289- /// let m2 = Message::from(sha256::Hash::hash("Hello world!".as_bytes()));
290- ///
291- /// assert_eq!(m1, m2);
292- /// # }
293- /// ```
294- #[ cfg( feature = "hashes" ) ]
295- pub fn from_hashed_data < H : ThirtyTwoByteHash + hashes:: Hash > ( data : & [ u8 ] ) -> Self {
296- <H as hashes:: Hash >:: hash ( data) . into ( )
297- }
298260}
299261
262+ #[ allow( deprecated) ]
300263impl < T : ThirtyTwoByteHash > From < T > for Message {
301264 /// Converts a 32-byte hash directly to a message without error paths.
302265 fn from ( t : T ) -> Message { Message ( t. into_32 ( ) ) }
@@ -1043,24 +1006,6 @@ mod tests {
10431006 let sig = SECP256K1 . sign_ecdsa ( & msg, & sk) ;
10441007 assert ! ( SECP256K1 . verify_ecdsa( & msg, & sig, & pk) . is_ok( ) ) ;
10451008 }
1046-
1047- #[ cfg( feature = "hashes" ) ]
1048- #[ test]
1049- fn test_from_hash ( ) {
1050- use hashes:: { sha256, sha256d, Hash } ;
1051-
1052- let test_bytes = "Hello world!" . as_bytes ( ) ;
1053-
1054- let hash = sha256:: Hash :: hash ( test_bytes) ;
1055- let msg = Message :: from ( hash) ;
1056- assert_eq ! ( msg. 0 , hash. to_byte_array( ) ) ;
1057- assert_eq ! ( msg, Message :: from_hashed_data:: <hashes:: sha256:: Hash >( test_bytes) ) ;
1058-
1059- let hash = sha256d:: Hash :: hash ( test_bytes) ;
1060- let msg = Message :: from ( hash) ;
1061- assert_eq ! ( msg. 0 , hash. to_byte_array( ) ) ;
1062- assert_eq ! ( msg, Message :: from_hashed_data:: <hashes:: sha256d:: Hash >( test_bytes) ) ;
1063- }
10641009}
10651010
10661011#[ cfg( bench) ]
0 commit comments