summaryrefslogtreecommitdiffstats
path: root/openpgp/src/keyhandle.rs
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2020-01-14 09:35:54 +0100
committerNeal H. Walfield <neal@pep.foundation>2020-01-14 09:51:02 +0100
commit9e4e94e3378093baf569404b4be1ca8b7fedbe1b (patch)
treeaf88a1f223b3831d7db28b44882ddb250cf72b1a /openpgp/src/keyhandle.rs
parent5e636b7352cc709597895944b88067961664a0c5 (diff)
openpgp: Add conversions from &KeyHandle to KeyID and Fingerprint.
Diffstat (limited to 'openpgp/src/keyhandle.rs')
-rw-r--r--openpgp/src/keyhandle.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/openpgp/src/keyhandle.rs b/openpgp/src/keyhandle.rs
index 88a9acde..c5058b9d 100644
--- a/openpgp/src/keyhandle.rs
+++ b/openpgp/src/keyhandle.rs
@@ -51,6 +51,15 @@ impl From<KeyHandle> for KeyID {
}
}
+impl From<&KeyHandle> for KeyID {
+ fn from(i: &KeyHandle) -> Self {
+ match i {
+ KeyHandle::Fingerprint(i) => i.clone().into(),
+ KeyHandle::KeyID(i) => i.clone(),
+ }
+ }
+}
+
impl From<Fingerprint> for KeyHandle {
fn from(i: Fingerprint) -> Self {
KeyHandle::Fingerprint(i)
@@ -74,6 +83,17 @@ impl TryFrom<KeyHandle> for Fingerprint {
}
}
+impl TryFrom<&KeyHandle> for Fingerprint {
+ type Error = failure::Error;
+ fn try_from(i: &KeyHandle) -> Result<Self> {
+ match i {
+ KeyHandle::Fingerprint(i) => Ok(i.clone()),
+ KeyHandle::KeyID(i) => Err(Error::InvalidOperation(
+ format!("Cannot convert keyid {} to fingerprint", i)).into()),
+ }
+ }
+}
+
impl PartialOrd for KeyHandle {
fn partial_cmp(&self, other: &KeyHandle) -> Option<Ordering> {
let a = self.as_slice();