diff options
Diffstat (limited to 'openpgp')
-rw-r--r-- | openpgp/src/packet/key.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/openpgp/src/packet/key.rs b/openpgp/src/packet/key.rs index c5a9e663..f31d58aa 100644 --- a/openpgp/src/packet/key.rs +++ b/openpgp/src/packet/key.rs @@ -1,6 +1,8 @@ //! Public key, public subkey, private key and private subkey packets. use std::fmt; +use std::mem; +use std::cmp::Ordering; use time; use Error; @@ -57,6 +59,33 @@ impl fmt::Display for Key { } impl Key { + /// Compares the public bits of two keys. + /// + /// This returns Ordering::Equal if the public MPIs, version, + /// creation time and algorithm of the two `Key`s match. This + /// does not consider the packet's encoding, packet's tag or the + /// secret key material. + pub fn public_cmp(a: &Self, b: &Self) -> Ordering { + match a.mpis.cmp(&b.mpis) { + Ordering::Equal => (), + o => return o, + } + + match a.version.cmp(&b.version) { + Ordering::Equal => (), + o => return o, + } + + match a.creation_time.cmp(&b.creation_time) { + Ordering::Equal => (), + o => return o, + } + + a.pk_algo.cmp(&b.pk_algo) + } +} + +impl Key { pub(crate) fn new_(creation_time: time::Tm,pk_algo: PublicKeyAlgorithm, mpis: mpis::PublicKey, secret: Option<SecretKey>) -> Result<Key> |