identity_jose/jwk/curve/
ec.rs

1// Copyright 2020-2023 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4use core::fmt::Display;
5use core::fmt::Formatter;
6use core::fmt::Result;
7
8/// Supported Elliptic Curves.
9///
10/// [More Info](https://www.iana.org/assignments/jose/jose.xhtml#web-key-elliptic-curve)
11#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
12pub enum EcCurve {
13  /// P-256 Curve.
14  P256,
15  /// P-384 Curve.
16  P384,
17  /// P-521 Curve.
18  P521,
19  /// SECG secp256k1 curve.
20  Secp256K1,
21}
22
23impl EcCurve {
24  /// Returns the name of the curve as a string slice.
25  pub const fn name(self) -> &'static str {
26    match self {
27      Self::P256 => "P-256",
28      Self::P384 => "P-384",
29      Self::P521 => "P-521",
30      Self::Secp256K1 => "secp256k1",
31    }
32  }
33}
34
35impl Display for EcCurve {
36  fn fmt(&self, f: &mut Formatter<'_>) -> Result {
37    f.write_str(self.name())
38  }
39}