diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2023-08-22 10:08:49 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2023-08-22 10:35:29 +0200 |
commit | 8f540a2d4e705e36892a900401674c102de3ab28 (patch) | |
tree | b153b0674cf506c5ffdba97d1df52c79729a141a | |
parent | a4dc34fc6574fa333067bdafe772071240e688ed (diff) |
openpgp: Add the SEIPDv2 feature.
-rw-r--r-- | openpgp/NEWS | 1 | ||||
-rw-r--r-- | openpgp/src/packet/signature/subpacket.rs | 2 | ||||
-rw-r--r-- | openpgp/src/types/features.rs | 80 |
3 files changed, 80 insertions, 3 deletions
diff --git a/openpgp/NEWS b/openpgp/NEWS index 4b24313f..4bb624e3 100644 --- a/openpgp/NEWS +++ b/openpgp/NEWS @@ -7,6 +7,7 @@ ** New functionality - types::AEADAlgorithm::GCM - types::Features::{clear,set,supports}_seipdv1 + - types::Features::{clear,set,supports}_seipdv2 ** Deprecated functionality - types::Features::{clear,set,supports}_mdc * Changes in 1.16.0 diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs index 3d324fb0..0c37145f 100644 --- a/openpgp/src/packet/signature/subpacket.rs +++ b/openpgp/src/packet/signature/subpacket.rs @@ -7284,7 +7284,7 @@ fn accessors() { sig.clone().sign_hash(&mut keypair, hash.clone()).unwrap(); assert_eq!(sig_.features().unwrap(), feats); - let feats = Features::empty().set_aead(); + let feats = Features::empty().set_seipdv2(); sig = sig.set_features(feats.clone()).unwrap(); let sig_ = sig.clone().sign_hash(&mut keypair, hash.clone()).unwrap(); diff --git a/openpgp/src/types/features.rs b/openpgp/src/types/features.rs index ebda6821..24f18842 100644 --- a/openpgp/src/types/features.rs +++ b/openpgp/src/types/features.rs @@ -8,10 +8,10 @@ use crate::types::Bitfield; /// Describes the features supported by an OpenPGP implementation. /// /// The feature flags are defined in [Section 5.2.3.24 of RFC 4880], -/// and [Section 5.2.3.25 of RFC 4880bis]. +/// and [Section 5.2.3.32 of draft-ietf-openpgp-crypto-refresh]. /// /// [Section 5.2.3.24 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-5.2.3.24 -/// [Section 5.2.3.25 of RFC 4880bis]: https://tools.ietf.org/html/draft-ietf-openpgp-rfc4880bis-09#section-5.2.3.25 +/// [Section 5.2.3.32 of draft-ietf-openpgp-crypto-refresh]: https://www.ietf.org/archive/id/draft-ietf-openpgp-crypto-refresh-10.html#features-subpacket /// /// The feature flags are set by the user's OpenPGP implementation to /// signal to any senders what features the implementation supports. @@ -65,6 +65,11 @@ impl fmt::Debug for Features { f.write_str("SEIPDv1")?; need_comma = true; } + if self.supports_seipdv2() { + if need_comma { f.write_str(", ")?; } + f.write_str("SEIPDv2")?; + need_comma = true; + } if self.supports_aead() { if need_comma { f.write_str(", ")?; } f.write_str("AEAD")?; @@ -75,6 +80,7 @@ impl fmt::Debug for Features { for i in self.0.iter() { match i { FEATURE_FLAG_SEIPDV1 => (), + FEATURE_FLAG_SEIPDV2 => (), FEATURE_FLAG_AEAD => (), i => { if need_comma { f.write_str(", ")?; } @@ -116,6 +122,7 @@ impl Features { Self::new(&v[..]) .set_seipdv1() + .set_seipdv2() } /// Compares two feature sets for semantic equality. @@ -307,6 +314,66 @@ impl Features { self.clear_seipdv1() } + /// Returns whether the SEIPDv2 feature flag is set. + /// + /// # Examples + /// + /// ``` + /// use sequoia_openpgp as openpgp; + /// # use openpgp::Result; + /// use openpgp::types::Features; + /// + /// # fn main() -> Result<()> { + /// let f = Features::empty(); + /// + /// assert!(! f.supports_seipdv2()); + /// # Ok(()) } + /// ``` + pub fn supports_seipdv2(&self) -> bool { + self.get(FEATURE_FLAG_SEIPDV2) + } + + /// Sets the SEIPDv2 feature flag. + /// + /// # Examples + /// + /// ``` + /// use sequoia_openpgp as openpgp; + /// # use openpgp::Result; + /// use openpgp::types::Features; + /// + /// # fn main() -> Result<()> { + /// let f = Features::empty().set_seipdv2(); + /// + /// assert!(f.supports_seipdv2()); + /// # assert!(f.get(3)); + /// # Ok(()) } + /// ``` + pub fn set_seipdv2(self) -> Self { + self.set(FEATURE_FLAG_SEIPDV2) + } + + /// Clears the SEIPDv2 feature flag. + /// + /// # Examples + /// + /// ``` + /// use sequoia_openpgp as openpgp; + /// # use openpgp::Result; + /// use openpgp::types::Features; + /// + /// # fn main() -> Result<()> { + /// let f = Features::new(&[0x8]); + /// assert!(f.supports_seipdv2()); + /// + /// let f = f.clear_seipdv2(); + /// assert!(! f.supports_seipdv2()); + /// # Ok(()) } + /// ``` + pub fn clear_seipdv2(self) -> Self { + self.clear(FEATURE_FLAG_SEIPDV2) + } + /// Returns whether the AEAD feature flag is set. /// /// # Examples @@ -376,6 +443,10 @@ const FEATURE_FLAG_SEIPDV1: usize = 0; /// Encrypted Session Key Packets (packet 3). const FEATURE_FLAG_AEAD: usize = 1; +/// Symmetrically Encrypted and Integrity Protected Data packet +/// version 2. +const FEATURE_FLAG_SEIPDV2: usize = 3; + #[cfg(test)] impl Arbitrary for Features { fn arbitrary(g: &mut Gen) -> Self { @@ -467,6 +538,11 @@ mod tests { assert_eq!(a, b); assert!(a.normalized_eq(&b)); + let a = Features::empty().set_seipdv2(); + let b = Features::new(&[ 0x8 ]); + assert_eq!(a, b); + assert!(a.normalized_eq(&b)); + let a = Features::empty().set_aead(); let b = Features::new(&[ 0x2 ]); assert_eq!(a, b); |