identity_jose/jwk/
key_type.rs

1// Copyright 2020-2025 IOTA Stiftung, Fondazione LINKS
2// SPDX-License-Identifier: Apache-2.0
3
4use core::fmt::Display;
5use core::fmt::Formatter;
6use core::fmt::Result;
7
8/// Supported types for the JSON Web Key `kty` property.
9///
10/// [More Info](https://www.iana.org/assignments/jose/jose.xhtml#web-key-types)
11#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, serde::Deserialize, serde::Serialize)]
12pub enum JwkType {
13  /// Elliptic Curve.
14  #[serde(rename = "EC")]
15  Ec,
16  /// RSA.
17  #[serde(rename = "RSA")]
18  Rsa,
19  /// Octet sequence.
20  #[serde(rename = "oct")]
21  Oct,
22  /// Octet string key pairs.
23  #[serde(rename = "OKP")]
24  Okp,
25  /// Algorithm Key Pair, JSON Web Key Type for the ML-DSA and SLH-DSA Algorithm Family.
26  /// [More Info] (https://datatracker.ietf.org/doc/html/draft-ietf-cose-dilithium-06#name-algorithm-key-pair-type)
27  #[serde(rename = "AKP")]
28  Akp,
29}
30
31impl JwkType {
32  /// Returns the JWK "kty" as a `str` slice.
33  pub const fn name(self) -> &'static str {
34    match self {
35      Self::Ec => "EC",
36      Self::Rsa => "RSA",
37      Self::Oct => "oct",
38      Self::Okp => "OKP",
39      Self::Akp => "AKP",
40    }
41  }
42}
43
44impl Display for JwkType {
45  fn fmt(&self, f: &mut Formatter<'_>) -> Result {
46    f.write_str(self.name())
47  }
48}