Replace ThirtyTwoByteHash
trait impl for more generic From
#211
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch replaces the
ThirtyTwoByteHash
trait with a more genericFrom
impl that allows us to construct a message from any 32-byte array.There is a companion PR for
bitcoin_hashes
that provides said impls which plays nicely together with this: rust-bitcoin/bitcoin_hashes#81Judging from the comment on the original
ThirtyTwoByteHash
trait, the idea of this trait was to make good use of the type system to prevent conversions that make semantically no sense.Hence, in an ideal world, the bytes going into a message should always come from a hash function.
I would argue that this is unnecessarily restrictive and the more general
From
impl is more useful and allows for type interactions that are more pleasant to use (see the updated examples).Also, in practice, we already allow users to construct a message from arbitrary bytes using the
from_slice
function. The downside of this function is that imposes a runtime error that in many cases "can never happen", yet we have to deal with in in the type system.