Skip to content

Commit 7bba2bc

Browse files
committed
secp256k1-sys: Remove custom implementations of Eq, Ord and friends
Note: Only effects code when fuzzing is enabled, as such does not include a mention in the changelog. Now that we have Rust 1.48 as the MSRV we no longer need the custom implementations of `PartialEq`, `Eq`, `PartialOrd`, `Ord`, and `Hash`. We can just let users of the `impl_array_newtype` macro derive these traits if they want them. Remove the custom implementations and add derives to our two users of the macro.
1 parent a815272 commit 7bba2bc

File tree

3 files changed

+5
-36
lines changed

3 files changed

+5
-36
lines changed

secp256k1-sys/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ impl SchnorrSigExtraParams {
133133
/// Library-internal representation of a Secp256k1 public key
134134
#[repr(C)]
135135
#[derive(Copy, Clone)]
136+
#[cfg_attr(fuzzing, derive(PartialEq, Eq, PartialOrd, Ord, Hash))]
136137
pub struct PublicKey([c_uchar; 64]);
137138
impl_array_newtype!(PublicKey, c_uchar, 64);
138139
impl_raw_debug!(PublicKey);
@@ -227,6 +228,7 @@ impl core::hash::Hash for PublicKey {
227228
/// Library-internal representation of a Secp256k1 signature
228229
#[repr(C)]
229230
#[derive(Copy, Clone)]
231+
#[cfg_attr(fuzzing, derive(PartialEq, Eq, PartialOrd, Ord, Hash))]
230232
pub struct Signature([c_uchar; 64]);
231233
impl_array_newtype!(Signature, c_uchar, 64);
232234
impl_raw_debug!(Signature);
@@ -315,6 +317,7 @@ impl core::hash::Hash for Signature {
315317

316318
#[repr(C)]
317319
#[derive(Copy, Clone)]
320+
#[cfg_attr(fuzzing, derive(PartialEq, Eq, PartialOrd, Ord, Hash))]
318321
pub struct XOnlyPublicKey([c_uchar; 64]);
319322
impl_array_newtype!(XOnlyPublicKey, c_uchar, 64);
320323
impl_raw_debug!(XOnlyPublicKey);
@@ -404,6 +407,7 @@ impl core::hash::Hash for XOnlyPublicKey {
404407

405408
#[repr(C)]
406409
#[derive(Copy, Clone)]
410+
#[cfg_attr(fuzzing, derive(PartialEq, Eq, PartialOrd, Ord, Hash))]
407411
pub struct KeyPair([c_uchar; 96]);
408412
impl_array_newtype!(KeyPair, c_uchar, 96);
409413
impl_raw_debug!(KeyPair);

secp256k1-sys/src/macros.rs

-36
Original file line numberDiff line numberDiff line change
@@ -45,42 +45,6 @@ macro_rules! impl_array_newtype {
4545
}
4646
}
4747

48-
// We cannot derive these traits because Rust 1.41.1 requires `std::array::LengthAtMost32`.
49-
50-
#[cfg(fuzzing)]
51-
impl PartialEq for $thing {
52-
#[inline]
53-
fn eq(&self, other: &$thing) -> bool {
54-
&self[..] == &other[..]
55-
}
56-
}
57-
58-
#[cfg(fuzzing)]
59-
impl Eq for $thing {}
60-
61-
#[cfg(fuzzing)]
62-
impl core::hash::Hash for $thing {
63-
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
64-
(&self[..]).hash(state)
65-
}
66-
}
67-
68-
#[cfg(fuzzing)]
69-
impl PartialOrd for $thing {
70-
#[inline]
71-
fn partial_cmp(&self, other: &$thing) -> Option<core::cmp::Ordering> {
72-
self[..].partial_cmp(&other[..])
73-
}
74-
}
75-
76-
#[cfg(fuzzing)]
77-
impl Ord for $thing {
78-
#[inline]
79-
fn cmp(&self, other: &$thing) -> core::cmp::Ordering {
80-
self[..].cmp(&other[..])
81-
}
82-
}
83-
8448
impl AsRef<[$ty; $len]> for $thing {
8549
#[inline]
8650
/// Gets a reference to the underlying array

secp256k1-sys/src/recovery.rs

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use core::fmt;
2222
/// Library-internal representation of a Secp256k1 signature + recovery ID
2323
#[repr(C)]
2424
#[derive(Copy, Clone)]
25+
#[cfg_attr(fuzzing, derive(PartialEq, Eq, PartialOrd, Ord, Hash))]
2526
pub struct RecoverableSignature([c_uchar; 65]);
2627
impl_array_newtype!(RecoverableSignature, c_uchar, 65);
2728

0 commit comments

Comments
 (0)