summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2020-08-12 10:55:01 +0200
committerNeal H. Walfield <neal@pep.foundation>2020-08-12 13:09:39 +0200
commit8c1efceea2207352a2780d581c12cd867f22587d (patch)
tree6214f94dba269fd4dd57620238d9aaca6251ecaf
parenteb2d6fdf9bf4dcfc245abd60a07517648a139c7d (diff)
openpgp: Move accessors from SubpacketArea to SubpacketAreas
- `SubpacketAreas`'s high-level subpacket accessors implement routing. For instance, `SubpacketAreas::embedded_signature` first looks for the `Embedded Signature` subpacket in the hashed subpacket area, and, if it is not found there, it falls back to the unhashed subpacket area. In contrast, `SubpacketAreas::signature_creation_time` only looks for the `Signature Creation Time` subpacket in the hashed subpacket area. - This is potentially confusing. `SubpacketArea` also implements the `embedded_signature` accessor and the `signature_creation_time` accessor. They only look in the associated subpacket area. That is, `SubpacketArea::embedded_signature` only looks in the selected subpacket area, not both. And, `SubpacketArea::signature_creation_time` may look in the "wrong" subpacket area: if the `Signature Creation Time` subpacket occurs in the the unhashed subpacket area, it should normally be ignored. - Instead, only provide high-level accessors for `SubpacketAreas`. - If necessary, it is still possible to work with an individual SubpacketArea using `SubpacketArea::lookup`, etc.
-rw-r--r--openpgp/src/packet/signature/subpacket.rs76
1 files changed, 4 insertions, 72 deletions
diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs
index 6945b8a3..214a33cd 100644
--- a/openpgp/src/packet/signature/subpacket.rs
+++ b/openpgp/src/packet/signature/subpacket.rs
@@ -1143,7 +1143,9 @@ impl SubpacketArea {
-> impl Iterator<Item = &Subpacket> {
self.iter().filter(move |sp| sp.tag() == target)
}
+}
+impl SubpacketAreas {
/// Returns the value of the Creation Time subpacket, which
/// contains the time when the signature was created as a unix
/// timestamp.
@@ -1852,7 +1854,7 @@ impl SubpacketAreas {
/// Returns the *last* instance of the specified subpacket.
fn subpacket<'a>(&'a self, tag: SubpacketTag) -> Option<&Subpacket> {
- if let Some(sb) = self.hashed_area().lookup(tag) {
+ if let Some(sb) = self.hashed_area().subpacket(tag) {
return Some(sb);
}
@@ -1865,7 +1867,7 @@ impl SubpacketAreas {
return None;
}
- self.unhashed_area().lookup(tag)
+ self.unhashed_area().subpacket(tag)
}
@@ -2014,76 +2016,6 @@ impl SubpacketAreas {
_ => Ok(()),
}
}
-
- /// Returns the value of the Issuer subpacket, which contains the
- /// KeyID of the key that allegedly created this signature.
- ///
- /// If the subpacket is not present, this returns `None`.
- ///
- /// Note: if the signature contains multiple instances of this
- /// subpacket, only the last one is considered.
- pub fn issuer(&self) -> Option<&KeyID> {
- // 8-octet Key ID
- if let Some(sb)
- = self.subpacket(SubpacketTag::Issuer) {
- if let SubpacketValue::Issuer(v) = &sb.value {
- Some(v)
- } else {
- None
- }
- } else {
- None
- }
- }
-
- /// Returns the value of the Embedded Signature subpacket, which
- /// contains a signature.
- ///
- /// This is used, for instance, to store a subkey's primary key
- /// binding signature (0x19).
- ///
- /// If the subpacket is not present, this returns `None`.
- ///
- /// Note: if the signature contains multiple instances of this
- /// subpacket, only the last one is considered.
- pub fn embedded_signature(&self) -> Option<&Signature> {
- // 1 signature packet body
- if let Some(sb)
- = self.subpacket(SubpacketTag::EmbeddedSignature) {
- if let SubpacketValue::EmbeddedSignature(v) = &sb.value {
- Some(v)
- } else {
- None
- }
- } else {
- None
- }
- }
-
- /// Returns the value of the Issuer Fingerprint subpacket, which
- /// contains the fingerprint of the key that allegedly created
- /// this signature.
- ///
- /// This subpacket should be preferred to the Issuer subpacket,
- /// because Fingerprints are not subject to collisions.
- ///
- /// If the subpacket is not present, this returns `None`.
- ///
- /// Note: if the signature contains multiple instances of this
- /// subpacket, only the last one is considered.
- pub fn issuer_fingerprint(&self) -> Option<&Fingerprint> {
- // 1 octet key version number, N octets of fingerprint
- if let Some(sb)
- = self.subpacket(SubpacketTag::IssuerFingerprint) {
- if let SubpacketValue::IssuerFingerprint(v) = &sb.value {
- Some(v)
- } else {
- None
- }
- } else {
- None
- }
- }
}
impl TryFrom<Signature> for Signature4 {