diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-01-02 13:55:29 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-01-02 14:00:24 +0100 |
commit | 61c3c3bfe300b2cf638a1d9dd7985526ea4c23b0 (patch) | |
tree | 576a273df1079c074be1234adedb1a1d52e7a74b | |
parent | 2ea47f61ef6aca4097d7abba850dc4ba6a9018be (diff) |
openpgp: Change SubpacketValue::Unknown to store the tag.
- Makes it possible to construct unknown packets with arbitrary
subpacket tags.
- Fixes a regression.
-rw-r--r-- | openpgp/examples/statistics.rs | 5 | ||||
-rw-r--r-- | openpgp/src/packet/signature/subpacket.rs | 14 | ||||
-rw-r--r-- | openpgp/src/parse/parse.rs | 6 | ||||
-rw-r--r-- | openpgp/src/serialize/mod.rs | 6 | ||||
-rw-r--r-- | tool/src/commands/dump.rs | 6 |
5 files changed, 22 insertions, 15 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(), } } diff --git a/tool/src/commands/dump.rs b/tool/src/commands/dump.rs index 0c874c8c..56f285c1 100644 --- a/tool/src/commands/dump.rs +++ b/tool/src/commands/dump.rs @@ -727,10 +727,10 @@ impl PacketDumper { }; match s.value() { - Unknown(ref b) => { + Unknown { body, .. } => { writeln!(output, "{} {:?}{}:", i, s.tag(), if s.critical() { " (critical)" } else { "" })?; - hexdump_unknown(output, b)?; + hexdump_unknown(output, body)?; }, SignatureCreationTime(t) => write!(output, "{} Signature creation time: {}", i, @@ -815,7 +815,7 @@ impl PacketDumper { } match s.value() { - Unknown(_) => (), + Unknown { .. } => (), EmbeddedSignature(ref sig) => { if s.critical() { write!(output, " (critical)")?; |