From b0b716b8910c220703734313e11f0bf01aa2e315 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Thu, 23 Mar 2023 17:46:26 +0100 Subject: openpgp: Provide a common public SymmetricAlgorithm::is_supported. --- openpgp/src/crypto/backend/botan/symmetric.rs | 18 +----------------- openpgp/src/crypto/backend/cng/symmetric.rs | 18 +----------------- openpgp/src/crypto/backend/nettle/symmetric.rs | 18 +----------------- openpgp/src/crypto/backend/openssl/symmetric.rs | 18 +----------------- openpgp/src/crypto/backend/rust/symmetric.rs | 18 +----------------- openpgp/src/types/mod.rs | 20 ++++++++++++++++++++ 6 files changed, 25 insertions(+), 85 deletions(-) diff --git a/openpgp/src/crypto/backend/botan/symmetric.rs b/openpgp/src/crypto/backend/botan/symmetric.rs index 759d3f4f..729f7196 100644 --- a/openpgp/src/crypto/backend/botan/symmetric.rs +++ b/openpgp/src/crypto/backend/botan/symmetric.rs @@ -49,23 +49,7 @@ impl Mode for Cfb { impl SymmetricAlgorithm { /// Returns whether this algorithm is supported by the crypto backend. - /// - /// All backends support all the AES variants. - /// - /// # Examples - /// - /// ```rust - /// use sequoia_openpgp as openpgp; - /// use openpgp::types::SymmetricAlgorithm; - /// - /// assert!(SymmetricAlgorithm::AES256.is_supported()); - /// assert!(SymmetricAlgorithm::TripleDES.is_supported()); - /// - /// assert!(SymmetricAlgorithm::IDEA.is_supported()); - /// assert!(!SymmetricAlgorithm::Unencrypted.is_supported()); - /// assert!(!SymmetricAlgorithm::Private(101).is_supported()); - /// ``` - pub fn is_supported(&self) -> bool { + pub(crate) fn is_supported_by_backend(&self) -> bool { use self::SymmetricAlgorithm::*; match &self { TripleDES | IDEA | CAST5 | Blowfish | diff --git a/openpgp/src/crypto/backend/cng/symmetric.rs b/openpgp/src/crypto/backend/cng/symmetric.rs index 481a5404..baa92191 100644 --- a/openpgp/src/crypto/backend/cng/symmetric.rs +++ b/openpgp/src/crypto/backend/cng/symmetric.rs @@ -110,23 +110,7 @@ impl TryFrom for (cng::SymmetricAlgorithmId, usize) { impl SymmetricAlgorithm { /// Returns whether this algorithm is supported by the crypto backend. - /// - /// All backends support all the AES variants. - /// - /// # Examples - /// - /// ```rust - /// use sequoia_openpgp as openpgp; - /// use openpgp::types::SymmetricAlgorithm; - /// - /// assert!(SymmetricAlgorithm::AES256.is_supported()); - /// assert!(SymmetricAlgorithm::TripleDES.is_supported()); - /// - /// assert!(!SymmetricAlgorithm::IDEA.is_supported()); - /// assert!(!SymmetricAlgorithm::Unencrypted.is_supported()); - /// assert!(!SymmetricAlgorithm::Private(101).is_supported()); - /// ``` - pub fn is_supported(&self) -> bool { + pub(crate) fn is_supported_by_backend(&self) -> bool { use self::SymmetricAlgorithm::*; match self { AES128 | AES192 | AES256 | TripleDES => true, diff --git a/openpgp/src/crypto/backend/nettle/symmetric.rs b/openpgp/src/crypto/backend/nettle/symmetric.rs index 2b3c9f1b..f4b476f3 100644 --- a/openpgp/src/crypto/backend/nettle/symmetric.rs +++ b/openpgp/src/crypto/backend/nettle/symmetric.rs @@ -82,23 +82,7 @@ where impl SymmetricAlgorithm { /// Returns whether this algorithm is supported by the crypto backend. - /// - /// All backends support all the AES variants. - /// - /// # Examples - /// - /// ```rust - /// use sequoia_openpgp as openpgp; - /// use openpgp::types::SymmetricAlgorithm; - /// - /// assert!(SymmetricAlgorithm::AES256.is_supported()); - /// assert!(SymmetricAlgorithm::TripleDES.is_supported()); - /// - /// assert!(!SymmetricAlgorithm::IDEA.is_supported()); - /// assert!(!SymmetricAlgorithm::Unencrypted.is_supported()); - /// assert!(!SymmetricAlgorithm::Private(101).is_supported()); - /// ``` - pub fn is_supported(&self) -> bool { + pub(crate) fn is_supported_by_backend(&self) -> bool { use self::SymmetricAlgorithm::*; match &self { TripleDES | CAST5 | Blowfish | AES128 | AES192 | AES256 | Twofish diff --git a/openpgp/src/crypto/backend/openssl/symmetric.rs b/openpgp/src/crypto/backend/openssl/symmetric.rs index aa2cff01..60522a32 100644 --- a/openpgp/src/crypto/backend/openssl/symmetric.rs +++ b/openpgp/src/crypto/backend/openssl/symmetric.rs @@ -60,23 +60,7 @@ impl Mode for OpenSslMode { impl SymmetricAlgorithm { /// Returns whether this algorithm is supported by the crypto backend. - /// - /// All backends support all the AES variants. - /// - /// # Examples - /// - /// ```rust - /// use sequoia_openpgp as openpgp; - /// use openpgp::types::SymmetricAlgorithm; - /// - /// assert!(SymmetricAlgorithm::AES256.is_supported()); - /// assert!(SymmetricAlgorithm::TripleDES.is_supported()); - /// - /// assert!(!SymmetricAlgorithm::Twofish.is_supported()); - /// assert!(!SymmetricAlgorithm::Unencrypted.is_supported()); - /// assert!(!SymmetricAlgorithm::Private(101).is_supported()); - /// ``` - pub fn is_supported(&self) -> bool { + pub(crate) fn is_supported_by_backend(&self) -> bool { let cipher: &CipherRef = if let Ok(cipher) = (*self).make_cfb_cipher() { cipher } else { diff --git a/openpgp/src/crypto/backend/rust/symmetric.rs b/openpgp/src/crypto/backend/rust/symmetric.rs index c419dbc3..160cdb4f 100644 --- a/openpgp/src/crypto/backend/rust/symmetric.rs +++ b/openpgp/src/crypto/backend/rust/symmetric.rs @@ -79,23 +79,7 @@ where impl SymmetricAlgorithm { /// Returns whether this algorithm is supported by the crypto backend. - /// - /// All backends support all the AES variants. - /// - /// # Examples - /// - /// ```rust - /// use sequoia_openpgp as openpgp; - /// use openpgp::types::SymmetricAlgorithm; - /// - /// assert!(SymmetricAlgorithm::AES256.is_supported()); - /// assert!(SymmetricAlgorithm::TripleDES.is_supported()); - /// assert!(SymmetricAlgorithm::IDEA.is_supported()); - /// - /// assert!(!SymmetricAlgorithm::Unencrypted.is_supported()); - /// assert!(!SymmetricAlgorithm::Private(101).is_supported()); - /// ``` - pub fn is_supported(&self) -> bool { + pub(crate) fn is_supported_by_backend(&self) -> bool { use SymmetricAlgorithm::*; match self { IDEA => true, diff --git a/openpgp/src/types/mod.rs b/openpgp/src/types/mod.rs index eca26d92..8402655d 100644 --- a/openpgp/src/types/mod.rs +++ b/openpgp/src/types/mod.rs @@ -863,6 +863,26 @@ impl SymmetricAlgorithm { SYMMETRIC_ALGORITHM_VARIANTS.iter().cloned() } + /// Returns whether this algorithm is supported by the crypto backend. + /// + /// All backends support all the AES variants. + /// + /// # Examples + /// + /// ```rust + /// use sequoia_openpgp as openpgp; + /// use openpgp::types::SymmetricAlgorithm; + /// + /// assert!(SymmetricAlgorithm::AES256.is_supported()); + /// assert!(SymmetricAlgorithm::TripleDES.is_supported()); + /// + /// assert!(!SymmetricAlgorithm::Unencrypted.is_supported()); + /// assert!(!SymmetricAlgorithm::Private(101).is_supported()); + /// ``` + pub fn is_supported(&self) -> bool { + self.is_supported_by_backend() + } + /// Length of a key for this algorithm in bytes. /// /// Fails if the algorithm isn't known to Sequoia. -- cgit v1.2.3