Skip to content

Commit 6f8a480

Browse files
committed
Implement lexigraphic ordering for PubKey
1 parent d31dcf2 commit 6f8a480

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/key.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub const ONE_KEY: SecretKey = SecretKey([0, 0, 0, 0, 0, 0, 0, 0,
6464
0, 0, 0, 0, 0, 0, 0, 1]);
6565

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

7070
impl fmt::LowerHex for PublicKey {
@@ -470,6 +470,18 @@ impl<'de> ::serde::Deserialize<'de> for PublicKey {
470470
}
471471
}
472472

473+
impl PartialOrd for PublicKey {
474+
fn partial_cmp(&self, other: &PublicKey) -> Option<::core::cmp::Ordering> {
475+
self.serialize().partial_cmp(&other.serialize())
476+
}
477+
}
478+
479+
impl Ord for PublicKey {
480+
fn cmp(&self, other: &PublicKey) -> ::core::cmp::Ordering {
481+
self.serialize().cmp(&other.serialize())
482+
}
483+
}
484+
473485
#[cfg(test)]
474486
mod test {
475487
use Secp256k1;
@@ -860,10 +872,10 @@ mod test {
860872
assert!(!(pk2 < pk1));
861873
assert!(!(pk1 < pk2));
862874

863-
assert!(pk3 < pk1);
864-
assert!(pk1 > pk3);
865-
assert!(pk3 <= pk1);
866-
assert!(pk1 >= pk3);
875+
assert!(pk3 > pk1);
876+
assert!(pk1 < pk3);
877+
assert!(pk3 >= pk1);
878+
assert!(pk1 <= pk3);
867879
}
868880

869881
#[cfg(feature = "serde")]

0 commit comments

Comments
 (0)