summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-10-01 15:04:39 +0200
committerJustus Winter <justus@sequoia-pgp.org>2020-10-02 15:09:11 +0200
commit5a7005bc3d4c86db7f35ed942fd12f1487e4fe8b (patch)
tree95ac05c26a8aef385c1c24b9734361165e691dce
parent354410284a549b17292bc210d41acff6049de696 (diff)
openpgp: Add SubpacketAreas::embedded_signature_mut.
-rw-r--r--openpgp/src/packet/signature/subpacket.rs36
1 files changed, 35 insertions, 1 deletions
diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs
index 676ad3d3..baca8425 100644
--- a/openpgp/src/packet/signature/subpacket.rs
+++ b/openpgp/src/packet/signature/subpacket.rs
@@ -3379,7 +3379,7 @@ impl SubpacketAreas {
}
}
- /// Returns the value of the Embedded Signature subpacket.
+ /// Returns a reference to the Embedded Signature subpacket.
///
/// The [Embedded Signature subpacket] is normally used to hold a
/// [Primary Key Binding signature], which binds a
@@ -3412,6 +3412,40 @@ impl SubpacketAreas {
}
}
+ /// Returns a mutable reference to the Embedded Signature
+ /// subpacket.
+ ///
+ /// The [Embedded Signature subpacket] is normally used to hold a
+ /// [Primary Key Binding signature], which binds a
+ /// signing-capable, authentication-capable, or
+ /// certification-capable subkey to the primary key. Since this
+ /// information is self-authenticating, it is usually stored in
+ /// the unhashed subpacket area.
+ ///
+ /// [Embedded Signature subpacket]: https://tools.ietf.org/html/rfc4880#section-5.2.3.26
+ /// [Primary Key Binding signature]: https://tools.ietf.org/html/rfc4880#section-5.2.1
+ ///
+ /// If the subpacket is not present in the hashed subpacket area
+ /// or in the unhashed subpacket area, this returns `None`.
+ ///
+ /// Note: if the signature contains multiple instances of this
+ /// subpacket in the hashed subpacket area, the last one is
+ /// returned. Otherwise, the last one is returned from the
+ /// unhashed subpacket area.
+ pub fn embedded_signature_mut(&mut self) -> Option<&mut Signature> {
+ // 1 signature packet body
+ if let Some(sb)
+ = self.subpacket_mut(SubpacketTag::EmbeddedSignature) {
+ if let SubpacketValue::EmbeddedSignature(v) = &mut sb.value {
+ Some(v)
+ } else {
+ None
+ }
+ } else {
+ None
+ }
+ }
+
/// Returns the intended recipients.
///
/// The [Intended Recipient subpacket] holds the fingerprint of a