diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2023-02-15 15:22:09 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2024-03-13 10:59:08 +0100 |
commit | b6c06886844dc000d25d4c0c51f74f4d5045ff8b (patch) | |
tree | 4650789b770ea4ce92b9512c6b5d2016734efc43 | |
parent | 394369d72979e6a1dbaf8695d1ea71e341a38e0b (diff) |
openpgp: Implement v6 fingerprints.
-rw-r--r-- | openpgp/src/fingerprint.rs | 33 | ||||
-rw-r--r-- | openpgp/src/keyid.rs | 4 | ||||
-rw-r--r-- | openpgp/src/parse.rs | 4 | ||||
-rw-r--r-- | openpgp/src/serialize.rs | 8 |
4 files changed, 30 insertions, 19 deletions
diff --git a/openpgp/src/fingerprint.rs b/openpgp/src/fingerprint.rs index 114366de..b35cf61b 100644 --- a/openpgp/src/fingerprint.rs +++ b/openpgp/src/fingerprint.rs @@ -50,8 +50,8 @@ pub enum Fingerprint { /// A 20 byte SHA-1 hash of the public key packet as defined in the RFC. V4([u8;20]), - /// A v5 OpenPGP fingerprint. - V5([u8; 32]), + /// A v6 OpenPGP fingerprint. + V6([u8; 32]), /// Used for holding fingerprint data that is not a V4 fingerprint, e.g. a /// V3 fingerprint (deprecated) or otherwise wrong-length data. @@ -126,7 +126,7 @@ impl Fingerprint { } else if raw.len() == 32 { let mut fp: [u8; 32] = Default::default(); fp.copy_from_slice(raw); - Fingerprint::V5(fp) + Fingerprint::V6(fp) } else { Fingerprint::Invalid(raw.to_vec().into_boxed_slice()) } @@ -153,7 +153,7 @@ impl Fingerprint { pub fn as_bytes(&self) -> &[u8] { match self { Fingerprint::V4(ref fp) => fp, - Fingerprint::V5(fp) => fp, + Fingerprint::V6(fp) => fp, Fingerprint::Invalid(ref fp) => fp, } } @@ -375,16 +375,27 @@ impl Fingerprint { } #[cfg(test)] +impl Fingerprint { + pub(crate) fn arbitrary_v4(g: &mut Gen) -> Self { + let mut fp = [0; 20]; + fp.iter_mut().for_each(|p| *p = Arbitrary::arbitrary(g)); + Fingerprint::V4(fp) + } + + pub(crate) fn arbitrary_v6(g: &mut Gen) -> Self { + let mut fp = [0; 32]; + fp.iter_mut().for_each(|p| *p = Arbitrary::arbitrary(g)); + Fingerprint::V6(fp) + } +} + + #[cfg(test)] impl Arbitrary for Fingerprint { fn arbitrary(g: &mut Gen) -> Self { if Arbitrary::arbitrary(g) { - let mut fp = [0; 20]; - fp.iter_mut().for_each(|p| *p = Arbitrary::arbitrary(g)); - Fingerprint::V4(fp) + Self::arbitrary_v4(g) } else { - let mut fp = [0; 32]; - fp.iter_mut().for_each(|p| *p = Arbitrary::arbitrary(g)); - Fingerprint::V5(fp) + Self::arbitrary_v6(g) } } } @@ -407,7 +418,7 @@ mod tests { let fp = "0123 4567 89AB CDEF 0123 4567 89AB CDEF \ 0123 4567 89AB CDEF 0123 4567 89AB CDEF" .parse::<Fingerprint>()?; - assert!(matches!(&fp, Fingerprint::V5(_))); + assert!(matches!(&fp, Fingerprint::V6(_))); assert_eq!(format!("{:X}", fp), "0123456789ABCDEF0123456789ABCDEF\ 0123456789ABCDEF0123456789ABCDEF"); assert_eq!(format!("{:x}", fp), "0123456789abcdef0123456789abcdef\ diff --git a/openpgp/src/keyid.rs b/openpgp/src/keyid.rs index 1dc08fe8..244f9d6d 100644 --- a/openpgp/src/keyid.rs +++ b/openpgp/src/keyid.rs @@ -145,7 +145,7 @@ impl From<&Fingerprint> for KeyID { match fp { Fingerprint::V4(fp) => KeyID::from_bytes(&fp[fp.len() - 8..]), - Fingerprint::V5(fp) => + Fingerprint::V6(fp) => KeyID::Invalid(fp.iter().cloned().collect()), Fingerprint::Invalid(fp) => { KeyID::Invalid(fp.clone()) @@ -159,7 +159,7 @@ impl From<Fingerprint> for KeyID { match fp { Fingerprint::V4(fp) => KeyID::from_bytes(&fp[fp.len() - 8..]), - Fingerprint::V5(fp) => + Fingerprint::V6(fp) => KeyID::Invalid(fp.into()), Fingerprint::Invalid(fp) => { KeyID::Invalid(fp) diff --git a/openpgp/src/parse.rs b/openpgp/src/parse.rs index e001a3ac..f1c5ad99 100644 --- a/openpgp/src/parse.rs +++ b/openpgp/src/parse.rs @@ -1783,7 +1783,7 @@ impl Subpacket { let version = php.parse_u8("version")?; if let Some(expect_len) = match version { 4 => Some(1 + 20), - 5 => Some(1 + 32), + 6 => Some(1 + 32), _ => None, } { if len != expect_len { @@ -1809,7 +1809,7 @@ impl Subpacket { let version = php.parse_u8("version")?; if let Some(expect_len) = match version { 4 => Some(1 + 20), - 5 => Some(1 + 32), + 6 => Some(1 + 32), _ => None, } { if len != expect_len { diff --git a/openpgp/src/serialize.rs b/openpgp/src/serialize.rs index 6dcc1845..0925310e 100644 --- a/openpgp/src/serialize.rs +++ b/openpgp/src/serialize.rs @@ -1493,8 +1493,8 @@ impl Marshal for SubpacketValue { o.write_all(&[4])?; o.write_all(fp.as_bytes())?; }, - Fingerprint::V5(_) => { - o.write_all(&[5])?; + Fingerprint::V6(_) => { + o.write_all(&[6])?; o.write_all(fp.as_bytes())?; }, _ => return Err(Error::InvalidArgument( @@ -1509,8 +1509,8 @@ impl Marshal for SubpacketValue { o.write_all(&[4])?; o.write_all(fp.as_bytes())?; }, - Fingerprint::V5(_) => { - o.write_all(&[5])?; + Fingerprint::V6(_) => { + o.write_all(&[6])?; o.write_all(fp.as_bytes())?; }, _ => return Err(Error::InvalidArgument( |