From ee17f352185f40e43874faece5a0e22c95a8d839 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 21 Nov 2022 15:06:14 +0100 Subject: [PATCH] Implement Ord and PartialOrd for secret key type --- radicle-crypto/src/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/radicle-crypto/src/lib.rs b/radicle-crypto/src/lib.rs index c48b0a2f..cad67d4b 100644 --- a/radicle-crypto/src/lib.rs +++ b/radicle-crypto/src/lib.rs @@ -1,3 +1,4 @@ +use std::cmp::Ordering; use std::{fmt, ops::Deref, str::FromStr}; use ed25519_compact as ed25519; @@ -156,6 +157,18 @@ impl PublicKey { #[derive(Clone, Debug, Eq, PartialEq, Hash)] pub struct SecretKey(ed25519::SecretKey); +impl PartialOrd for SecretKey { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for SecretKey { + fn cmp(&self, other: &Self) -> Ordering { + self.0.cmp(&other.0) + } +} + impl zeroize::Zeroize for SecretKey { fn zeroize(&mut self) { self.0.zeroize();