summaryrefslogtreecommitdiffstats
path: root/openpgp
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2021-09-09 15:14:20 +0200
committerJustus Winter <justus@sequoia-pgp.org>2021-09-16 12:51:19 +0200
commite939ea0fbc206856709955fe1937ff635749d4e7 (patch)
treeb4dab6c9d3fe2b9ed4bf4758f0a7fb9cca7ede71 /openpgp
parent794d128c704934e828302a7f02df66c72fe7819e (diff)
openpgp: Make list of supported algorithms backend-dependent.
Diffstat (limited to 'openpgp')
-rw-r--r--openpgp/src/crypto/backend/cng.rs39
-rw-r--r--openpgp/src/crypto/backend/nettle.rs39
-rw-r--r--openpgp/src/types/mod.rs25
3 files changed, 81 insertions, 22 deletions
diff --git a/openpgp/src/crypto/backend/cng.rs b/openpgp/src/crypto/backend/cng.rs
index 9947f3a2..8bf01b02 100644
--- a/openpgp/src/crypto/backend/cng.rs
+++ b/openpgp/src/crypto/backend/cng.rs
@@ -1,5 +1,7 @@
//! Implementation of crypto primitives using the Windows CNG (Cryptographic API: Next Generation).
+use crate::types::*;
+
use win_crypto_ng::random::RandomNumberGenerator;
pub mod aead;
@@ -14,3 +16,40 @@ pub fn random<B: AsMut<[u8]>>(mut buf: B) {
.gen_random(buf.as_mut())
.expect("system-preferred RNG not to fail")
}
+
+impl PublicKeyAlgorithm {
+ pub(crate) fn is_supported_by_backend(&self) -> bool {
+ use PublicKeyAlgorithm::*;
+ #[allow(deprecated)]
+ match &self {
+ RSAEncryptSign | RSAEncrypt | RSASign | DSA | ECDH | ECDSA | EdDSA
+ => true,
+ ElGamalEncrypt | ElGamalEncryptSign | Private(_) | Unknown(_)
+ => false,
+ }
+ }
+}
+
+impl Curve {
+ pub(crate) fn is_supported_by_backend(&self) -> bool {
+ use self::Curve::*;
+ match &self {
+ NistP256 | NistP384 | NistP521 | Ed25519 | Cv25519
+ => true,
+ BrainpoolP256 | BrainpoolP512 | Unknown(_)
+ => false,
+ }
+ }
+}
+
+impl AEADAlgorithm {
+ pub(crate) fn is_supported_by_backend(&self) -> bool {
+ use self::AEADAlgorithm::*;
+ match &self {
+ EAX
+ => true,
+ OCB | Private(_) | Unknown(_)
+ => false,
+ }
+ }
+}
diff --git a/openpgp/src/crypto/backend/nettle.rs b/openpgp/src/crypto/backend/nettle.rs
index a07e7824..9bf737c0 100644
--- a/openpgp/src/crypto/backend/nettle.rs
+++ b/openpgp/src/crypto/backend/nettle.rs
@@ -1,5 +1,7 @@
//! Implementation of Sequoia crypto API using the Nettle cryptographic library.
+use crate::types::*;
+
use nettle::random::{Random, Yarrow};
pub mod aead;
@@ -20,3 +22,40 @@ pub mod symmetric;
pub fn random<B: AsMut<[u8]>>(mut buf: B) {
Yarrow::default().random(buf.as_mut());
}
+
+impl PublicKeyAlgorithm {
+ pub(crate) fn is_supported_by_backend(&self) -> bool {
+ use PublicKeyAlgorithm::*;
+ #[allow(deprecated)]
+ match &self {
+ RSAEncryptSign | RSAEncrypt | RSASign | DSA | ECDH | ECDSA | EdDSA
+ => true,
+ ElGamalEncrypt | ElGamalEncryptSign | Private(_) | Unknown(_)
+ => false,
+ }
+ }
+}
+
+impl Curve {
+ pub(crate) fn is_supported_by_backend(&self) -> bool {
+ use self::Curve::*;
+ match &self {
+ NistP256 | NistP384 | NistP521 | Ed25519 | Cv25519
+ => true,
+ BrainpoolP256 | BrainpoolP512 | Unknown(_)
+ => false,
+ }
+ }
+}
+
+impl AEADAlgorithm {
+ pub(crate) fn is_supported_by_backend(&self) -> bool {
+ use self::AEADAlgorithm::*;
+ match &self {
+ EAX
+ => true,
+ OCB | Private(_) | Unknown(_)
+ => false,
+ }
+ }
+}
diff --git a/openpgp/src/types/mod.rs b/openpgp/src/types/mod.rs
index 750ef2ca..09b79f9d 100644
--- a/openpgp/src/types/mod.rs
+++ b/openpgp/src/types/mod.rs
@@ -195,14 +195,7 @@ impl PublicKeyAlgorithm {
/// assert!(!PublicKeyAlgorithm::Private(101).is_supported());
/// ```
pub fn is_supported(&self) -> bool {
- use self::PublicKeyAlgorithm::*;
- #[allow(deprecated)]
- match &self {
- RSAEncryptSign | RSAEncrypt | RSASign | DSA | ECDH | ECDSA | EdDSA
- => true,
- ElGamalEncrypt | ElGamalEncryptSign | Private(_) | Unknown(_)
- => false,
- }
+ self.is_supported_by_backend()
}
}
@@ -491,13 +484,7 @@ impl Curve {
/// assert!(!Curve::Unknown(Box::new([0x2B, 0x11])).is_supported());
/// ```
pub fn is_supported(&self) -> bool {
- use self::Curve::*;
- match &self {
- NistP256 | NistP384 | NistP521 | Ed25519 | Cv25519
- => true,
- BrainpoolP256 | BrainpoolP512 | Unknown(_)
- => false,
- }
+ self.is_supported_by_backend()
}
}
@@ -738,13 +725,7 @@ impl AEADAlgorithm {
/// assert!(!AEADAlgorithm::OCB.is_supported());
/// ```
pub fn is_supported(&self) -> bool {
- use self::AEADAlgorithm::*;
- match &self {
- EAX
- => true,
- OCB | Private(_) | Unknown(_)
- => false,
- }
+ self.is_supported_by_backend()
}
}