diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2024-02-20 13:20:48 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2024-02-20 14:20:16 +0100 |
commit | 5ebcd83992195de2bcb961fa5b359260f0b92a7e (patch) | |
tree | 058ffca19e0490163ebba2ec0e91a4806ac4cbf8 | |
parent | 4d0f02a366e1c9a746ffe6b8d3702f65db040814 (diff) |
openpgp: New function Curve::variants.
-rw-r--r-- | openpgp/NEWS | 2 | ||||
-rw-r--r-- | openpgp/src/types/mod.rs | 23 |
2 files changed, 25 insertions, 0 deletions
diff --git a/openpgp/NEWS b/openpgp/NEWS index 572dce4f..ce276afe 100644 --- a/openpgp/NEWS +++ b/openpgp/NEWS @@ -9,6 +9,8 @@ secret scalar to make the generated secret key packet more compatible with implementations that do not implicitly do the clamping before decryption. +** New functionality + - Curve::variants * Changes in 1.18.0 ** New functionality - ComponentAmalgamation::certifications_by_key diff --git a/openpgp/src/types/mod.rs b/openpgp/src/types/mod.rs index 147524ff..50813cc7 100644 --- a/openpgp/src/types/mod.rs +++ b/openpgp/src/types/mod.rs @@ -375,6 +375,17 @@ impl Curve { } assert_send_and_sync!(Curve); +const CURVE_VARIANTS: [Curve; 7] = [ + Curve::NistP256, + Curve::NistP384, + Curve::NistP521, + Curve::BrainpoolP256, + // XXXv2: Curve::BrainpoolP384, + Curve::BrainpoolP512, + Curve::Ed25519, + Curve::Cv25519, +]; + impl Curve { /// Returns the length of public keys over this curve in bits. /// @@ -636,6 +647,18 @@ impl Curve { use crate::crypto::backend::{Backend, interface::Asymmetric}; Backend::supports_curve(self) } + + /// Returns an iterator over all valid variants. + /// + /// Returns an iterator over all known variants. This does not + /// include the [`Curve::Private`], or [`Curve::Unknown`] + /// variants, except to include BrainpoolP384 which is missing + /// from [`Curve`]. + pub fn variants() -> impl Iterator<Item=Self> { + CURVE_VARIANTS.iter().cloned() + // XXXv2: Remove that hack, fix documentation. + .chain(std::iter::once(Curve::Unknown(BRAINPOOL_P384_OID.into()))) + } } #[cfg(test)] |