diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2021-09-20 12:00:50 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2021-09-28 13:46:50 +0200 |
commit | 7eeba4c3dfccdf4cb11699a6b02d7e73ccd22654 (patch) | |
tree | 095c51d119fb8baa62246118c89545444159b658 | |
parent | fda86c1b3054b029263859b553544e4fce077fac (diff) |
openpgp: Add example that prints the supported algorithms.
- Also run this example in the CI so that we can see what algorithms
are supported by which backend.
-rw-r--r-- | .gitlab-ci.yml | 2 | ||||
-rw-r--r-- | openpgp/examples/supported-algorithms.rs | 100 |
2 files changed, 102 insertions, 0 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 60da0ee6..76218ecc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -23,6 +23,7 @@ build-bullseye: dependencies: - codespell script: + - cargo run --manifest-path openpgp/Cargo.toml --no-default-features --features crypto-nettle,compression --example supported-algorithms - $MAKE_TOP - if ! git diff --quiet Cargo.lock ; then echo "Cargo.lock changed. Please add the change to the corresponding commit." ; false ; fi - if ! git diff --quiet sq ; then echo "Please commit the changes to sq/src/sq-usage.rs." ; false ; fi @@ -272,6 +273,7 @@ windows-msvc: - cargo --version script: # https://github.com/rust-lang/cargo/issues/5015 + - cargo run --manifest-path openpgp/Cargo.toml --no-default-features --features crypto-cng,compression --example supported-algorithms - cargo build --manifest-path ffi/Cargo.toml --no-default-features --features crypto-cng,compression - cargo build --manifest-path openpgp-ffi/Cargo.toml --no-default-features --features crypto-cng,compression - cargo test --manifest-path openpgp/Cargo.toml --no-default-features --features crypto-cng,compression diff --git a/openpgp/examples/supported-algorithms.rs b/openpgp/examples/supported-algorithms.rs new file mode 100644 index 00000000..570cdc96 --- /dev/null +++ b/openpgp/examples/supported-algorithms.rs @@ -0,0 +1,100 @@ +//! This example prints all algorithms supported by the currently +//! selected cryptographic backend. + +use sequoia_openpgp as openpgp; +use openpgp::types::*; +use openpgp::cert::CipherSuite; + +fn main() { + println!("Cipher suites:"); + for a in &[ + CipherSuite::Cv25519, + CipherSuite::P256, + CipherSuite::P384, + CipherSuite::P521, + CipherSuite::RSA2k, + CipherSuite::RSA3k, + CipherSuite::RSA4k, + ] { + println!(" - {:70} {:?}", format!("{:?}", a), a.is_supported().is_ok()); + } + println!(); + + println!("Public-Key algorithms:"); + for a in &[ + PublicKeyAlgorithm::RSAEncryptSign, + PublicKeyAlgorithm::ElGamalEncrypt, + PublicKeyAlgorithm::DSA, + PublicKeyAlgorithm::ECDH, + PublicKeyAlgorithm::ECDSA, + PublicKeyAlgorithm::EdDSA, + ] { + println!(" - {:70} {:?}", a.to_string(), a.is_supported()); + } + println!(); + + println!("ECC algorithms:"); + for a in &[ + Curve::NistP256, + Curve::NistP384, + Curve::NistP521, + Curve::BrainpoolP256, + Curve::BrainpoolP512, + Curve::Ed25519, + Curve::Cv25519, + ] { + println!(" - {:70} {:?}", a.to_string(), a.is_supported()); + } + println!(); + + println!("Symmetric algorithms:"); + for a in &[ + SymmetricAlgorithm::IDEA, + SymmetricAlgorithm::TripleDES, + SymmetricAlgorithm::CAST5, + SymmetricAlgorithm::Blowfish, + SymmetricAlgorithm::AES128, + SymmetricAlgorithm::AES192, + SymmetricAlgorithm::AES256, + SymmetricAlgorithm::Twofish, + SymmetricAlgorithm::Camellia128, + SymmetricAlgorithm::Camellia192, + SymmetricAlgorithm::Camellia256, + ] { + println!(" - {:70} {:?}", a.to_string(), a.is_supported()); + } + println!(); + + println!("AEAD algorithms:"); + for a in &[ + AEADAlgorithm::EAX, + AEADAlgorithm::OCB, + ] { + println!(" - {:70} {:?}", a.to_string(), a.is_supported()); + } + println!(); + + println!("Hash algorithms:"); + for a in &[ + HashAlgorithm::MD5, + HashAlgorithm::SHA1, + HashAlgorithm::RipeMD, + HashAlgorithm::SHA256, + HashAlgorithm::SHA384, + HashAlgorithm::SHA512, + HashAlgorithm::SHA224, + ] { + println!(" - {:70} {:?}", a.to_string(), a.is_supported()); + } + println!(); + + println!("Compression algorithms:"); + for a in &[ + CompressionAlgorithm::Zip, + CompressionAlgorithm::Zlib, + CompressionAlgorithm::BZip2, + ] { + println!(" - {:70} {:?}", a.to_string(), a.is_supported()); + } + println!(); +} |