Skip to content

Commit 3367b0a

Browse files
Merge rust-bitcoin/rust-secp256k1#335: Implement Hash for schnorrsig::Signature
75b49efb3d10c307631e6005c5f1e7bf233ecfc6 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 75b49efb3d10c307631e6005c5f1e7bf233ecfc6 Tree-SHA512: 44d1bebdd3437dfd86de8b475f12097c4a2f872905c822a9cde624089fdc20f68f59a7734fdcc6f3a17ed233f70f63258dfd204ca269d2baf8002ffc325ddc87
2 parents 53b2a9c + 7a3ed77 commit 3367b0a

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-19
lines changed

secp256k1-sys/src/lib.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub mod types;
3636
#[cfg(feature = "recovery")]
3737
pub mod recovery;
3838

39-
use core::{hash, slice, ptr};
39+
use core::{slice, ptr};
4040
use types::*;
4141

4242
/// Flag for context to enable no precomputation
@@ -133,12 +133,6 @@ impl PublicKey {
133133
}
134134
}
135135

136-
impl hash::Hash for PublicKey {
137-
fn hash<H: hash::Hasher>(&self, state: &mut H) {
138-
state.write(&self.0)
139-
}
140-
}
141-
142136
/// Library-internal representation of a Secp256k1 signature
143137
#[repr(C)]
144138
pub struct Signature([c_uchar; 64]);
@@ -210,12 +204,6 @@ impl XOnlyPublicKey {
210204
}
211205
}
212206

213-
impl hash::Hash for XOnlyPublicKey {
214-
fn hash<H: hash::Hasher>(&self, state: &mut H) {
215-
state.write(&self.0)
216-
}
217-
}
218-
219207
#[repr(C)]
220208
pub struct KeyPair([c_uchar; 96]);
221209
impl_array_newtype!(KeyPair, c_uchar, 96);
@@ -251,12 +239,6 @@ impl KeyPair {
251239
}
252240
}
253241

254-
impl hash::Hash for KeyPair {
255-
fn hash<H: hash::Hasher>(&self, state: &mut H) {
256-
state.write(&self.0)
257-
}
258-
}
259-
260242
extern "C" {
261243
/// Default ECDH hash function
262244
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_4_1_ecdh_hash_function_default")]

secp256k1-sys/src/macros.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ macro_rules! impl_array_newtype {
6161

6262
impl Eq for $thing {}
6363

64+
impl ::core::hash::Hash for $thing {
65+
fn hash<H: ::core::hash::Hasher>(&self, state: &mut H) {
66+
(&self[..]).hash(state)
67+
}
68+
}
69+
6470
impl PartialOrd for $thing {
6571
#[inline]
6672
fn partial_cmp(&self, other: &$thing) -> Option<::core::cmp::Ordering> {

0 commit comments

Comments
 (0)