summaryrefslogtreecommitdiffstats
path: root/openpgp
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2018-12-24 15:02:05 +0100
committerNeal H. Walfield <neal@pep.foundation>2018-12-24 16:31:14 +0100
commitbf4c310cb400294514ca42994a8c72cf4111e7d9 (patch)
treeb508ffc3160c1277423ce42958f3dda9ac0ef541 /openpgp
parent5136023a44cd15aaa0fe0b50d85720d936d256c7 (diff)
openpgp: Add a function to compare the public bits of two Keys
- This is made available as Key::public_cmp and not as an implementation of Ord::cmp, because Ord::cmp, should it be implemented, should also compare the private bits.
Diffstat (limited to 'openpgp')
-rw-r--r--openpgp/src/packet/key.rs29
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>