Merge rust-bitcoin/rust-secp256k1#335: Implement `Hash` for `schnorrsig::Signature`

75b49efb3d Implement `Hash` for all array newtypes (elsirion)

Pull request description:

  I pondered putting the impl into the array type macro together with `(Partial)Eq`, but that would have meant removing other implementations and potentially implementing it for types where it is not wanted. The drawback of the separate impl is that it is more disconnected from the `(Partial)Eq` impl and could theoretically diverge (although unlikely in case of such a simple type) which would break the trait's contract.

ACKs for top commit:
  apoelstra:
    ACK 75b49efb3d

Tree-SHA512: 44d1bebdd3437dfd86de8b475f12097c4a2f872905c822a9cde624089fdc20f68f59a7734fdcc6f3a17ed233f70f63258dfd204ca269d2baf8002ffc325ddc87
This commit is contained in:
Andrew Poelstra 2021-11-05 14:29:44 +00:00
commit 96d2242f6a
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
2 changed files with 7 additions and 19 deletions

View File

@ -36,7 +36,7 @@ pub mod types;
#[cfg(feature = "recovery")]
pub mod recovery;
use core::{hash, slice, ptr};
use core::{slice, ptr};
use types::*;
/// Flag for context to enable no precomputation
@ -133,12 +133,6 @@ impl PublicKey {
}
}
impl hash::Hash for PublicKey {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
state.write(&self.0)
}
}
/// Library-internal representation of a Secp256k1 signature
#[repr(C)]
pub struct Signature([c_uchar; 64]);
@ -210,12 +204,6 @@ impl XOnlyPublicKey {
}
}
impl hash::Hash for XOnlyPublicKey {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
state.write(&self.0)
}
}
#[repr(C)]
pub struct KeyPair([c_uchar; 96]);
impl_array_newtype!(KeyPair, c_uchar, 96);
@ -251,12 +239,6 @@ impl KeyPair {
}
}
impl hash::Hash for KeyPair {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
state.write(&self.0)
}
}
extern "C" {
/// Default ECDH hash function
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_4_1_ecdh_hash_function_default")]

View File

@ -61,6 +61,12 @@ macro_rules! impl_array_newtype {
impl Eq for $thing {}
impl ::core::hash::Hash for $thing {
fn hash<H: ::core::hash::Hasher>(&self, state: &mut H) {
(&self[..]).hash(state)
}
}
impl PartialOrd for $thing {
#[inline]
fn partial_cmp(&self, other: &$thing) -> Option<::core::cmp::Ordering> {