From e1f5eb9169f802e58a5b1c428dad55566e5ff364 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Fri, 4 Aug 2023 16:17:52 -0400 Subject: [PATCH] docs --- src/p384.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/p384.rs b/src/p384.rs index 994b4e8..ffe90a1 100644 --- a/src/p384.rs +++ b/src/p384.rs @@ -374,6 +374,7 @@ impl crate::Address for Address { const SIZE: usize = 48; } +/// NIST P-384 based new format identity with key upgrade capability. #[derive(Clone)] pub struct Identity { pub address: Address, @@ -393,6 +394,13 @@ impl Identity { sign_tmp.push_slice(self.ecdsa.as_bytes()); self.address.is_valid() && self.master_signing_key.verify(sign_tmp.as_bytes(), &self.master_signature) } + + /// Returns true if this identity should replace the other. + /// This just returns true if the timestamp is newer and the address (master signing key hash) is the same. + #[inline(always)] + pub fn replaces(&self, other: &Identity) -> bool { + self.address == other.address && self.timestamp > other.timestamp + } } impl ToString for Identity { @@ -504,6 +512,10 @@ impl crate::Identity for Identity { } } +/// Secret NIST P-384 identity (also contains public). +/// +/// The master signing key is optional to allow it to be removed and placed in cold storage. +/// It's only needed if the identity is to have its regular working keys upgraded. pub struct IdentitySecret { pub public: Identity, pub master_signing_key: Option, @@ -512,6 +524,7 @@ pub struct IdentitySecret { } impl PartialEq for IdentitySecret { + #[inline(always)] fn eq(&self, other: &Self) -> bool { self.public == other.public }