core/identity: Implement Hash and Ord for PublicKey (#2915)

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
This commit is contained in:
futpib
2022-09-22 21:35:42 +04:00
committed by GitHub
parent 0a12418b18
commit bcff814b92
9 changed files with 100 additions and 15 deletions

View File

@ -21,7 +21,9 @@
//! ECDSA keys with secp256r1 curve support.
use super::error::DecodingError;
use core::cmp;
use core::fmt;
use core::hash;
use p256::{
ecdsa::{
signature::{Signer, Verifier},
@ -117,7 +119,7 @@ impl fmt::Debug for SecretKey {
}
/// An ECDSA public key.
#[derive(Clone, PartialEq, Eq)]
#[derive(Clone, Eq, PartialOrd, Ord)]
pub struct PublicKey(VerifyingKey);
impl PublicKey {
@ -222,6 +224,18 @@ impl fmt::Debug for PublicKey {
}
}
impl cmp::PartialEq for PublicKey {
fn eq(&self, other: &Self) -> bool {
self.to_bytes().eq(&other.to_bytes())
}
}
impl hash::Hash for PublicKey {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
self.to_bytes().hash(state);
}
}
#[cfg(test)]
mod tests {
use super::*;