diff --git a/bitcoin/src/taproot/mod.rs b/bitcoin/src/taproot/mod.rs index 50ea6c257..d9842ec28 100644 --- a/bitcoin/src/taproot/mod.rs +++ b/bitcoin/src/taproot/mod.rs @@ -1564,7 +1564,6 @@ mod sealed { #[cfg(test)] mod test { use hashes::sha256; - use hashes::sha256t::Tag; use hex::{DisplayHex, FromHex}; use secp256k1::VerifyOnly; @@ -1590,12 +1589,12 @@ mod test { #[test] fn midstates() { - use sha256t::Hash; + use sha256t::{Hash, Tag}; // test that engine creation roundtrips - assert_eq!(tag_engine("TapLeaf").midstate(), TapLeafTag::engine().midstate()); - assert_eq!(tag_engine("TapBranch").midstate(), TapBranchTag::engine().midstate()); - assert_eq!(tag_engine("TapTweak").midstate(), TapTweakTag::engine().midstate()); - assert_eq!(tag_engine("TapSighash").midstate(), TapSighashTag::engine().midstate()); + assert_eq!(tag_engine("TapLeaf").midstate().unwrap(), TapLeafTag::MIDSTATE); + assert_eq!(tag_engine("TapBranch").midstate().unwrap(), TapBranchTag::MIDSTATE); + assert_eq!(tag_engine("TapTweak").midstate().unwrap(), TapTweakTag::MIDSTATE); + assert_eq!(tag_engine("TapSighash").midstate().unwrap(), TapSighashTag::MIDSTATE); // check that hash creation is the same as building into the same engine fn empty_hash(tag_name: &str) -> [u8; 32] { @@ -1618,19 +1617,19 @@ mod test { // CHashWriter writer = HasherTapLeaf; // writer.GetSHA256().GetHex() assert_eq!( - Hash::::from_engine(TapLeafTag::engine()).to_string(), + Hash::::from_engine(Hash::::engine()).to_string(), "5212c288a377d1f8164962a5a13429f9ba6a7b84e59776a52c6637df2106facb" ); assert_eq!( - Hash::::from_engine(TapBranchTag::engine()).to_string(), + Hash::::from_engine(Hash::::engine()).to_string(), "53c373ec4d6f3c53c1f5fb2ff506dcefe1a0ed74874f93fa93c8214cbe9ffddf" ); assert_eq!( - Hash::::from_engine(TapTweakTag::engine()).to_string(), + Hash::::from_engine(Hash::::engine()).to_string(), "8aa4229474ab0100b2d6f0687f031d1fc9d8eef92a042ad97d279bff456b15e4" ); assert_eq!( - Hash::::from_engine(TapSighashTag::engine()).to_string(), + Hash::::from_engine(Hash::::engine()).to_string(), "dabc11914abcd8072900042a2681e52f8dba99ce82e224f97b5fdb7cd4b9c803" ); diff --git a/hashes/src/sha256t/mod.rs b/hashes/src/sha256t/mod.rs index 4a4ce84ee..cb91f6ab0 100644 --- a/hashes/src/sha256t/mod.rs +++ b/hashes/src/sha256t/mod.rs @@ -13,11 +13,6 @@ type HashEngine = sha256::HashEngine; pub trait Tag { /// The [`Midstate`] after pre-tagging the hash engine. const MIDSTATE: sha256::Midstate; - - /// Returns a hash engine that is pre-tagged and is ready to be used for the data. - fn engine() -> sha256::HashEngine { - sha256::HashEngine::from_midstate(Self::MIDSTATE) - } } /// Output of the SHA256t hash function. @@ -65,7 +60,9 @@ where pub fn from_engine(e: HashEngine) -> Hash { from_engine(e) } /// Constructs a new engine. - pub fn engine() -> HashEngine { T::engine() } + pub fn engine() -> HashEngine { + sha256::HashEngine::from_midstate(T::MIDSTATE) + } /// Hashes some bytes. #[allow(clippy::self_named_constructors)] // Hash is a noun and a verb.