summaryrefslogtreecommitdiffstats
path: root/openpgp/src/keyid.rs
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-11-26 13:04:47 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-11-26 14:29:29 +0100
commitb24d1c5a099e2c741cf724816d49b8dd7977e049 (patch)
tree0288feb61d74b61acc39045a5e2b31551eb7b131 /openpgp/src/keyid.rs
parent33fd6f48682b15e140d479574ec3377610acb22d (diff)
openpgp: Implement From<Fingerprint> for KeyID.
- Remove Fingerprint::to_keyid, use From instead.
Diffstat (limited to 'openpgp/src/keyid.rs')
-rw-r--r--openpgp/src/keyid.rs26
1 files changed, 25 insertions, 1 deletions
diff --git a/openpgp/src/keyid.rs b/openpgp/src/keyid.rs
index 275599f9..5cda407b 100644
--- a/openpgp/src/keyid.rs
+++ b/openpgp/src/keyid.rs
@@ -45,6 +45,30 @@ impl From<u64> for KeyID {
}
}
+impl From<&Fingerprint> for KeyID {
+ fn from(fp: &Fingerprint) -> Self {
+ match fp {
+ Fingerprint::V4(fp) =>
+ KeyID::from_bytes(&fp[fp.len() - 8..]),
+ Fingerprint::Invalid(fp) => {
+ KeyID::Invalid(fp.clone())
+ }
+ }
+ }
+}
+
+impl From<Fingerprint> for KeyID {
+ fn from(fp: Fingerprint) -> Self {
+ match fp {
+ Fingerprint::V4(fp) =>
+ KeyID::from_bytes(&fp[fp.len() - 8..]),
+ Fingerprint::Invalid(fp) => {
+ KeyID::Invalid(fp)
+ }
+ }
+ }
+}
+
impl KeyID {
/// Converts a u64 to a KeyID.
pub fn new(data: u64) -> KeyID {
@@ -100,7 +124,7 @@ impl KeyID {
} else {
// Maybe a fingerprint was given. Try to parse it and
// convert it to a KeyID.
- Ok(Fingerprint::from_hex(hex)?.to_keyid())
+ Ok(Fingerprint::from_hex(hex)?.into())
}
}