From 78f83b21767077f602f30148e513a52e844abbb6 Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Sun, 22 Jan 2023 23:09:26 -0800 Subject: [PATCH] add Ord, Hash impls for VerificationKey (#9) * add Ord, Hash impls for VerificationKey --- CHANGELOG.md | 5 +++++ Cargo.toml | 2 +- src/lib.rs | 2 +- src/verification_key.rs | 18 ++++++++++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42342fe..d1ca83b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ Entries are listed in reverse chronological order. +# 2.1.0 + +* Add `PartialOrd`, `Ord`, `Hash` implementations for `VerificationKey`, + forwarding to the implementations on `VerificationKeyBytes`. + # 2.0.1 * Improve `Debug` output for `VerificationKey`. diff --git a/Cargo.toml b/Cargo.toml index 5aa46e3..71583b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "ed25519-consensus" # Before publishing: # - update CHANGELOG.md # - update html_root_url -version = "2.0.1" +version = "2.1.0" authors = ["Henry de Valence "] license = "MIT OR Apache-2.0" edition = "2018" diff --git a/src/lib.rs b/src/lib.rs index 414a094..2d6292c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -#![doc(html_root_url = "https://docs.rs/ed25519-consensus/2.0.1")] +#![doc(html_root_url = "https://docs.rs/ed25519-consensus/2.1.0")] #![doc = include_str!("../README.md")] #![deny(missing_docs)] #![cfg_attr(not(feature = "std"), no_std)] diff --git a/src/verification_key.rs b/src/verification_key.rs index e7453ae..afa2d88 100644 --- a/src/verification_key.rs +++ b/src/verification_key.rs @@ -113,6 +113,24 @@ pub struct VerificationKey { pub(crate) minus_A: EdwardsPoint, } +impl PartialOrd for VerificationKey { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for VerificationKey { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.A_bytes.cmp(&other.A_bytes) + } +} + +impl core::hash::Hash for VerificationKey { + fn hash(&self, state: &mut H) { + self.A_bytes.hash(state); + } +} + impl core::fmt::Debug for VerificationKey { fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result { fmt.debug_tuple("VerificationKey")