From 67b719cb2347776471966a645f6c489dc7244425 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Thu, 27 Dec 2018 18:30:15 +0100 Subject: openpgp: Add tests. --- openpgp/src/tpk/mod.rs | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'openpgp') diff --git a/openpgp/src/tpk/mod.rs b/openpgp/src/tpk/mod.rs index 0cbf81bb..d3360f63 100644 --- a/openpgp/src/tpk/mod.rs +++ b/openpgp/src/tpk/mod.rs @@ -1293,6 +1293,32 @@ impl TPK { } /// Returns a revocation certificate for the TPK. + /// + /// # Example + /// + /// ```rust + /// # extern crate sequoia_openpgp as openpgp; + /// # use openpgp::Result; + /// use openpgp::RevocationStatus; + /// use openpgp::constants::{{ReasonForRevocation, SignatureType}}; + /// use openpgp::tpk::{{CipherSuite, TPKBuilder}}; + /// use openpgp::parse::Parse; + /// # fn main() { f().unwrap(); } + /// # fn f() -> Result<()> + /// # { + /// let (tpk, _) = TPKBuilder::default() + /// .set_cipher_suite(CipherSuite::Cv25519) + /// .generate()?; + /// assert_eq!(RevocationStatus::NotAsFarAsWeKnow, tpk.revoked()); + /// + /// let sig = tpk.revoke(ReasonForRevocation::KeyCompromised, + /// b"It was the maid :/")?; + /// assert_eq!(sig.sigtype(), SignatureType::KeyRevocation); + /// + /// let tpk = tpk.merge_packets(vec![sig.clone().to_packet()])?; + /// assert_eq!(RevocationStatus::Revoked(&[sig]), tpk.revoked()); + /// # Ok(()) + /// # } pub fn revoke(&self, code: ReasonForRevocation, reason: &[u8]) -> Result { @@ -1319,6 +1345,38 @@ impl TPK { } /// Revokes the TPK. + /// + /// # Example + /// + /// ```rust + /// # extern crate sequoia_openpgp as openpgp; + /// # use openpgp::Result; + /// use openpgp::RevocationStatus; + /// use openpgp::constants::{{ReasonForRevocation, SignatureType}}; + /// use openpgp::tpk::{{CipherSuite, TPKBuilder}}; + /// use openpgp::parse::Parse; + /// # fn main() { f().unwrap(); } + /// # fn f() -> Result<()> + /// # { + /// let (mut tpk, _) = TPKBuilder::default() + /// .set_cipher_suite(CipherSuite::Cv25519) + /// .generate()?; + /// assert_eq!(RevocationStatus::NotAsFarAsWeKnow, tpk.revoked()); + /// + /// let tpk = tpk.revoke_in_place(ReasonForRevocation::KeyCompromised, + /// b"It was the maid :/")?; + /// if let RevocationStatus::Revoked(sigs) = tpk.revoked() { + /// assert_eq!(sigs.len(), 1); + /// assert_eq!(sigs[0].sigtype(), SignatureType::KeyRevocation); + /// assert_eq!(sigs[0].reason_for_revocation(), + /// Some((ReasonForRevocation::KeyCompromised, + /// &b"It was the maid :/"[..]))); + /// } else { + /// unreachable!() + /// } + /// # Ok(()) + /// # } + /// ``` pub fn revoke_in_place(self, code: ReasonForRevocation, reason: &[u8]) -> Result { -- cgit v1.2.3