identity_jose/jwk/
key_use.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 algorithms for the JSON Web Key `use` property.
9///
10/// [More Info](https://www.iana.org/assignments/jose/jose.xhtml#web-key-use)
11#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, serde::Deserialize, serde::Serialize)]
12pub enum JwkUse {
13  /// Digital Signature or MAC.
14  #[serde(rename = "sig")]
15  Signature,
16  /// Encryption.
17  #[serde(rename = "enc")]
18  Encryption,
19  /// Proof
20  #[serde(rename = "proof")]
21  Proof,
22}
23
24impl JwkUse {
25  /// Returns the JWK "use" as a `str` slice.
26  pub const fn name(&self) -> &'static str {
27    match self {
28      Self::Signature => "sig",
29      Self::Encryption => "enc",
30      Self::Proof => "proof",
31    }
32  }
33}
34
35impl Display for JwkUse {
36  fn fmt(&self, f: &mut Formatter<'_>) -> Result {
37    f.write_str(self.name())
38  }
39}