Skip to content
This repository was archived by the owner on Feb 25, 2021. It is now read-only.

Commit e3b08c2

Browse files
authored
Merge pull request BlockstreamResearch#26 from alekseysidorov/derive-standard-traits
Implement Ord for arrays
2 parents 01fb305 + 113fe42 commit e3b08c2

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
name = "secp256k1"
4-
version = "0.9.0"
4+
version = "0.9.1"
55
authors = [ "Dawid Ciężarkiewicz <[email protected]>",
66
"Andrew Poelstra <[email protected]>" ]
77
license = "CC0-1.0"

src/key.rs

+26-2
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,9 @@ pub const ONE_KEY: SecretKey = SecretKey([0, 0, 0, 0, 0, 0, 0, 0,
4949
0, 0, 0, 0, 0, 0, 0, 1]);
5050

5151
/// A Secp256k1 public key, used for verification of signatures
52-
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
52+
#[derive(Copy, Clone, PartialEq, Eq, Debug, PartialOrd, Ord, Hash)]
5353
pub struct PublicKey(ffi::PublicKey);
5454

55-
5655
#[cfg(any(test, feature = "rand"))]
5756
fn random_32_bytes<R: Rng>(rng: &mut R) -> [u8; 32] {
5857
let mut ret = [0u8; 32];
@@ -559,6 +558,31 @@ mod test {
559558
assert_eq!(sum1, sum2);
560559
assert_eq!(sum1.unwrap(), exp_sum);
561560
}
561+
562+
#[test]
563+
fn pubkey_equal() {
564+
let s = Secp256k1::new();
565+
let pk1 = PublicKey::from_slice(
566+
&s,
567+
&hex!("0241cc121c419921942add6db6482fb36243faf83317c866d2a28d8c6d7089f7ba"),
568+
).unwrap();
569+
let pk2 = pk1.clone();
570+
let pk3 = PublicKey::from_slice(
571+
&s,
572+
&hex!("02e6642fd69bd211f93f7f1f36ca51a26a5290eb2dd1b0d8279a87bb0d480c8443"),
573+
).unwrap();
574+
575+
assert!(pk1 == pk2);
576+
assert!(pk1 <= pk2);
577+
assert!(pk2 <= pk1);
578+
assert!(!(pk2 < pk1));
579+
assert!(!(pk1 < pk2));
580+
581+
assert!(pk3 < pk1);
582+
assert!(pk1 > pk3);
583+
assert!(pk3 <= pk1);
584+
assert!(pk1 >= pk3);
585+
}
562586
}
563587

564588

src/macros.rs

+14
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ macro_rules! impl_array_newtype {
5151

5252
impl Eq for $thing {}
5353

54+
impl PartialOrd for $thing {
55+
#[inline]
56+
fn partial_cmp(&self, other: &$thing) -> Option<::std::cmp::Ordering> {
57+
self[..].partial_cmp(&other[..])
58+
}
59+
}
60+
61+
impl Ord for $thing {
62+
#[inline]
63+
fn cmp(&self, other: &$thing) -> ::std::cmp::Ordering {
64+
self[..].cmp(&other[..])
65+
}
66+
}
67+
5468
impl Clone for $thing {
5569
#[inline]
5670
fn clone(&self) -> $thing {

0 commit comments

Comments
 (0)