summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2023-03-23 17:46:26 +0100
committerJustus Winter <justus@sequoia-pgp.org>2023-03-24 10:08:31 +0100
commitb0b716b8910c220703734313e11f0bf01aa2e315 (patch)
tree6b902cd15a4a0cad456c73da02d1d430b0687875
parent301ad2858cf43b06f398214d87c8b5bf24dffa79 (diff)
openpgp: Provide a common public SymmetricAlgorithm::is_supported.
-rw-r--r--openpgp/src/crypto/backend/botan/symmetric.rs18
-rw-r--r--openpgp/src/crypto/backend/cng/symmetric.rs18
-rw-r--r--openpgp/src/crypto/backend/nettle/symmetric.rs18
-rw-r--r--openpgp/src/crypto/backend/openssl/symmetric.rs18
-rw-r--r--openpgp/src/crypto/backend/rust/symmetric.rs18
-rw-r--r--openpgp/src/types/mod.rs20
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<SymmetricAlgorithm> 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.