summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2023-02-15 15:22:09 +0100
committerJustus Winter <justus@sequoia-pgp.org>2023-05-22 12:10:54 +0200
commit94d80c41e38550940019b58e89e576ffcec53b56 (patch)
treecdf9ec212ca884ca69eb692ec967722228368e15
parent38759493832e84395fa74e247fb84d3e6700d4a8 (diff)
openpgp: Implement v6 fingerprints.
-rw-r--r--openpgp/src/fingerprint.rs33
-rw-r--r--openpgp/src/keyid.rs4
-rw-r--r--openpgp/src/parse.rs4
-rw-r--r--openpgp/src/serialize.rs8
4 files changed, 30 insertions, 19 deletions
diff --git a/openpgp/src/fingerprint.rs b/openpgp/src/fingerprint.rs
index 36cc8662..78efe3da 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.
@@ -121,7 +121,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())
}
@@ -148,7 +148,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,
}
}
@@ -370,16 +370,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)
}
}
}
@@ -402,7 +413,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 1c83c63b..5bee3ff2 100644
--- a/openpgp/src/keyid.rs
+++ b/openpgp/src/keyid.rs
@@ -138,7 +138,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())
@@ -152,7 +152,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 2dc9fad5..e3b4f32f 100644
--- a/openpgp/src/parse.rs
+++ b/openpgp/src/parse.rs
@@ -1759,7 +1759,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 {
@@ -1785,7 +1785,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 531b3d35..cf57eb8b 100644
--- a/openpgp/src/serialize.rs
+++ b/openpgp/src/serialize.rs
@@ -1458,8 +1458,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(
@@ -1474,8 +1474,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(