New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove the sha256t::Hash
type
#2717
Remove the sha256t::Hash
type
#2717
Conversation
sha256t::Hash
type
Pull Request Test Coverage Report for Build 8826416322Details
💛 - Coveralls |
1c84f5b
to
743b61e
Compare
In `bitcoin` we never use the `sha256t::Hash` type directly but only as an underlying generic type that holds the tagging logic. To get tagged hash types we currently use the `sha256t_hash_newtype` macro. Assuming other users implement tagged hashing as we do in `rust-bitcoin` then the `sha256t::Hash` type currently serves only as a type to implement `Tag::engine` on - but as long as there exists a way to get the pre-tagged engine then we do not actually need the type. If we assume all users will use a provided macro to define tagged hashes then we have two options. This PR implements the first option. 1. In the `NewTypeHash::engine` function return a pre-tagged `sha256::HashEngine`. 2. Have callers of the macro define a new engine type as well as a new hash type, then we can put the tagging logic in the `Default` implementation of the new engine. Remove the `sha256t::Hash` type, and the `Tag` trait. Modify the `sha256_hash_newtype` macro to match and just implement the tagging logic in the `engine` function. Add unit tests to make sure we correctly handle the forward/backward attribute. `rust-bitcoin` includes test already that verify this patch.
743b61e
to
2c73f7e
Compare
@@ -78,6 +78,7 @@ const UTXO_3: P2trUtxo = P2trUtxo { | |||
use std::collections::BTreeMap; | |||
use std::str::FromStr; | |||
|
|||
use bitcoin::hashes::Hash; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In 2c73f7e:
Can you add as _
here?
} | ||
|
||
impl_message_from_hash!(TapSighash); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In 2c73f7e:
Why does this go away?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a mistake, right there. I had a feeling something was wrong with the Message::from_digest
instead of Message::from
changes. And I knew you'd catch it in review. Sorry to lean on you like that, I've literally done various combinations of all these hashes
changes like 10 times over the last two weeks.
I pulled the concept in this out of #2708 and attempted to reduce the scope.
In
bitcoin
we never use thesha256t::Hash
type directly but only as an underlying generic type that holds the tagging logic. To get tagged hash types we currently use thesha256t_hash_newtype
macro.Assuming other users implement tagged hashing as we do in
rust-bitcoin
then thesha256t::Hash
type currently serves only as a type to implementTag::engine
on - but as long as there exists a way to get the pre-tagged engine then we do not actually need the type.If we assume all users will use a provided macro to define tagged hashes then we have two options. This PR implements the first option and #2719 demonstrates the second.
In the
NewTypeHash::engine
function return a pre-taggedsha256::HashEngine
.Have callers of the macro define a new engine type as well as a new hash type, then we can put the tagging logic in the
Default
implementation of the new engine.Remove the
sha256t::Hash
type, and theTag
trait. Modify thesha256_hash_newtype
macro to more closely mimichash_newtype!
and just implement the tagging logic in theengine
function.Add unit tests to make sure we correctly handle the forward/backward attribute.
rust-bitcoin
includes test already that verify this patch.