-
Notifications
You must be signed in to change notification settings - Fork 305
Manually implement PartialEq, Eq, and Hash for PublicKey
#506
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
Manually implement PartialEq, Eq, and Hash for PublicKey
#506
Conversation
|
Patch 1 looks like it removes the I don't understand though what this has to do with Patch 2, which (correctly) changes the Finally, the current behavior of |
You are right, not sure what I was thinking yesterday. I'll split the first patch off into its own PR. |
20d0381 to
587e838
Compare
PartialEq, Eq, and Hash for PublicKey
`PartialEq` and `Eq` should agree with `PartialOrd` and `Ord` but we are deriving `PartialEq`/`Eq` and doing a custom implementation of `PartialOrd` and `Ord` (that calls down to ffi functions). If two keys are equal their hashes should be equal so, we should add a custom implementation of `Hash` also. In order to guarantee the digest will be the same across library versions first serialize the key before hashing it. Add custom implementation of `PartialEq`, `Eq`, and `Hash` when not fuzzing. Please note, this is for the main `PublicKey` type, the patch does not effect the `ffi::PublicKey`, nor do we call methods on the `ffi::PublicKey`.
587e838 to
5ccf0c8
Compare
apoelstra
left a comment
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.
ACK 5ccf0c8
|
I'm gonna go ahead and merge this. If people need high-performance comparisons it's not too difficult to work around this and bypass our |
…, `Eq`, and `Hash` for `PublicKey`
5ccf0c8db7cd63ab80ff9388565e258d4faec4c6 Manually implement PartialEq, Eq, and Hash for PublicKey (Tobin C. Harding)
Pull request description:
`PartialEq` and `Eq` should agree with `PartialOrd` and `Ord` but we are deriving `PartialEq`/`Eq` and doing a custom implementation of `PartialOrd` and `Ord` (that calls down to ffi functions).
If two keys are equal their hashes should be equal so, we should add a custom implementation of `Hash` also. In order to guarantee the digest will be the same across library versions first serialize the key before hashing it.
Add custom implementation of `PartialEq`, `Eq`, and `Hash` when not fuzzing.
Please note, this is for the main `PublicKey` type, the patch does not effect the `ffi::PublicKey`, nor do we call methods on the `ffi::PublicKey`.
EDIT: Please note the comment below by apoelstra about the possible performance hit introduced by this PR.
ACKs for top commit:
apoelstra:
ACK 5ccf0c8db7cd63ab80ff9388565e258d4faec4c6
Tree-SHA512: 1464308238411d259bb0493dc1eca775ec235036eef10b91f70ef17816174f452d5911ecae3b40434b71f9866be1db54d69e8ed9475a4f2801c07a800aead2b2
…, `Eq`, and `Hash` for `PublicKey`
5ccf0c8db7cd63ab80ff9388565e258d4faec4c6 Manually implement PartialEq, Eq, and Hash for PublicKey (Tobin C. Harding)
Pull request description:
`PartialEq` and `Eq` should agree with `PartialOrd` and `Ord` but we are deriving `PartialEq`/`Eq` and doing a custom implementation of `PartialOrd` and `Ord` (that calls down to ffi functions).
If two keys are equal their hashes should be equal so, we should add a custom implementation of `Hash` also. In order to guarantee the digest will be the same across library versions first serialize the key before hashing it.
Add custom implementation of `PartialEq`, `Eq`, and `Hash` when not fuzzing.
Please note, this is for the main `PublicKey` type, the patch does not effect the `ffi::PublicKey`, nor do we call methods on the `ffi::PublicKey`.
EDIT: Please note the comment below by apoelstra about the possible performance hit introduced by this PR.
ACKs for top commit:
apoelstra:
ACK 5ccf0c8db7cd63ab80ff9388565e258d4faec4c6
Tree-SHA512: 1464308238411d259bb0493dc1eca775ec235036eef10b91f70ef17816174f452d5911ecae3b40434b71f9866be1db54d69e8ed9475a4f2801c07a800aead2b2
PartialEqandEqshould agree withPartialOrdandOrdbut we are derivingPartialEq/Eqand doing a custom implementation ofPartialOrdandOrd(that calls down to ffi functions).If two keys are equal their hashes should be equal so, we should add a custom implementation of
Hashalso. In order to guarantee the digest will be the same across library versions first serialize the key before hashing it.Add custom implementation of
PartialEq,Eq, andHashwhen not fuzzing.Please note, this is for the main
PublicKeytype, the patch does not effect theffi::PublicKey, nor do we call methods on theffi::PublicKey.EDIT: Please note the comment below by apoelstra about the possible performance hit introduced by this PR.