summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-01-02 14:22:25 +0100
committerJustus Winter <justus@sequoia-pgp.org>2020-01-02 14:22:25 +0100
commit5987c772b2681fd82cfb8c3974a5408f40474f5a (patch)
treed10bf4124af07f0648e92f77623ddd36e58d9ac6
parent4860c74a89627841993b96f0d22716ba5fc79ceb (diff)
openpgp: Do not explicitly store the subpacket tag.
-rw-r--r--openpgp/src/packet/signature/subpacket.rs52
-rw-r--r--openpgp/src/parse/parse.rs3
2 files changed, 9 insertions, 46 deletions
diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs
index d71bca15..323c5cfb 100644
--- a/openpgp/src/packet/signature/subpacket.rs
+++ b/openpgp/src/packet/signature/subpacket.rs
@@ -392,7 +392,7 @@ impl SubpacketArea {
if self.parsed.lock().unwrap().borrow().is_none() {
let mut hash = HashMap::new();
for (i, sp) in self.packets.iter().enumerate() {
- hash.insert(sp.tag, i);
+ hash.insert(sp.tag(), i);
}
*self.parsed.lock().unwrap().borrow_mut() = Some(hash);
@@ -778,8 +778,6 @@ pub struct Subpacket {
length: SubpacketLength,
/// Critical flag.
critical: bool,
- /// Packet type.
- tag: SubpacketTag,
/// Packet value, must match packet type.
value: SubpacketValue,
}
@@ -802,21 +800,19 @@ impl Subpacket {
/// Creates a new subpacket.
pub fn new(value: SubpacketValue, critical: bool)
-> Result<Subpacket> {
- Ok(Self::with_length_tag(
+ Ok(Self::with_length(
SubpacketLength::from(1 /* Tag */ + value.len() as u32),
- value.tag(), value, critical))
+ value, critical))
}
/// Creates a new subpacket with the given length and tag.
- pub(crate) fn with_length_tag(length: SubpacketLength,
- tag: SubpacketTag,
- value: SubpacketValue,
- critical: bool)
- -> Subpacket {
+ pub(crate) fn with_length(length: SubpacketLength,
+ value: SubpacketValue,
+ critical: bool)
+ -> Subpacket {
Subpacket {
length,
critical,
- tag,
value,
}
}
@@ -828,7 +824,7 @@ impl Subpacket {
/// Returns the subpacket tag.
pub fn tag(&self) -> SubpacketTag {
- self.tag
+ self.value.tag()
}
/// Returns the subpackets value.
@@ -2620,7 +2616,6 @@ fn subpacket_test_2() {
Some(&Subpacket {
length: 5.into(),
critical: false,
- tag: SubpacketTag::SignatureCreationTime,
value: SubpacketValue::SignatureCreationTime(
1515791508.into())
}));
@@ -2634,7 +2629,6 @@ fn subpacket_test_2() {
Some(&Subpacket {
length: 5.into(),
critical: false,
- tag: SubpacketTag::KeyExpirationTime,
value: SubpacketValue::KeyExpirationTime(
63072000.into())
}));
@@ -2658,7 +2652,6 @@ fn subpacket_test_2() {
Some(&Subpacket {
length: 5.into(),
critical: false,
- tag: SubpacketTag::PreferredSymmetricAlgorithms,
value: SubpacketValue::PreferredSymmetricAlgorithms(
vec![SymmetricAlgorithm::AES256,
SymmetricAlgorithm::AES192,
@@ -2676,7 +2669,6 @@ fn subpacket_test_2() {
Some(&Subpacket {
length: 6.into(),
critical: false,
- tag: SubpacketTag::PreferredHashAlgorithms,
value: SubpacketValue::PreferredHashAlgorithms(
vec![HashAlgorithm::SHA256,
HashAlgorithm::SHA384,
@@ -2693,7 +2685,6 @@ fn subpacket_test_2() {
Some(&Subpacket {
length: 4.into(),
critical: false,
- tag: SubpacketTag::PreferredCompressionAlgorithms,
value: SubpacketValue::PreferredCompressionAlgorithms(
vec![CompressionAlgorithm::Zlib,
CompressionAlgorithm::BZip2,
@@ -2706,7 +2697,6 @@ fn subpacket_test_2() {
Some(&Subpacket {
length: 2.into(),
critical: false,
- tag: SubpacketTag::KeyServerPreferences,
value: SubpacketValue::KeyServerPreferences(
KeyServerPreferences::default().set_no_modify(true)),
}));
@@ -2716,7 +2706,6 @@ fn subpacket_test_2() {
Some(&Subpacket {
length: 2.into(),
critical: false,
- tag: SubpacketTag::KeyFlags,
value: SubpacketValue::KeyFlags(
KeyFlags::default().set_certification(true).set_signing(true))
}));
@@ -2726,7 +2715,6 @@ fn subpacket_test_2() {
Some(&Subpacket {
length: 2.into(),
critical: false,
- tag: SubpacketTag::Features,
value: SubpacketValue::Features(
Features::default().set_mdc(true))
}));
@@ -2737,7 +2725,6 @@ fn subpacket_test_2() {
Some(&Subpacket {
length: 9.into(),
critical: false,
- tag: SubpacketTag::Issuer,
value: SubpacketValue::Issuer(keyid)
}));
@@ -2748,7 +2735,6 @@ fn subpacket_test_2() {
Some(&Subpacket {
length: 22.into(),
critical: false,
- tag: SubpacketTag::IssuerFingerprint,
value: SubpacketValue::IssuerFingerprint(fp)
}));
@@ -2762,7 +2748,6 @@ fn subpacket_test_2() {
Some(&Subpacket {
length: 32.into(),
critical: false,
- tag: SubpacketTag::NotationData,
value: SubpacketValue::NotationData(n.clone())
}));
assert_eq!(sig.subpackets(SubpacketTag::NotationData)
@@ -2770,7 +2755,6 @@ fn subpacket_test_2() {
vec![&Subpacket {
length: 32.into(),
critical: false,
- tag: SubpacketTag::NotationData,
value: SubpacketValue::NotationData(n.clone())
}]);
} else {
@@ -2796,7 +2780,6 @@ fn subpacket_test_2() {
Some(&Subpacket {
length: 5.into(),
critical: false,
- tag: SubpacketTag::SignatureCreationTime,
value: SubpacketValue::SignatureCreationTime(
1515791490.into())
}));
@@ -2806,7 +2789,6 @@ fn subpacket_test_2() {
Some(&Subpacket {
length: 2.into(),
critical: false,
- tag: SubpacketTag::ExportableCertification,
value: SubpacketValue::ExportableCertification(false)
}));
}
@@ -2834,7 +2816,6 @@ fn subpacket_test_2() {
Some(&Subpacket {
length: 5.into(),
critical: false,
- tag: SubpacketTag::SignatureCreationTime,
value: SubpacketValue::SignatureCreationTime(
1515791376.into())
}));
@@ -2844,7 +2825,6 @@ fn subpacket_test_2() {
Some(&Subpacket {
length: 2.into(),
critical: false,
- tag: SubpacketTag::Revocable,
value: SubpacketValue::Revocable(false)
}));
@@ -2856,7 +2836,6 @@ fn subpacket_test_2() {
Some(&Subpacket {
length: 23.into(),
critical: false,
- tag: SubpacketTag::RevocationKey,
value: SubpacketValue::RevocationKey {
class: 0x80,
pk_algo: PublicKeyAlgorithm::RSAEncryptSign,
@@ -2871,7 +2850,6 @@ fn subpacket_test_2() {
Some(&Subpacket {
length: 9.into(),
critical: false,
- tag: SubpacketTag::Issuer,
value: SubpacketValue::Issuer(keyid)
}));
@@ -2882,7 +2860,6 @@ fn subpacket_test_2() {
Some(&Subpacket {
length: 22.into(),
critical: false,
- tag: SubpacketTag::IssuerFingerprint,
value: SubpacketValue::IssuerFingerprint(fp)
}));
@@ -2909,7 +2886,6 @@ fn subpacket_test_2() {
Some(&Subpacket {
length: 5.into(),
critical: false,
- tag: SubpacketTag::SignatureCreationTime,
value: SubpacketValue::SignatureCreationTime(
1515886658.into())
}));
@@ -2921,7 +2897,6 @@ fn subpacket_test_2() {
Some(&Subpacket {
length: 33.into(),
critical: false,
- tag: SubpacketTag::ReasonForRevocation,
value: SubpacketValue::ReasonForRevocation {
code: ReasonForRevocation::Unspecified,
reason: b"Forgot to set a sig expiration.".to_vec(),
@@ -2941,7 +2916,6 @@ fn subpacket_test_2() {
Some(&Subpacket {
length: 5.into(),
critical: false,
- tag: SubpacketTag::SignatureCreationTime,
value: SubpacketValue::SignatureCreationTime(
1515791467.into())
}));
@@ -2970,7 +2944,6 @@ fn subpacket_test_2() {
Some(&Subpacket {
length: 35.into(),
critical: false,
- tag: SubpacketTag::NotationData,
value: SubpacketValue::NotationData(n3.clone())
}));
@@ -2981,19 +2954,16 @@ fn subpacket_test_2() {
&Subpacket {
length: 38.into(),
critical: false,
- tag: SubpacketTag::NotationData,
value: SubpacketValue::NotationData(n1)
},
&Subpacket {
length: 24.into(),
critical: false,
- tag: SubpacketTag::NotationData,
value: SubpacketValue::NotationData(n2)
},
&Subpacket {
length: 35.into(),
critical: false,
- tag: SubpacketTag::NotationData,
value: SubpacketValue::NotationData(n3)
},
]);
@@ -3021,7 +2991,6 @@ fn subpacket_test_2() {
Some(&Subpacket {
length: 5.into(),
critical: false,
- tag: SubpacketTag::SignatureCreationTime,
value: SubpacketValue::SignatureCreationTime(
1515791223.into())
}));
@@ -3031,7 +3000,6 @@ fn subpacket_test_2() {
Some(&Subpacket {
length: 3.into(),
critical: false,
- tag: SubpacketTag::TrustSignature,
value: SubpacketValue::TrustSignature {
level: 2,
trust: 120,
@@ -3045,7 +3013,6 @@ fn subpacket_test_2() {
Some(&Subpacket {
length: 23.into(),
critical: true,
- tag: SubpacketTag::RegularExpression,
value: SubpacketValue::RegularExpression(regex.to_vec())
}));
}
@@ -3077,7 +3044,6 @@ fn subpacket_test_2() {
Some(&Subpacket {
length: 5.into(),
critical: false,
- tag: SubpacketTag::KeyExpirationTime,
value: SubpacketValue::KeyExpirationTime(
63072000.into())
}));
@@ -3088,7 +3054,6 @@ fn subpacket_test_2() {
Some(&Subpacket {
length: 9.into(),
critical: false,
- tag: SubpacketTag::Issuer,
value: SubpacketValue::Issuer(keyid)
}));
@@ -3099,7 +3064,6 @@ fn subpacket_test_2() {
Some(&Subpacket {
length: 22.into(),
critical: false,
- tag: SubpacketTag::IssuerFingerprint,
value: SubpacketValue::IssuerFingerprint(fp)
}));
diff --git a/openpgp/src/parse/parse.rs b/openpgp/src/parse/parse.rs
index 9c08867a..9b58d495 100644
--- a/openpgp/src/parse/parse.rs
+++ b/openpgp/src/parse/parse.rs
@@ -1426,9 +1426,8 @@ impl Subpacket {
len, total_out - total_out_before)).into());
}
- Ok(Subpacket::with_length_tag(
+ Ok(Subpacket::with_length(
length,
- tag,
value,
critical,
))