Skip to main content

mas_iana/
jose.rs

1// Copyright 2024, 2025 New Vector Ltd.
2// Copyright 2023, 2024 The Matrix.org Foundation C.I.C.
3//
4// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
5// Please see LICENSE files in the repository root for full details.
6
7#![allow(clippy::doc_markdown)]
8
9//! Enums from the "JSON Object Signing and Encryption" IANA registry
10//! See <https://www.iana.org/assignments/oauth-parameters/oauth-parameters.xhtml>
11
12// Do not edit this file manually
13
14/// JSON Web Signature "alg" parameter
15///
16/// Source: <http://www.iana.org/assignments/jose/web-signature-encryption-algorithms.csv>
17#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
18#[non_exhaustive]
19pub enum JsonWebSignatureAlg {
20    /// HMAC using SHA-256
21    Hs256,
22
23    /// HMAC using SHA-384
24    Hs384,
25
26    /// HMAC using SHA-512
27    Hs512,
28
29    /// RSASSA-PKCS1-v1_5 using SHA-256
30    Rs256,
31
32    /// RSASSA-PKCS1-v1_5 using SHA-384
33    Rs384,
34
35    /// RSASSA-PKCS1-v1_5 using SHA-512
36    Rs512,
37
38    /// ECDSA using P-256 and SHA-256
39    Es256,
40
41    /// ECDSA using P-384 and SHA-384
42    Es384,
43
44    /// ECDSA using P-521 and SHA-512
45    Es512,
46
47    /// RSASSA-PSS using SHA-256 and MGF1 with SHA-256
48    Ps256,
49
50    /// RSASSA-PSS using SHA-384 and MGF1 with SHA-384
51    Ps384,
52
53    /// RSASSA-PSS using SHA-512 and MGF1 with SHA-512
54    Ps512,
55
56    /// No digital signature or MAC performed
57    None,
58
59    /// EdDSA signature algorithms
60    EdDsa,
61
62    /// ECDSA using secp256k1 curve and SHA-256
63    Es256K,
64
65    /// EdDSA using Ed25519 curve
66    Ed25519,
67
68    /// EdDSA using Ed448 curve
69    Ed448,
70
71    /// An unknown value.
72    Unknown(String),
73}
74
75impl core::fmt::Display for JsonWebSignatureAlg {
76    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
77        match self {
78            Self::Hs256 => write!(f, "HS256"),
79            Self::Hs384 => write!(f, "HS384"),
80            Self::Hs512 => write!(f, "HS512"),
81            Self::Rs256 => write!(f, "RS256"),
82            Self::Rs384 => write!(f, "RS384"),
83            Self::Rs512 => write!(f, "RS512"),
84            Self::Es256 => write!(f, "ES256"),
85            Self::Es384 => write!(f, "ES384"),
86            Self::Es512 => write!(f, "ES512"),
87            Self::Ps256 => write!(f, "PS256"),
88            Self::Ps384 => write!(f, "PS384"),
89            Self::Ps512 => write!(f, "PS512"),
90            Self::None => write!(f, "none"),
91            Self::EdDsa => write!(f, "EdDSA"),
92            Self::Es256K => write!(f, "ES256K"),
93            Self::Ed25519 => write!(f, "Ed25519"),
94            Self::Ed448 => write!(f, "Ed448"),
95            Self::Unknown(value) => write!(f, "{value}"),
96        }
97    }
98}
99
100impl core::str::FromStr for JsonWebSignatureAlg {
101    type Err = core::convert::Infallible;
102
103    fn from_str(s: &str) -> Result<Self, Self::Err> {
104        match s {
105            "HS256" => Ok(Self::Hs256),
106            "HS384" => Ok(Self::Hs384),
107            "HS512" => Ok(Self::Hs512),
108            "RS256" => Ok(Self::Rs256),
109            "RS384" => Ok(Self::Rs384),
110            "RS512" => Ok(Self::Rs512),
111            "ES256" => Ok(Self::Es256),
112            "ES384" => Ok(Self::Es384),
113            "ES512" => Ok(Self::Es512),
114            "PS256" => Ok(Self::Ps256),
115            "PS384" => Ok(Self::Ps384),
116            "PS512" => Ok(Self::Ps512),
117            "none" => Ok(Self::None),
118            "EdDSA" => Ok(Self::EdDsa),
119            "ES256K" => Ok(Self::Es256K),
120            "Ed25519" => Ok(Self::Ed25519),
121            "Ed448" => Ok(Self::Ed448),
122            value => Ok(Self::Unknown(value.to_owned())),
123        }
124    }
125}
126
127impl<'de> serde::Deserialize<'de> for JsonWebSignatureAlg {
128    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
129    where
130        D: serde::de::Deserializer<'de>,
131    {
132        let s = String::deserialize(deserializer)?;
133        core::str::FromStr::from_str(&s).map_err(serde::de::Error::custom)
134    }
135}
136
137impl serde::Serialize for JsonWebSignatureAlg {
138    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
139    where
140        S: serde::ser::Serializer,
141    {
142        serializer.serialize_str(&self.to_string())
143    }
144}
145
146impl schemars::JsonSchema for JsonWebSignatureAlg {
147    fn schema_name() -> std::borrow::Cow<'static, str> {
148        std::borrow::Cow::Borrowed("JsonWebSignatureAlg")
149    }
150
151    fn json_schema(_gen: &mut schemars::SchemaGenerator) -> schemars::Schema {
152        let enums = vec![
153            // ---
154            schemars::json_schema!({
155                "description": r"HMAC using SHA-256",
156                "const": "HS256",
157            }),
158            // ---
159            schemars::json_schema!({
160                "description": r"HMAC using SHA-384",
161                "const": "HS384",
162            }),
163            // ---
164            schemars::json_schema!({
165                "description": r"HMAC using SHA-512",
166                "const": "HS512",
167            }),
168            // ---
169            schemars::json_schema!({
170                "description": r"RSASSA-PKCS1-v1_5 using SHA-256",
171                "const": "RS256",
172            }),
173            // ---
174            schemars::json_schema!({
175                "description": r"RSASSA-PKCS1-v1_5 using SHA-384",
176                "const": "RS384",
177            }),
178            // ---
179            schemars::json_schema!({
180                "description": r"RSASSA-PKCS1-v1_5 using SHA-512",
181                "const": "RS512",
182            }),
183            // ---
184            schemars::json_schema!({
185                "description": r"ECDSA using P-256 and SHA-256",
186                "const": "ES256",
187            }),
188            // ---
189            schemars::json_schema!({
190                "description": r"ECDSA using P-384 and SHA-384",
191                "const": "ES384",
192            }),
193            // ---
194            schemars::json_schema!({
195                "description": r"ECDSA using P-521 and SHA-512",
196                "const": "ES512",
197            }),
198            // ---
199            schemars::json_schema!({
200                "description": r"RSASSA-PSS using SHA-256 and MGF1 with SHA-256",
201                "const": "PS256",
202            }),
203            // ---
204            schemars::json_schema!({
205                "description": r"RSASSA-PSS using SHA-384 and MGF1 with SHA-384",
206                "const": "PS384",
207            }),
208            // ---
209            schemars::json_schema!({
210                "description": r"RSASSA-PSS using SHA-512 and MGF1 with SHA-512",
211                "const": "PS512",
212            }),
213            // ---
214            schemars::json_schema!({
215                "description": r"No digital signature or MAC performed",
216                "const": "none",
217            }),
218            // ---
219            schemars::json_schema!({
220                "description": r"EdDSA signature algorithms",
221                "const": "EdDSA",
222            }),
223            // ---
224            schemars::json_schema!({
225                "description": r"ECDSA using secp256k1 curve and SHA-256",
226                "const": "ES256K",
227            }),
228            // ---
229            schemars::json_schema!({
230                "description": r"EdDSA using Ed25519 curve",
231                "const": "Ed25519",
232            }),
233            // ---
234            schemars::json_schema!({
235                "description": r"EdDSA using Ed448 curve",
236                "const": "Ed448",
237            }),
238        ];
239
240        let description = r#"JSON Web Signature "alg" parameter"#;
241        schemars::json_schema!({
242            "description": description,
243            "anyOf": enums,
244        })
245    }
246}
247
248/// JSON Web Encryption "alg" parameter
249///
250/// Source: <http://www.iana.org/assignments/jose/web-signature-encryption-algorithms.csv>
251#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
252#[non_exhaustive]
253pub enum JsonWebEncryptionAlg {
254    /// RSAES-PKCS1-v1_5
255    Rsa15,
256
257    /// RSAES OAEP using default parameters
258    RsaOaep,
259
260    /// RSAES OAEP using SHA-256 and MGF1 with SHA-256
261    RsaOaep256,
262
263    /// AES Key Wrap using 128-bit key
264    A128Kw,
265
266    /// AES Key Wrap using 192-bit key
267    A192Kw,
268
269    /// AES Key Wrap using 256-bit key
270    A256Kw,
271
272    /// Direct use of a shared symmetric key
273    Dir,
274
275    /// ECDH-ES using Concat KDF
276    EcdhEs,
277
278    /// ECDH-ES using Concat KDF and "A128KW" wrapping
279    EcdhEsA128Kw,
280
281    /// ECDH-ES using Concat KDF and "A192KW" wrapping
282    EcdhEsA192Kw,
283
284    /// ECDH-ES using Concat KDF and "A256KW" wrapping
285    EcdhEsA256Kw,
286
287    /// Key wrapping with AES GCM using 128-bit key
288    A128Gcmkw,
289
290    /// Key wrapping with AES GCM using 192-bit key
291    A192Gcmkw,
292
293    /// Key wrapping with AES GCM using 256-bit key
294    A256Gcmkw,
295
296    /// PBES2 with HMAC SHA-256 and "A128KW" wrapping
297    Pbes2Hs256A128Kw,
298
299    /// PBES2 with HMAC SHA-384 and "A192KW" wrapping
300    Pbes2Hs384A192Kw,
301
302    /// PBES2 with HMAC SHA-512 and "A256KW" wrapping
303    Pbes2Hs512A256Kw,
304
305    /// RSA-OAEP using SHA-384 and MGF1 with SHA-384
306    RsaOaep384,
307
308    /// RSA-OAEP using SHA-512 and MGF1 with SHA-512
309    RsaOaep512,
310
311    /// An unknown value.
312    Unknown(String),
313}
314
315impl core::fmt::Display for JsonWebEncryptionAlg {
316    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
317        match self {
318            Self::Rsa15 => write!(f, "RSA1_5"),
319            Self::RsaOaep => write!(f, "RSA-OAEP"),
320            Self::RsaOaep256 => write!(f, "RSA-OAEP-256"),
321            Self::A128Kw => write!(f, "A128KW"),
322            Self::A192Kw => write!(f, "A192KW"),
323            Self::A256Kw => write!(f, "A256KW"),
324            Self::Dir => write!(f, "dir"),
325            Self::EcdhEs => write!(f, "ECDH-ES"),
326            Self::EcdhEsA128Kw => write!(f, "ECDH-ES+A128KW"),
327            Self::EcdhEsA192Kw => write!(f, "ECDH-ES+A192KW"),
328            Self::EcdhEsA256Kw => write!(f, "ECDH-ES+A256KW"),
329            Self::A128Gcmkw => write!(f, "A128GCMKW"),
330            Self::A192Gcmkw => write!(f, "A192GCMKW"),
331            Self::A256Gcmkw => write!(f, "A256GCMKW"),
332            Self::Pbes2Hs256A128Kw => write!(f, "PBES2-HS256+A128KW"),
333            Self::Pbes2Hs384A192Kw => write!(f, "PBES2-HS384+A192KW"),
334            Self::Pbes2Hs512A256Kw => write!(f, "PBES2-HS512+A256KW"),
335            Self::RsaOaep384 => write!(f, "RSA-OAEP-384"),
336            Self::RsaOaep512 => write!(f, "RSA-OAEP-512"),
337            Self::Unknown(value) => write!(f, "{value}"),
338        }
339    }
340}
341
342impl core::str::FromStr for JsonWebEncryptionAlg {
343    type Err = core::convert::Infallible;
344
345    fn from_str(s: &str) -> Result<Self, Self::Err> {
346        match s {
347            "RSA1_5" => Ok(Self::Rsa15),
348            "RSA-OAEP" => Ok(Self::RsaOaep),
349            "RSA-OAEP-256" => Ok(Self::RsaOaep256),
350            "A128KW" => Ok(Self::A128Kw),
351            "A192KW" => Ok(Self::A192Kw),
352            "A256KW" => Ok(Self::A256Kw),
353            "dir" => Ok(Self::Dir),
354            "ECDH-ES" => Ok(Self::EcdhEs),
355            "ECDH-ES+A128KW" => Ok(Self::EcdhEsA128Kw),
356            "ECDH-ES+A192KW" => Ok(Self::EcdhEsA192Kw),
357            "ECDH-ES+A256KW" => Ok(Self::EcdhEsA256Kw),
358            "A128GCMKW" => Ok(Self::A128Gcmkw),
359            "A192GCMKW" => Ok(Self::A192Gcmkw),
360            "A256GCMKW" => Ok(Self::A256Gcmkw),
361            "PBES2-HS256+A128KW" => Ok(Self::Pbes2Hs256A128Kw),
362            "PBES2-HS384+A192KW" => Ok(Self::Pbes2Hs384A192Kw),
363            "PBES2-HS512+A256KW" => Ok(Self::Pbes2Hs512A256Kw),
364            "RSA-OAEP-384" => Ok(Self::RsaOaep384),
365            "RSA-OAEP-512" => Ok(Self::RsaOaep512),
366            value => Ok(Self::Unknown(value.to_owned())),
367        }
368    }
369}
370
371impl<'de> serde::Deserialize<'de> for JsonWebEncryptionAlg {
372    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
373    where
374        D: serde::de::Deserializer<'de>,
375    {
376        let s = String::deserialize(deserializer)?;
377        core::str::FromStr::from_str(&s).map_err(serde::de::Error::custom)
378    }
379}
380
381impl serde::Serialize for JsonWebEncryptionAlg {
382    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
383    where
384        S: serde::ser::Serializer,
385    {
386        serializer.serialize_str(&self.to_string())
387    }
388}
389
390impl schemars::JsonSchema for JsonWebEncryptionAlg {
391    fn schema_name() -> std::borrow::Cow<'static, str> {
392        std::borrow::Cow::Borrowed("JsonWebEncryptionAlg")
393    }
394
395    fn json_schema(_gen: &mut schemars::SchemaGenerator) -> schemars::Schema {
396        let enums = vec![
397            // ---
398            schemars::json_schema!({
399                "description": r"RSAES-PKCS1-v1_5",
400                "const": "RSA1_5",
401            }),
402            // ---
403            schemars::json_schema!({
404                "description": r"RSAES OAEP using default parameters",
405                "const": "RSA-OAEP",
406            }),
407            // ---
408            schemars::json_schema!({
409                "description": r"RSAES OAEP using SHA-256 and MGF1 with SHA-256",
410                "const": "RSA-OAEP-256",
411            }),
412            // ---
413            schemars::json_schema!({
414                "description": r"AES Key Wrap using 128-bit key",
415                "const": "A128KW",
416            }),
417            // ---
418            schemars::json_schema!({
419                "description": r"AES Key Wrap using 192-bit key",
420                "const": "A192KW",
421            }),
422            // ---
423            schemars::json_schema!({
424                "description": r"AES Key Wrap using 256-bit key",
425                "const": "A256KW",
426            }),
427            // ---
428            schemars::json_schema!({
429                "description": r"Direct use of a shared symmetric key",
430                "const": "dir",
431            }),
432            // ---
433            schemars::json_schema!({
434                "description": r"ECDH-ES using Concat KDF",
435                "const": "ECDH-ES",
436            }),
437            // ---
438            schemars::json_schema!({
439                "description": r#"ECDH-ES using Concat KDF and "A128KW" wrapping"#,
440                "const": "ECDH-ES+A128KW",
441            }),
442            // ---
443            schemars::json_schema!({
444                "description": r#"ECDH-ES using Concat KDF and "A192KW" wrapping"#,
445                "const": "ECDH-ES+A192KW",
446            }),
447            // ---
448            schemars::json_schema!({
449                "description": r#"ECDH-ES using Concat KDF and "A256KW" wrapping"#,
450                "const": "ECDH-ES+A256KW",
451            }),
452            // ---
453            schemars::json_schema!({
454                "description": r"Key wrapping with AES GCM using 128-bit key",
455                "const": "A128GCMKW",
456            }),
457            // ---
458            schemars::json_schema!({
459                "description": r"Key wrapping with AES GCM using 192-bit key",
460                "const": "A192GCMKW",
461            }),
462            // ---
463            schemars::json_schema!({
464                "description": r"Key wrapping with AES GCM using 256-bit key",
465                "const": "A256GCMKW",
466            }),
467            // ---
468            schemars::json_schema!({
469                "description": r#"PBES2 with HMAC SHA-256 and "A128KW" wrapping"#,
470                "const": "PBES2-HS256+A128KW",
471            }),
472            // ---
473            schemars::json_schema!({
474                "description": r#"PBES2 with HMAC SHA-384 and "A192KW" wrapping"#,
475                "const": "PBES2-HS384+A192KW",
476            }),
477            // ---
478            schemars::json_schema!({
479                "description": r#"PBES2 with HMAC SHA-512 and "A256KW" wrapping"#,
480                "const": "PBES2-HS512+A256KW",
481            }),
482            // ---
483            schemars::json_schema!({
484                "description": r"RSA-OAEP using SHA-384 and MGF1 with SHA-384",
485                "const": "RSA-OAEP-384",
486            }),
487            // ---
488            schemars::json_schema!({
489                "description": r"RSA-OAEP using SHA-512 and MGF1 with SHA-512",
490                "const": "RSA-OAEP-512",
491            }),
492        ];
493
494        let description = r#"JSON Web Encryption "alg" parameter"#;
495        schemars::json_schema!({
496            "description": description,
497            "anyOf": enums,
498        })
499    }
500}
501
502/// JSON Web Encryption "enc" parameter
503///
504/// Source: <http://www.iana.org/assignments/jose/web-signature-encryption-algorithms.csv>
505#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
506#[non_exhaustive]
507pub enum JsonWebEncryptionEnc {
508    /// AES_128_CBC_HMAC_SHA_256 authenticated encryption algorithm
509    A128CbcHs256,
510
511    /// AES_192_CBC_HMAC_SHA_384 authenticated encryption algorithm
512    A192CbcHs384,
513
514    /// AES_256_CBC_HMAC_SHA_512 authenticated encryption algorithm
515    A256CbcHs512,
516
517    /// AES GCM using 128-bit key
518    A128Gcm,
519
520    /// AES GCM using 192-bit key
521    A192Gcm,
522
523    /// AES GCM using 256-bit key
524    A256Gcm,
525
526    /// An unknown value.
527    Unknown(String),
528}
529
530impl core::fmt::Display for JsonWebEncryptionEnc {
531    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
532        match self {
533            Self::A128CbcHs256 => write!(f, "A128CBC-HS256"),
534            Self::A192CbcHs384 => write!(f, "A192CBC-HS384"),
535            Self::A256CbcHs512 => write!(f, "A256CBC-HS512"),
536            Self::A128Gcm => write!(f, "A128GCM"),
537            Self::A192Gcm => write!(f, "A192GCM"),
538            Self::A256Gcm => write!(f, "A256GCM"),
539            Self::Unknown(value) => write!(f, "{value}"),
540        }
541    }
542}
543
544impl core::str::FromStr for JsonWebEncryptionEnc {
545    type Err = core::convert::Infallible;
546
547    fn from_str(s: &str) -> Result<Self, Self::Err> {
548        match s {
549            "A128CBC-HS256" => Ok(Self::A128CbcHs256),
550            "A192CBC-HS384" => Ok(Self::A192CbcHs384),
551            "A256CBC-HS512" => Ok(Self::A256CbcHs512),
552            "A128GCM" => Ok(Self::A128Gcm),
553            "A192GCM" => Ok(Self::A192Gcm),
554            "A256GCM" => Ok(Self::A256Gcm),
555            value => Ok(Self::Unknown(value.to_owned())),
556        }
557    }
558}
559
560impl<'de> serde::Deserialize<'de> for JsonWebEncryptionEnc {
561    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
562    where
563        D: serde::de::Deserializer<'de>,
564    {
565        let s = String::deserialize(deserializer)?;
566        core::str::FromStr::from_str(&s).map_err(serde::de::Error::custom)
567    }
568}
569
570impl serde::Serialize for JsonWebEncryptionEnc {
571    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
572    where
573        S: serde::ser::Serializer,
574    {
575        serializer.serialize_str(&self.to_string())
576    }
577}
578
579impl schemars::JsonSchema for JsonWebEncryptionEnc {
580    fn schema_name() -> std::borrow::Cow<'static, str> {
581        std::borrow::Cow::Borrowed("JsonWebEncryptionEnc")
582    }
583
584    fn json_schema(_gen: &mut schemars::SchemaGenerator) -> schemars::Schema {
585        let enums = vec![
586            // ---
587            schemars::json_schema!({
588                "description": r"AES_128_CBC_HMAC_SHA_256 authenticated encryption algorithm",
589                "const": "A128CBC-HS256",
590            }),
591            // ---
592            schemars::json_schema!({
593                "description": r"AES_192_CBC_HMAC_SHA_384 authenticated encryption algorithm",
594                "const": "A192CBC-HS384",
595            }),
596            // ---
597            schemars::json_schema!({
598                "description": r"AES_256_CBC_HMAC_SHA_512 authenticated encryption algorithm",
599                "const": "A256CBC-HS512",
600            }),
601            // ---
602            schemars::json_schema!({
603                "description": r"AES GCM using 128-bit key",
604                "const": "A128GCM",
605            }),
606            // ---
607            schemars::json_schema!({
608                "description": r"AES GCM using 192-bit key",
609                "const": "A192GCM",
610            }),
611            // ---
612            schemars::json_schema!({
613                "description": r"AES GCM using 256-bit key",
614                "const": "A256GCM",
615            }),
616        ];
617
618        let description = r#"JSON Web Encryption "enc" parameter"#;
619        schemars::json_schema!({
620            "description": description,
621            "anyOf": enums,
622        })
623    }
624}
625
626/// JSON Web Encryption Compression Algorithm
627///
628/// Source: <http://www.iana.org/assignments/jose/web-encryption-compression-algorithms.csv>
629#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
630#[non_exhaustive]
631pub enum JsonWebEncryptionCompressionAlgorithm {
632    /// DEFLATE
633    Def,
634
635    /// An unknown value.
636    Unknown(String),
637}
638
639impl core::fmt::Display for JsonWebEncryptionCompressionAlgorithm {
640    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
641        match self {
642            Self::Def => write!(f, "DEF"),
643            Self::Unknown(value) => write!(f, "{value}"),
644        }
645    }
646}
647
648impl core::str::FromStr for JsonWebEncryptionCompressionAlgorithm {
649    type Err = core::convert::Infallible;
650
651    fn from_str(s: &str) -> Result<Self, Self::Err> {
652        match s {
653            "DEF" => Ok(Self::Def),
654            value => Ok(Self::Unknown(value.to_owned())),
655        }
656    }
657}
658
659impl<'de> serde::Deserialize<'de> for JsonWebEncryptionCompressionAlgorithm {
660    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
661    where
662        D: serde::de::Deserializer<'de>,
663    {
664        let s = String::deserialize(deserializer)?;
665        core::str::FromStr::from_str(&s).map_err(serde::de::Error::custom)
666    }
667}
668
669impl serde::Serialize for JsonWebEncryptionCompressionAlgorithm {
670    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
671    where
672        S: serde::ser::Serializer,
673    {
674        serializer.serialize_str(&self.to_string())
675    }
676}
677
678impl schemars::JsonSchema for JsonWebEncryptionCompressionAlgorithm {
679    fn schema_name() -> std::borrow::Cow<'static, str> {
680        std::borrow::Cow::Borrowed("JsonWebEncryptionCompressionAlgorithm")
681    }
682
683    fn json_schema(_gen: &mut schemars::SchemaGenerator) -> schemars::Schema {
684        let enums = vec![
685            // ---
686            schemars::json_schema!({
687                "description": r"DEFLATE",
688                "const": "DEF",
689            }),
690        ];
691
692        let description = r"JSON Web Encryption Compression Algorithm";
693        schemars::json_schema!({
694            "description": description,
695            "anyOf": enums,
696        })
697    }
698}
699
700/// JSON Web Key Type
701///
702/// Source: <http://www.iana.org/assignments/jose/web-key-types.csv>
703#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
704#[non_exhaustive]
705pub enum JsonWebKeyType {
706    /// Elliptic Curve
707    Ec,
708
709    /// RSA
710    Rsa,
711
712    /// Octet sequence
713    Oct,
714
715    /// Octet string key pairs
716    Okp,
717
718    /// An unknown value.
719    Unknown(String),
720}
721
722impl core::fmt::Display for JsonWebKeyType {
723    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
724        match self {
725            Self::Ec => write!(f, "EC"),
726            Self::Rsa => write!(f, "RSA"),
727            Self::Oct => write!(f, "oct"),
728            Self::Okp => write!(f, "OKP"),
729            Self::Unknown(value) => write!(f, "{value}"),
730        }
731    }
732}
733
734impl core::str::FromStr for JsonWebKeyType {
735    type Err = core::convert::Infallible;
736
737    fn from_str(s: &str) -> Result<Self, Self::Err> {
738        match s {
739            "EC" => Ok(Self::Ec),
740            "RSA" => Ok(Self::Rsa),
741            "oct" => Ok(Self::Oct),
742            "OKP" => Ok(Self::Okp),
743            value => Ok(Self::Unknown(value.to_owned())),
744        }
745    }
746}
747
748impl<'de> serde::Deserialize<'de> for JsonWebKeyType {
749    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
750    where
751        D: serde::de::Deserializer<'de>,
752    {
753        let s = String::deserialize(deserializer)?;
754        core::str::FromStr::from_str(&s).map_err(serde::de::Error::custom)
755    }
756}
757
758impl serde::Serialize for JsonWebKeyType {
759    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
760    where
761        S: serde::ser::Serializer,
762    {
763        serializer.serialize_str(&self.to_string())
764    }
765}
766
767impl schemars::JsonSchema for JsonWebKeyType {
768    fn schema_name() -> std::borrow::Cow<'static, str> {
769        std::borrow::Cow::Borrowed("JsonWebKeyType")
770    }
771
772    fn json_schema(_gen: &mut schemars::SchemaGenerator) -> schemars::Schema {
773        let enums = vec![
774            // ---
775            schemars::json_schema!({
776                "description": r"Elliptic Curve",
777                "const": "EC",
778            }),
779            // ---
780            schemars::json_schema!({
781                "description": r"RSA",
782                "const": "RSA",
783            }),
784            // ---
785            schemars::json_schema!({
786                "description": r"Octet sequence",
787                "const": "oct",
788            }),
789            // ---
790            schemars::json_schema!({
791                "description": r"Octet string key pairs",
792                "const": "OKP",
793            }),
794        ];
795
796        let description = r"JSON Web Key Type";
797        schemars::json_schema!({
798            "description": description,
799            "anyOf": enums,
800        })
801    }
802}
803
804/// JSON Web Key EC Elliptic Curve
805///
806/// Source: <http://www.iana.org/assignments/jose/web-key-elliptic-curve.csv>
807#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
808#[non_exhaustive]
809pub enum JsonWebKeyEcEllipticCurve {
810    /// P-256 Curve
811    P256,
812
813    /// P-384 Curve
814    P384,
815
816    /// P-521 Curve
817    P521,
818
819    /// SECG secp256k1 curve
820    Secp256K1,
821
822    /// An unknown value.
823    Unknown(String),
824}
825
826impl core::fmt::Display for JsonWebKeyEcEllipticCurve {
827    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
828        match self {
829            Self::P256 => write!(f, "P-256"),
830            Self::P384 => write!(f, "P-384"),
831            Self::P521 => write!(f, "P-521"),
832            Self::Secp256K1 => write!(f, "secp256k1"),
833            Self::Unknown(value) => write!(f, "{value}"),
834        }
835    }
836}
837
838impl core::str::FromStr for JsonWebKeyEcEllipticCurve {
839    type Err = core::convert::Infallible;
840
841    fn from_str(s: &str) -> Result<Self, Self::Err> {
842        match s {
843            "P-256" => Ok(Self::P256),
844            "P-384" => Ok(Self::P384),
845            "P-521" => Ok(Self::P521),
846            "secp256k1" => Ok(Self::Secp256K1),
847            value => Ok(Self::Unknown(value.to_owned())),
848        }
849    }
850}
851
852impl<'de> serde::Deserialize<'de> for JsonWebKeyEcEllipticCurve {
853    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
854    where
855        D: serde::de::Deserializer<'de>,
856    {
857        let s = String::deserialize(deserializer)?;
858        core::str::FromStr::from_str(&s).map_err(serde::de::Error::custom)
859    }
860}
861
862impl serde::Serialize for JsonWebKeyEcEllipticCurve {
863    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
864    where
865        S: serde::ser::Serializer,
866    {
867        serializer.serialize_str(&self.to_string())
868    }
869}
870
871impl schemars::JsonSchema for JsonWebKeyEcEllipticCurve {
872    fn schema_name() -> std::borrow::Cow<'static, str> {
873        std::borrow::Cow::Borrowed("JsonWebKeyEcEllipticCurve")
874    }
875
876    fn json_schema(_gen: &mut schemars::SchemaGenerator) -> schemars::Schema {
877        let enums = vec![
878            // ---
879            schemars::json_schema!({
880                "description": r"P-256 Curve",
881                "const": "P-256",
882            }),
883            // ---
884            schemars::json_schema!({
885                "description": r"P-384 Curve",
886                "const": "P-384",
887            }),
888            // ---
889            schemars::json_schema!({
890                "description": r"P-521 Curve",
891                "const": "P-521",
892            }),
893            // ---
894            schemars::json_schema!({
895                "description": r"SECG secp256k1 curve",
896                "const": "secp256k1",
897            }),
898        ];
899
900        let description = r"JSON Web Key EC Elliptic Curve";
901        schemars::json_schema!({
902            "description": description,
903            "anyOf": enums,
904        })
905    }
906}
907
908/// JSON Web Key OKP Elliptic Curve
909///
910/// Source: <http://www.iana.org/assignments/jose/web-key-elliptic-curve.csv>
911#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
912#[non_exhaustive]
913pub enum JsonWebKeyOkpEllipticCurve {
914    /// Ed25519 signature algorithm key pairs
915    Ed25519,
916
917    /// Ed448 signature algorithm key pairs
918    Ed448,
919
920    /// X25519 function key pairs
921    X25519,
922
923    /// X448 function key pairs
924    X448,
925
926    /// An unknown value.
927    Unknown(String),
928}
929
930impl core::fmt::Display for JsonWebKeyOkpEllipticCurve {
931    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
932        match self {
933            Self::Ed25519 => write!(f, "Ed25519"),
934            Self::Ed448 => write!(f, "Ed448"),
935            Self::X25519 => write!(f, "X25519"),
936            Self::X448 => write!(f, "X448"),
937            Self::Unknown(value) => write!(f, "{value}"),
938        }
939    }
940}
941
942impl core::str::FromStr for JsonWebKeyOkpEllipticCurve {
943    type Err = core::convert::Infallible;
944
945    fn from_str(s: &str) -> Result<Self, Self::Err> {
946        match s {
947            "Ed25519" => Ok(Self::Ed25519),
948            "Ed448" => Ok(Self::Ed448),
949            "X25519" => Ok(Self::X25519),
950            "X448" => Ok(Self::X448),
951            value => Ok(Self::Unknown(value.to_owned())),
952        }
953    }
954}
955
956impl<'de> serde::Deserialize<'de> for JsonWebKeyOkpEllipticCurve {
957    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
958    where
959        D: serde::de::Deserializer<'de>,
960    {
961        let s = String::deserialize(deserializer)?;
962        core::str::FromStr::from_str(&s).map_err(serde::de::Error::custom)
963    }
964}
965
966impl serde::Serialize for JsonWebKeyOkpEllipticCurve {
967    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
968    where
969        S: serde::ser::Serializer,
970    {
971        serializer.serialize_str(&self.to_string())
972    }
973}
974
975impl schemars::JsonSchema for JsonWebKeyOkpEllipticCurve {
976    fn schema_name() -> std::borrow::Cow<'static, str> {
977        std::borrow::Cow::Borrowed("JsonWebKeyOkpEllipticCurve")
978    }
979
980    fn json_schema(_gen: &mut schemars::SchemaGenerator) -> schemars::Schema {
981        let enums = vec![
982            // ---
983            schemars::json_schema!({
984                "description": r"Ed25519 signature algorithm key pairs",
985                "const": "Ed25519",
986            }),
987            // ---
988            schemars::json_schema!({
989                "description": r"Ed448 signature algorithm key pairs",
990                "const": "Ed448",
991            }),
992            // ---
993            schemars::json_schema!({
994                "description": r"X25519 function key pairs",
995                "const": "X25519",
996            }),
997            // ---
998            schemars::json_schema!({
999                "description": r"X448 function key pairs",
1000                "const": "X448",
1001            }),
1002        ];
1003
1004        let description = r"JSON Web Key OKP Elliptic Curve";
1005        schemars::json_schema!({
1006            "description": description,
1007            "anyOf": enums,
1008        })
1009    }
1010}
1011
1012/// JSON Web Key Use
1013///
1014/// Source: <http://www.iana.org/assignments/jose/web-key-use.csv>
1015#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1016#[non_exhaustive]
1017pub enum JsonWebKeyUse {
1018    /// Digital Signature or MAC
1019    Sig,
1020
1021    /// Encryption
1022    Enc,
1023
1024    /// An unknown value.
1025    Unknown(String),
1026}
1027
1028impl core::fmt::Display for JsonWebKeyUse {
1029    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1030        match self {
1031            Self::Sig => write!(f, "sig"),
1032            Self::Enc => write!(f, "enc"),
1033            Self::Unknown(value) => write!(f, "{value}"),
1034        }
1035    }
1036}
1037
1038impl core::str::FromStr for JsonWebKeyUse {
1039    type Err = core::convert::Infallible;
1040
1041    fn from_str(s: &str) -> Result<Self, Self::Err> {
1042        match s {
1043            "sig" => Ok(Self::Sig),
1044            "enc" => Ok(Self::Enc),
1045            value => Ok(Self::Unknown(value.to_owned())),
1046        }
1047    }
1048}
1049
1050impl<'de> serde::Deserialize<'de> for JsonWebKeyUse {
1051    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1052    where
1053        D: serde::de::Deserializer<'de>,
1054    {
1055        let s = String::deserialize(deserializer)?;
1056        core::str::FromStr::from_str(&s).map_err(serde::de::Error::custom)
1057    }
1058}
1059
1060impl serde::Serialize for JsonWebKeyUse {
1061    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1062    where
1063        S: serde::ser::Serializer,
1064    {
1065        serializer.serialize_str(&self.to_string())
1066    }
1067}
1068
1069impl schemars::JsonSchema for JsonWebKeyUse {
1070    fn schema_name() -> std::borrow::Cow<'static, str> {
1071        std::borrow::Cow::Borrowed("JsonWebKeyUse")
1072    }
1073
1074    fn json_schema(_gen: &mut schemars::SchemaGenerator) -> schemars::Schema {
1075        let enums = vec![
1076            // ---
1077            schemars::json_schema!({
1078                "description": r"Digital Signature or MAC",
1079                "const": "sig",
1080            }),
1081            // ---
1082            schemars::json_schema!({
1083                "description": r"Encryption",
1084                "const": "enc",
1085            }),
1086        ];
1087
1088        let description = r"JSON Web Key Use";
1089        schemars::json_schema!({
1090            "description": description,
1091            "anyOf": enums,
1092        })
1093    }
1094}
1095
1096/// JSON Web Key Operation
1097///
1098/// Source: <http://www.iana.org/assignments/jose/web-key-operations.csv>
1099#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1100#[non_exhaustive]
1101pub enum JsonWebKeyOperation {
1102    /// Compute digital signature or MAC
1103    Sign,
1104
1105    /// Verify digital signature or MAC
1106    Verify,
1107
1108    /// Encrypt content
1109    Encrypt,
1110
1111    /// Decrypt content and validate decryption, if applicable
1112    Decrypt,
1113
1114    /// Encrypt key
1115    WrapKey,
1116
1117    /// Decrypt key and validate decryption, if applicable
1118    UnwrapKey,
1119
1120    /// Derive key
1121    DeriveKey,
1122
1123    /// Derive bits not to be used as a key
1124    DeriveBits,
1125
1126    /// An unknown value.
1127    Unknown(String),
1128}
1129
1130impl core::fmt::Display for JsonWebKeyOperation {
1131    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1132        match self {
1133            Self::Sign => write!(f, "sign"),
1134            Self::Verify => write!(f, "verify"),
1135            Self::Encrypt => write!(f, "encrypt"),
1136            Self::Decrypt => write!(f, "decrypt"),
1137            Self::WrapKey => write!(f, "wrapKey"),
1138            Self::UnwrapKey => write!(f, "unwrapKey"),
1139            Self::DeriveKey => write!(f, "deriveKey"),
1140            Self::DeriveBits => write!(f, "deriveBits"),
1141            Self::Unknown(value) => write!(f, "{value}"),
1142        }
1143    }
1144}
1145
1146impl core::str::FromStr for JsonWebKeyOperation {
1147    type Err = core::convert::Infallible;
1148
1149    fn from_str(s: &str) -> Result<Self, Self::Err> {
1150        match s {
1151            "sign" => Ok(Self::Sign),
1152            "verify" => Ok(Self::Verify),
1153            "encrypt" => Ok(Self::Encrypt),
1154            "decrypt" => Ok(Self::Decrypt),
1155            "wrapKey" => Ok(Self::WrapKey),
1156            "unwrapKey" => Ok(Self::UnwrapKey),
1157            "deriveKey" => Ok(Self::DeriveKey),
1158            "deriveBits" => Ok(Self::DeriveBits),
1159            value => Ok(Self::Unknown(value.to_owned())),
1160        }
1161    }
1162}
1163
1164impl<'de> serde::Deserialize<'de> for JsonWebKeyOperation {
1165    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1166    where
1167        D: serde::de::Deserializer<'de>,
1168    {
1169        let s = String::deserialize(deserializer)?;
1170        core::str::FromStr::from_str(&s).map_err(serde::de::Error::custom)
1171    }
1172}
1173
1174impl serde::Serialize for JsonWebKeyOperation {
1175    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1176    where
1177        S: serde::ser::Serializer,
1178    {
1179        serializer.serialize_str(&self.to_string())
1180    }
1181}
1182
1183impl schemars::JsonSchema for JsonWebKeyOperation {
1184    fn schema_name() -> std::borrow::Cow<'static, str> {
1185        std::borrow::Cow::Borrowed("JsonWebKeyOperation")
1186    }
1187
1188    fn json_schema(_gen: &mut schemars::SchemaGenerator) -> schemars::Schema {
1189        let enums = vec![
1190            // ---
1191            schemars::json_schema!({
1192                "description": r"Compute digital signature or MAC",
1193                "const": "sign",
1194            }),
1195            // ---
1196            schemars::json_schema!({
1197                "description": r"Verify digital signature or MAC",
1198                "const": "verify",
1199            }),
1200            // ---
1201            schemars::json_schema!({
1202                "description": r"Encrypt content",
1203                "const": "encrypt",
1204            }),
1205            // ---
1206            schemars::json_schema!({
1207                "description": r"Decrypt content and validate decryption, if applicable",
1208                "const": "decrypt",
1209            }),
1210            // ---
1211            schemars::json_schema!({
1212                "description": r"Encrypt key",
1213                "const": "wrapKey",
1214            }),
1215            // ---
1216            schemars::json_schema!({
1217                "description": r"Decrypt key and validate decryption, if applicable",
1218                "const": "unwrapKey",
1219            }),
1220            // ---
1221            schemars::json_schema!({
1222                "description": r"Derive key",
1223                "const": "deriveKey",
1224            }),
1225            // ---
1226            schemars::json_schema!({
1227                "description": r"Derive bits not to be used as a key",
1228                "const": "deriveBits",
1229            }),
1230        ];
1231
1232        let description = r"JSON Web Key Operation";
1233        schemars::json_schema!({
1234            "description": description,
1235            "anyOf": enums,
1236        })
1237    }
1238}