From ed740f824abd7159f30bf9deaee2a6023432ba31 Mon Sep 17 00:00:00 2001 From: "Neal H. Walfield" Date: Fri, 31 Jul 2020 18:30:06 +0200 Subject: openpgp: Make it easier to add an Intended Recipient. - `SignatureBuilder::set_intended_recipients` sets multiple Intended Recipient subpackets at once. However, if we want to build the intended recipients gradually, it is not appropriate: it first clears any existing Intended Recipient subpackets. - Add `SignatureBuilder::add_intended_recipient` to add an Intended Recipient subpacket without first clearing any existing Intended Recipient subpackets. --- openpgp/src/packet/signature/subpacket.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs index 4d33377b..a67cf7d0 100644 --- a/openpgp/src/packet/signature/subpacket.rs +++ b/openpgp/src/packet/signature/subpacket.rs @@ -2888,6 +2888,26 @@ impl signature::SignatureBuilder { Ok(self) } + + /// Adds an Intended Recipient subpacket. + /// + /// Adds any [Intended Recipient subpacket] to the hashed + /// subpacket area. Unlike [`set_intended_recipients`], this + /// function does not first removes any Intended Recipient + /// subpackets from the hashed subpacket area. + /// + /// [Intended Recipient subpacket]: https://www.ietf.org/id/draft-ietf-openpgp-rfc4880bis-09.html#section-5.2.3.29 + /// [`set_intended_recipients`]: #method.set_intended_recipients + pub fn add_intended_recipient(mut self, recipient: T) + -> Result + where T: AsRef + { + self.hashed_area.add( + Subpacket::new(SubpacketValue::IntendedRecipient( + recipient.as_ref().clone()), false)?)?; + + Ok(self) + } } #[test] -- cgit v1.2.3