diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2021-09-09 14:05:15 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2021-09-16 12:51:18 +0200 |
commit | 80d68b09494b6ba2c295a38fcedc9447512d2423 (patch) | |
tree | cd04c44194c167b35a655ac2f81fde4ffac8e141 /openpgp/src | |
parent | 573cf50c4de0102e6b58b7e3f8db27edbb055068 (diff) |
openpgp: New function CipherSuite::is_supported.
Diffstat (limited to 'openpgp/src')
-rw-r--r-- | openpgp/src/cert/builder.rs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/openpgp/src/cert/builder.rs b/openpgp/src/cert/builder.rs index 7f8812f7..eee275eb 100644 --- a/openpgp/src/cert/builder.rs +++ b/openpgp/src/cert/builder.rs @@ -78,6 +78,60 @@ impl Default for CipherSuite { } impl CipherSuite { + /// Returns whether the currently selected cryptographic backend + /// supports the encryption and signing algorithms that the cipher + /// suite selects. + pub fn is_supported(&self) -> Result<()> { + use crate::types::{Curve, PublicKeyAlgorithm}; + use CipherSuite::*; + + macro_rules! check_pk { + ($pk: expr) => { + if ! $pk.is_supported() { + return Err(Error::UnsupportedPublicKeyAlgorithm($pk) + .into()); + } + } + } + + macro_rules! check_curve { + ($curve: expr) => { + if ! $curve.is_supported() { + return Err(Error::UnsupportedEllipticCurve($curve) + .into()); + } + } + } + + match self { + Cv25519 => { + check_pk!(PublicKeyAlgorithm::EdDSA); + check_curve!(Curve::Ed25519); + check_pk!(PublicKeyAlgorithm::ECDH); + check_curve!(Curve::Cv25519); + }, + RSA2k | RSA3k | RSA4k => { + check_pk!(PublicKeyAlgorithm::RSAEncryptSign); + }, + P256 => { + check_pk!(PublicKeyAlgorithm::ECDSA); + check_curve!(Curve::NistP256); + check_pk!(PublicKeyAlgorithm::ECDH); + }, + P384 => { + check_pk!(PublicKeyAlgorithm::ECDSA); + check_curve!(Curve::NistP384); + check_pk!(PublicKeyAlgorithm::ECDH); + }, + P521 => { + check_pk!(PublicKeyAlgorithm::ECDSA); + check_curve!(Curve::NistP521); + check_pk!(PublicKeyAlgorithm::ECDH); + }, + } + Ok(()) + } + fn generate_key<K, R>(self, flags: K) -> Result<Key<key::SecretParts, R>> where R: key::KeyRole, |