diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2023-02-15 15:22:09 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2024-06-20 10:58:42 +0200 |
commit | cbeed31037570bfaa410b4ee620a75022bd9f2f9 (patch) | |
tree | 52b9fb2129b3db9c616c33403635768db8a6f590 /openpgp | |
parent | 6f62ed0525bb20b9d018b283f06e3bbf84200228 (diff) |
openpgp: Implement v6 fingerprints.
Diffstat (limited to 'openpgp')
-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 3d02438a..fdc8213f 100644 --- a/openpgp/src/parse.rs +++ b/openpgp/src/parse.rs @@ -1786,7 +1786,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 { @@ -1812,7 +1812,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 89ca0edf..5b0221c5 100644 --- a/openpgp/src/serialize.rs +++ b/openpgp/src/serialize.rs @@ -1495,8 +1495,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( @@ -1511,8 +1511,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( |