summaryrefslogtreecommitdiffstats
path: root/openpgp/src/policy.rs
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2022-11-15 00:07:40 +0100
committerNeal H. Walfield <neal@pep.foundation>2022-11-15 00:07:40 +0100
commitbe2de85d31674b6790b2f02bdac9bf7e7b4810aa (patch)
tree19fa6d6dd23b335067f014f3bbd2435512d51ade /openpgp/src/policy.rs
parent53474e58493cc10a9e021fde5ca1048a86859f2b (diff)
openpgp: Add a method to iterate over all variants of some enums.
- It is sometimes useful to iterate over all variants of a given enum. - Add the `variants` method to AsymmetricAlgorithm `PublicKeyAlgorithm`, `SymmetricAlgorithm`, `AEADAlgorithm`, `CompressionAlgorithm`, `HashAlgorithm`, `SignatureType`, `ReasonForRevocation`, `DataFormat`, `packet::Tag`, and `SubpacketTag` to do this.
Diffstat (limited to 'openpgp/src/policy.rs')
-rw-r--r--openpgp/src/policy.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/openpgp/src/policy.rs b/openpgp/src/policy.rs
index 879f3947..704a7ea8 100644
--- a/openpgp/src/policy.rs
+++ b/openpgp/src/policy.rs
@@ -1557,6 +1557,37 @@ pub enum AsymmetricAlgorithm {
}
assert_send_and_sync!(AsymmetricAlgorithm);
+const ASYMMETRIC_ALGORITHM_VARIANTS: [AsymmetricAlgorithm; 18] = [
+ AsymmetricAlgorithm::RSA1024,
+ AsymmetricAlgorithm::RSA2048,
+ AsymmetricAlgorithm::RSA3072,
+ AsymmetricAlgorithm::RSA4096,
+ AsymmetricAlgorithm::ElGamal1024,
+ AsymmetricAlgorithm::ElGamal2048,
+ AsymmetricAlgorithm::ElGamal3072,
+ AsymmetricAlgorithm::ElGamal4096,
+ AsymmetricAlgorithm::DSA1024,
+ AsymmetricAlgorithm::DSA2048,
+ AsymmetricAlgorithm::DSA3072,
+ AsymmetricAlgorithm::DSA4096,
+ AsymmetricAlgorithm::NistP256,
+ AsymmetricAlgorithm::NistP384,
+ AsymmetricAlgorithm::NistP521,
+ AsymmetricAlgorithm::BrainpoolP256,
+ AsymmetricAlgorithm::BrainpoolP512,
+ AsymmetricAlgorithm::Cv25519,
+];
+
+impl AsymmetricAlgorithm {
+ /// Returns an iterator over all valid variants.
+ ///
+ /// Returns an iterator over all known variants. This does not
+ /// include the [`AsymmetricAlgorithm::Unknown`] variant.
+ pub fn variants() -> impl Iterator<Item=AsymmetricAlgorithm> {
+ ASYMMETRIC_ALGORITHM_VARIANTS.iter().cloned()
+ }
+}
+
impl std::fmt::Display for AsymmetricAlgorithm {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{:?}", self)