diff options
Diffstat (limited to 'openpgp/src/keyid.rs')
-rw-r--r-- | openpgp/src/keyid.rs | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/openpgp/src/keyid.rs b/openpgp/src/keyid.rs index 244f9d6d..4052e6a2 100644 --- a/openpgp/src/keyid.rs +++ b/openpgp/src/keyid.rs @@ -59,8 +59,12 @@ use crate::Result; #[non_exhaustive] #[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Hash)] pub enum KeyID { - /// Lower 8 byte SHA-1 hash. - V4([u8;8]), + /// A long (8 bytes) key ID. + /// + /// For v4, this is the right-most 8 bytes of the v4 fingerprint. + /// For v6, this is the left-most 8 bytes of the v6 fingerprint. + Long([u8; 8]), + /// Used for holding invalid keyids encountered during parsing /// e.g. wrong number of bytes. Invalid(Box<[u8]>), @@ -121,7 +125,7 @@ impl From<KeyID> for Vec<u8> { fn from(id: KeyID) -> Self { let mut r = Vec::with_capacity(8); match id { - KeyID::V4(ref b) => r.extend_from_slice(b), + KeyID::Long(ref b) => r.extend_from_slice(b), KeyID::Invalid(ref b) => r.extend_from_slice(b), } r @@ -146,7 +150,7 @@ impl From<&Fingerprint> for KeyID { Fingerprint::V4(fp) => KeyID::from_bytes(&fp[fp.len() - 8..]), Fingerprint::V6(fp) => - KeyID::Invalid(fp.iter().cloned().collect()), + KeyID::from_bytes(&fp[..8]), Fingerprint::Invalid(fp) => { KeyID::Invalid(fp.clone()) } @@ -160,7 +164,7 @@ impl From<Fingerprint> for KeyID { Fingerprint::V4(fp) => KeyID::from_bytes(&fp[fp.len() - 8..]), Fingerprint::V6(fp) => - KeyID::Invalid(fp.into()), + KeyID::from_bytes(&fp[..8]), Fingerprint::Invalid(fp) => { KeyID::Invalid(fp) } @@ -200,7 +204,7 @@ impl KeyID { /// ``` pub fn as_u64(&self) -> Result<u64> { match &self { - KeyID::V4(ref b) => + KeyID::Long(ref b) => Ok(u64::from_be_bytes(*b)), KeyID::Invalid(_) => Err(Error::InvalidArgument("Invalid KeyID".into()).into()), @@ -226,7 +230,7 @@ impl KeyID { if raw.len() == 8 { let mut keyid : [u8; 8] = Default::default(); keyid.copy_from_slice(raw); - KeyID::V4(keyid) + KeyID::Long(keyid) } else { KeyID::Invalid(raw.to_vec().into_boxed_slice()) } @@ -249,7 +253,7 @@ impl KeyID { /// ``` pub fn as_bytes(&self) -> &[u8] { match self { - KeyID::V4(ref id) => id, + KeyID::Long(ref id) => id, KeyID::Invalid(ref id) => id, } } @@ -392,11 +396,11 @@ impl KeyID { let pretty = f.alternate(); let raw = match self { - KeyID::V4(ref fp) => &fp[..], + KeyID::Long(ref fp) => &fp[..], KeyID::Invalid(ref fp) => &fp[..], }; - // We currently only handle V4 Key IDs, which look like: + // We currently only handle long Key IDs, which look like: // // AACB 3243 6300 52D9 // |