Skip to content

Commit 75b49ef

Browse files
committed
Implement Hash for all array newtypes
* implements `Hash` as part of the newtype macro * removes type-specific implementations
1 parent 24a9c9c commit 75b49ef

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)