summaryrefslogtreecommitdiffstats
path: root/openpgp/src/keyid.rs
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2018-08-24 14:59:49 +0200
committerJustus Winter <justus@sequoia-pgp.org>2018-08-24 14:59:49 +0200
commit30f525ee2a7b92f17878704f4bcc3cafe6006dde (patch)
tree5784f8f6bd38e14fb3cd7ba063d55d762c331297 /openpgp/src/keyid.rs
parente0f20bbf1462957277119607ca2c0424fc657885 (diff)
openpgp: Make functions parsing key ids, fingerprints return Result.
- Fixes #13.
Diffstat (limited to 'openpgp/src/keyid.rs')
-rw-r--r--openpgp/src/keyid.rs7
1 files changed, 4 insertions, 3 deletions
diff --git a/openpgp/src/keyid.rs b/openpgp/src/keyid.rs
index ae51d27e..3065398a 100644
--- a/openpgp/src/keyid.rs
+++ b/openpgp/src/keyid.rs
@@ -2,6 +2,7 @@ use std::fmt;
use Fingerprint;
use KeyID;
+use Result;
impl fmt::Display for KeyID {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@@ -56,16 +57,16 @@ impl KeyID {
}
/// Reads a hex-encoded Key ID.
- pub fn from_hex(hex: &str) -> Option<KeyID> {
+ pub fn from_hex(hex: &str) -> Result<KeyID> {
let bytes = ::conversions::from_hex(hex, true)?;
// A KeyID is exactly 8 bytes long.
if bytes.len() == 8 {
- Some(KeyID::from_bytes(&bytes[..]))
+ Ok(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())
+ Ok(Fingerprint::from_hex(hex)?.to_keyid())
}
}