summaryrefslogtreecommitdiffstats
path: root/openpgp/src/keyid.rs
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2018-06-20 16:35:49 +0200
committerJustus Winter <justus@sequoia-pgp.org>2018-06-20 16:35:49 +0200
commit1ee5891da3d061cea6c8c61206e9129ba81d8bc7 (patch)
treeddedc9679e3f62765c7e885c6c5de06b16a1a4e5 /openpgp/src/keyid.rs
parente030f92ba92cf5be368eb7f9bf32c16350466e5b (diff)
openpgp: Make KeyID parsing more robust by accepting fingerprints.
- A fingerprint contains more information than a keyid, I see no reason not to parsing it to a keyid, other than to annoy any users.
Diffstat (limited to 'openpgp/src/keyid.rs')
-rw-r--r--openpgp/src/keyid.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/openpgp/src/keyid.rs b/openpgp/src/keyid.rs
index 976ad7ba..e112779b 100644
--- a/openpgp/src/keyid.rs
+++ b/openpgp/src/keyid.rs
@@ -1,5 +1,6 @@
use std::fmt;
+use Fingerprint;
use KeyID;
impl fmt::Display for KeyID {
@@ -59,11 +60,13 @@ impl KeyID {
let bytes = ::from_hex(hex, true)?;
// A KeyID is exactly 8 bytes long.
- if bytes.len() != 8 {
- return None;
+ if bytes.len() == 8 {
+ Some(KeyID::from_bytes(&bytes[..]))
+ } else {
+ // Maybe a fingerprint was given. Try to parse it and
+ // convert it to a KeyID.
+ Some(Fingerprint::from_hex(hex)?.to_keyid())
}
-
- Some(KeyID::from_bytes(&bytes[..]))
}
/// Returns a reference to the raw KeyID.