mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-07-02 19:21:37 +00:00
core/identity: Implement Hash
and Ord
for PublicKey (#2915)
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
This commit is contained in:
@ -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::*;
|
||||
|
Reference in New Issue
Block a user