From 08b8cd56a6b97e7d9f60a5835ebd305b1049ca5f Mon Sep 17 00:00:00 2001 From: Nora Widdecke Date: Tue, 12 Oct 2021 11:49:29 +0200 Subject: openpgp: Add notations to CertRevocationBuilder. --- openpgp/src/cert/revoke.rs | 81 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/openpgp/src/cert/revoke.rs b/openpgp/src/cert/revoke.rs index 7ecb5787..72f9661c 100644 --- a/openpgp/src/cert/revoke.rs +++ b/openpgp/src/cert/revoke.rs @@ -19,6 +19,7 @@ use crate::packet::{ UserAttribute, UserID, }; +use crate::packet::signature::subpacket::NotationDataFlags; use crate::cert::prelude::*; /// A builder for revocation certificates for OpenPGP certificates. @@ -183,6 +184,86 @@ impl CertRevocationBuilder { }) } + /// Adds a notation to the revocation certificate. + /// + /// Unlike the [`CertRevocationBuilder::set_notation`] method, this function + /// does not first remove any existing notation with the specified name. + /// + /// See [`SignatureBuilder::add_notation`] for further documentation. + /// + /// [`SignatureBuilder::add_notation`]: crate::packet::signature::SignatureBuilder::add_notation() + /// + /// # Examples + /// + /// ```rust + /// use sequoia_openpgp as openpgp; + /// # use openpgp::Result; + /// use openpgp::cert::prelude::*; + /// use openpgp::packet::signature::subpacket::NotationDataFlags; + /// + /// # fn main() -> Result<()> { + /// + /// let builder = CertRevocationBuilder::new().add_notation( + /// "notation_name", + /// &[0; 8], + /// NotationDataFlags::empty().set_human_readable(), + /// false, + /// ); + /// # Ok(()) + /// # } + pub fn add_notation(self, name: N, value: V, flags: F, + critical: bool) + -> Result + where + N: AsRef, + V: AsRef<[u8]>, + F: Into>, + { + Ok(Self { + builder: self.builder.add_notation(name, value, flags, critical)? + }) + } + + /// Sets a notation to the revocation certificate. + /// + /// Unlike the [`CertRevocationBuilder::add_notation`] method, this function + /// first removes any existing notation with the specified name. + /// + /// See [`SignatureBuilder::set_notation`] for further documentation. + /// + /// [`SignatureBuilder::set_notation`]: crate::packet::signature::SignatureBuilder::set_notation() + /// + /// # Examples + /// + /// ```rust + /// use sequoia_openpgp as openpgp; + /// # use openpgp::Result; + /// use openpgp::cert::prelude::*; + /// use openpgp::packet::signature::subpacket::NotationDataFlags; + /// + /// # fn main() -> Result<()> { + /// + /// let builder = CertRevocationBuilder::new().set_notation( + /// "notation_name", + /// &[0; 8], + /// NotationDataFlags::empty().set_human_readable(), + /// false, + /// ); + /// # Ok(()) + /// # } + pub fn set_notation(self, name: N, value: V, flags: F, + critical: bool) + -> Result + where + N: AsRef, + V: AsRef<[u8]>, + F: Into>, + { + Ok(Self { + builder: self.builder.set_notation(name, value, flags, critical)? + }) + } + /// Returns a signed revocation certificate. /// /// A revocation certificate is generated for `cert` and signed -- cgit v1.2.3