summaryrefslogtreecommitdiffstats
path: root/openpgp
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-01-02 13:55:29 +0100
committerJustus Winter <justus@sequoia-pgp.org>2020-01-02 14:00:24 +0100
commit61c3c3bfe300b2cf638a1d9dd7985526ea4c23b0 (patch)
tree576a273df1079c074be1234adedb1a1d52e7a74b /openpgp
parent2ea47f61ef6aca4097d7abba850dc4ba6a9018be (diff)
openpgp: Change SubpacketValue::Unknown to store the tag.
- Makes it possible to construct unknown packets with arbitrary subpacket tags. - Fixes a regression.
Diffstat (limited to 'openpgp')
-rw-r--r--openpgp/examples/statistics.rs5
-rw-r--r--openpgp/src/packet/signature/subpacket.rs14
-rw-r--r--openpgp/src/parse/parse.rs6
-rw-r--r--openpgp/src/serialize/mod.rs6
4 files changed, 19 insertions, 12 deletions
diff --git a/openpgp/examples/statistics.rs b/openpgp/examples/statistics.rs
index 0b453467..c990fb58 100644
--- a/openpgp/examples/statistics.rs
+++ b/openpgp/examples/statistics.rs
@@ -149,7 +149,7 @@ fn main() {
sigs_subpacket_tags_count[i] += 1;
cert.sigs_subpacket_tags_count[i] += 1;
signature.subpacket_tags_count[i] += 1;
- if let SubpacketValue::Unknown(_) = sub.value() {
+ if let SubpacketValue::Unknown { .. } = sub.value() {
sigs_subpacket_tags_unknown
[u8::from(sub.tag()) as usize] += 1;
} else {
@@ -165,7 +165,8 @@ fn main() {
}
match sub.value() {
- SubpacketValue::Unknown(_) => unreachable!(),
+ SubpacketValue::Unknown { .. } =>
+ unreachable!(),
SubpacketValue::KeyFlags(k) =>
if let Some(count) = key_flags.get_mut(&k) {
*count += 1;
diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs
index e37da609..5544e66d 100644
--- a/openpgp/src/packet/signature/subpacket.rs
+++ b/openpgp/src/packet/signature/subpacket.rs
@@ -562,8 +562,13 @@ impl NotationDataFlags {
/// description of these tags.
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub enum SubpacketValue {
- /// The subpacket is unknown.
- Unknown(Vec<u8>),
+ /// An unknown subpacket.
+ Unknown {
+ /// The unknown subpacket's tag.
+ tag: SubpacketTag,
+ /// The unknown subpacket's uninterpreted body.
+ body: Vec<u8>
+ },
/// 4-octet time field
SignatureCreationTime(Timestamp),
@@ -704,7 +709,7 @@ impl SubpacketValue {
// Educated guess for unknown versions.
Fingerprint::Invalid(_) => 1 + fp.as_slice().len(),
},
- Unknown(u) => u.len(),
+ Unknown { body, .. } => body.len(),
}
}
@@ -744,8 +749,7 @@ impl SubpacketValue {
PreferredAEADAlgorithms(_) =>
Ok(SubpacketTag::PreferredAEADAlgorithms),
IntendedRecipient(_) => Ok(SubpacketTag::IntendedRecipient),
- _ => Err(Error::InvalidArgument(
- "Unknown or invalid subpacket value".into()).into()),
+ Unknown { tag, .. } => Ok(*tag),
}
}
}
diff --git a/openpgp/src/parse/parse.rs b/openpgp/src/parse/parse.rs
index 1c6bc4ec..9c08867a 100644
--- a/openpgp/src/parse/parse.rs
+++ b/openpgp/src/parse/parse.rs
@@ -1412,8 +1412,10 @@ impl Subpacket {
| SubpacketTag::PlaceholderForBackwardCompatibility
| SubpacketTag::Private(_)
| SubpacketTag::Unknown(_) =>
- SubpacketValue::Unknown(
- php.parse_bytes("unknown subpacket", len)?),
+ SubpacketValue::Unknown {
+ tag,
+ body: php.parse_bytes("unknown subpacket", len)?,
+ },
};
let total_out = php.reader.total_out();
diff --git a/openpgp/src/serialize/mod.rs b/openpgp/src/serialize/mod.rs
index 51cb8311..1f27b50f 100644
--- a/openpgp/src/serialize/mod.rs
+++ b/openpgp/src/serialize/mod.rs
@@ -1077,8 +1077,8 @@ impl Serialize for SubpacketValue {
_ => return Err(Error::InvalidArgument(
"Unknown kind of fingerprint".into()).into()),
}
- Unknown(ref raw) =>
- o.write_all(raw)?,
+ Unknown { body, .. } =>
+ o.write_all(body)?,
}
Ok(())
}
@@ -1120,7 +1120,7 @@ impl SerializeInto for SubpacketValue {
Fingerprint::V4(_) => 1 + fp.serialized_len(),
_ => 0,
},
- Unknown(ref raw) => raw.len(),
+ Unknown { body, .. } => body.len(),
}
}