From 9a34a60df931358d35ea88c32afe3f044548d3c0 Mon Sep 17 00:00:00 2001 From: "Neal H. Walfield" Date: Fri, 31 Jul 2020 17:43:30 +0200 Subject: openpgp: Add variants to SignatureBuilder to add issuer subpackets. - `SignatureBuilder::set_issuer` and `SignatureBuilder::set_issuer_fingerprint` first clear the unhashed area of any existing Issuer or Issuer Fingerprint subpackets, respectively. - Add a variant to add an additional Issuer or Issuer Fingerprint subpacket. --- openpgp/src/packet/signature/subpacket.rs | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs index 158202ee..4d33377b 100644 --- a/openpgp/src/packet/signature/subpacket.rs +++ b/openpgp/src/packet/signature/subpacket.rs @@ -2595,6 +2595,25 @@ impl signature::SignatureBuilder { Ok(self) } + /// Adds an Issuer subpacket. + /// + /// Adds an [Issuer subpacket] to the unhashed subpacket area. + /// Unlike [`set_issuer`], this function does not first remove any + /// Issuer subpackets from the unhashed subpacket area. + /// + /// Caution: By default, the issuer is set correctly when creating + /// the signature. Only use this function to override it. + /// + /// [Issuer subpacket]: https://tools.ietf.org/html/rfc4880#section-5.2.3.5 + /// [`set_issuer`]: #method.set_issuer + pub fn add_issuer(mut self, id: KeyID) -> Result { + self.unhashed_area.add(Subpacket::new( + SubpacketValue::Issuer(id), + false)?)?; + + Ok(self) + } + /// Sets the value of the Notation Data subpacket with the given /// name. /// @@ -2828,6 +2847,23 @@ impl signature::SignatureBuilder { Ok(self) } + /// Adds an Issuer Fingerprint subpacket. + /// + /// Adds an [Issuer Fingerprint subpacket] to the unhashed + /// subpacket area. Unlike [`set_issuer_fingerprint`], this + /// function does not first remove any existing Issuer Fingerprint + /// subpackets from the unhashed subpacket area. + /// + /// [Issuer Fingerprint subpacket]: https://www.ietf.org/id/draft-ietf-openpgp-rfc4880bis-09.html#section-5.2.3.28 + /// [`set_issuer_fingerprint`]: #method.set_issuer_fingerprint + pub fn add_issuer_fingerprint(mut self, fp: Fingerprint) -> Result { + self.unhashed_area.add(Subpacket::new( + SubpacketValue::IssuerFingerprint(fp), + false)?)?; + + Ok(self) + } + /// Sets the value of the Preferred AEAD Algorithms subpacket, /// which contains the list of AEAD algorithms that the key holder /// prefers, ordered according by the key holder's preference. -- cgit v1.2.3