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() -> String {
148        "JsonWebSignatureAlg".to_owned()
149    }
150
151    #[allow(clippy::too_many_lines)]
152    fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
153        let enums = vec![
154            // ---
155            schemars::schema::SchemaObject {
156                metadata: Some(Box::new(schemars::schema::Metadata {
157                    description: Some(
158                        // ---
159                        r"HMAC using SHA-256".to_owned(),
160                    ),
161                    ..Default::default()
162                })),
163                const_value: Some("HS256".into()),
164                ..Default::default()
165            }
166            .into(),
167            // ---
168            schemars::schema::SchemaObject {
169                metadata: Some(Box::new(schemars::schema::Metadata {
170                    description: Some(
171                        // ---
172                        r"HMAC using SHA-384".to_owned(),
173                    ),
174                    ..Default::default()
175                })),
176                const_value: Some("HS384".into()),
177                ..Default::default()
178            }
179            .into(),
180            // ---
181            schemars::schema::SchemaObject {
182                metadata: Some(Box::new(schemars::schema::Metadata {
183                    description: Some(
184                        // ---
185                        r"HMAC using SHA-512".to_owned(),
186                    ),
187                    ..Default::default()
188                })),
189                const_value: Some("HS512".into()),
190                ..Default::default()
191            }
192            .into(),
193            // ---
194            schemars::schema::SchemaObject {
195                metadata: Some(Box::new(schemars::schema::Metadata {
196                    description: Some(
197                        // ---
198                        r"RSASSA-PKCS1-v1_5 using SHA-256".to_owned(),
199                    ),
200                    ..Default::default()
201                })),
202                const_value: Some("RS256".into()),
203                ..Default::default()
204            }
205            .into(),
206            // ---
207            schemars::schema::SchemaObject {
208                metadata: Some(Box::new(schemars::schema::Metadata {
209                    description: Some(
210                        // ---
211                        r"RSASSA-PKCS1-v1_5 using SHA-384".to_owned(),
212                    ),
213                    ..Default::default()
214                })),
215                const_value: Some("RS384".into()),
216                ..Default::default()
217            }
218            .into(),
219            // ---
220            schemars::schema::SchemaObject {
221                metadata: Some(Box::new(schemars::schema::Metadata {
222                    description: Some(
223                        // ---
224                        r"RSASSA-PKCS1-v1_5 using SHA-512".to_owned(),
225                    ),
226                    ..Default::default()
227                })),
228                const_value: Some("RS512".into()),
229                ..Default::default()
230            }
231            .into(),
232            // ---
233            schemars::schema::SchemaObject {
234                metadata: Some(Box::new(schemars::schema::Metadata {
235                    description: Some(
236                        // ---
237                        r"ECDSA using P-256 and SHA-256".to_owned(),
238                    ),
239                    ..Default::default()
240                })),
241                const_value: Some("ES256".into()),
242                ..Default::default()
243            }
244            .into(),
245            // ---
246            schemars::schema::SchemaObject {
247                metadata: Some(Box::new(schemars::schema::Metadata {
248                    description: Some(
249                        // ---
250                        r"ECDSA using P-384 and SHA-384".to_owned(),
251                    ),
252                    ..Default::default()
253                })),
254                const_value: Some("ES384".into()),
255                ..Default::default()
256            }
257            .into(),
258            // ---
259            schemars::schema::SchemaObject {
260                metadata: Some(Box::new(schemars::schema::Metadata {
261                    description: Some(
262                        // ---
263                        r"ECDSA using P-521 and SHA-512".to_owned(),
264                    ),
265                    ..Default::default()
266                })),
267                const_value: Some("ES512".into()),
268                ..Default::default()
269            }
270            .into(),
271            // ---
272            schemars::schema::SchemaObject {
273                metadata: Some(Box::new(schemars::schema::Metadata {
274                    description: Some(
275                        // ---
276                        r"RSASSA-PSS using SHA-256 and MGF1 with SHA-256".to_owned(),
277                    ),
278                    ..Default::default()
279                })),
280                const_value: Some("PS256".into()),
281                ..Default::default()
282            }
283            .into(),
284            // ---
285            schemars::schema::SchemaObject {
286                metadata: Some(Box::new(schemars::schema::Metadata {
287                    description: Some(
288                        // ---
289                        r"RSASSA-PSS using SHA-384 and MGF1 with SHA-384".to_owned(),
290                    ),
291                    ..Default::default()
292                })),
293                const_value: Some("PS384".into()),
294                ..Default::default()
295            }
296            .into(),
297            // ---
298            schemars::schema::SchemaObject {
299                metadata: Some(Box::new(schemars::schema::Metadata {
300                    description: Some(
301                        // ---
302                        r"RSASSA-PSS using SHA-512 and MGF1 with SHA-512".to_owned(),
303                    ),
304                    ..Default::default()
305                })),
306                const_value: Some("PS512".into()),
307                ..Default::default()
308            }
309            .into(),
310            // ---
311            schemars::schema::SchemaObject {
312                metadata: Some(Box::new(schemars::schema::Metadata {
313                    description: Some(
314                        // ---
315                        r"No digital signature or MAC performed".to_owned(),
316                    ),
317                    ..Default::default()
318                })),
319                const_value: Some("none".into()),
320                ..Default::default()
321            }
322            .into(),
323            // ---
324            schemars::schema::SchemaObject {
325                metadata: Some(Box::new(schemars::schema::Metadata {
326                    description: Some(
327                        // ---
328                        r"EdDSA signature algorithms".to_owned(),
329                    ),
330                    ..Default::default()
331                })),
332                const_value: Some("EdDSA".into()),
333                ..Default::default()
334            }
335            .into(),
336            // ---
337            schemars::schema::SchemaObject {
338                metadata: Some(Box::new(schemars::schema::Metadata {
339                    description: Some(
340                        // ---
341                        r"ECDSA using secp256k1 curve and SHA-256".to_owned(),
342                    ),
343                    ..Default::default()
344                })),
345                const_value: Some("ES256K".into()),
346                ..Default::default()
347            }
348            .into(),
349            // ---
350            schemars::schema::SchemaObject {
351                metadata: Some(Box::new(schemars::schema::Metadata {
352                    description: Some(
353                        // ---
354                        r"EdDSA using Ed25519 curve".to_owned(),
355                    ),
356                    ..Default::default()
357                })),
358                const_value: Some("Ed25519".into()),
359                ..Default::default()
360            }
361            .into(),
362            // ---
363            schemars::schema::SchemaObject {
364                metadata: Some(Box::new(schemars::schema::Metadata {
365                    description: Some(
366                        // ---
367                        r"EdDSA using Ed448 curve".to_owned(),
368                    ),
369                    ..Default::default()
370                })),
371                const_value: Some("Ed448".into()),
372                ..Default::default()
373            }
374            .into(),
375        ];
376
377        let description = r#"JSON Web Signature "alg" parameter"#;
378        schemars::schema::SchemaObject {
379            metadata: Some(Box::new(schemars::schema::Metadata {
380                description: Some(description.to_owned()),
381                ..Default::default()
382            })),
383            subschemas: Some(Box::new(schemars::schema::SubschemaValidation {
384                any_of: Some(enums),
385                ..Default::default()
386            })),
387            ..Default::default()
388        }
389        .into()
390    }
391}
392
393/// JSON Web Encryption "alg" parameter
394///
395/// Source: <http://www.iana.org/assignments/jose/web-signature-encryption-algorithms.csv>
396#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
397#[non_exhaustive]
398pub enum JsonWebEncryptionAlg {
399    /// RSAES-PKCS1-v1_5
400    Rsa15,
401
402    /// RSAES OAEP using default parameters
403    RsaOaep,
404
405    /// RSAES OAEP using SHA-256 and MGF1 with SHA-256
406    RsaOaep256,
407
408    /// AES Key Wrap using 128-bit key
409    A128Kw,
410
411    /// AES Key Wrap using 192-bit key
412    A192Kw,
413
414    /// AES Key Wrap using 256-bit key
415    A256Kw,
416
417    /// Direct use of a shared symmetric key
418    Dir,
419
420    /// ECDH-ES using Concat KDF
421    EcdhEs,
422
423    /// ECDH-ES using Concat KDF and "A128KW" wrapping
424    EcdhEsA128Kw,
425
426    /// ECDH-ES using Concat KDF and "A192KW" wrapping
427    EcdhEsA192Kw,
428
429    /// ECDH-ES using Concat KDF and "A256KW" wrapping
430    EcdhEsA256Kw,
431
432    /// Key wrapping with AES GCM using 128-bit key
433    A128Gcmkw,
434
435    /// Key wrapping with AES GCM using 192-bit key
436    A192Gcmkw,
437
438    /// Key wrapping with AES GCM using 256-bit key
439    A256Gcmkw,
440
441    /// PBES2 with HMAC SHA-256 and "A128KW" wrapping
442    Pbes2Hs256A128Kw,
443
444    /// PBES2 with HMAC SHA-384 and "A192KW" wrapping
445    Pbes2Hs384A192Kw,
446
447    /// PBES2 with HMAC SHA-512 and "A256KW" wrapping
448    Pbes2Hs512A256Kw,
449
450    /// RSA-OAEP using SHA-384 and MGF1 with SHA-384
451    RsaOaep384,
452
453    /// RSA-OAEP using SHA-512 and MGF1 with SHA-512
454    RsaOaep512,
455
456    /// An unknown value.
457    Unknown(String),
458}
459
460impl core::fmt::Display for JsonWebEncryptionAlg {
461    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
462        match self {
463            Self::Rsa15 => write!(f, "RSA1_5"),
464            Self::RsaOaep => write!(f, "RSA-OAEP"),
465            Self::RsaOaep256 => write!(f, "RSA-OAEP-256"),
466            Self::A128Kw => write!(f, "A128KW"),
467            Self::A192Kw => write!(f, "A192KW"),
468            Self::A256Kw => write!(f, "A256KW"),
469            Self::Dir => write!(f, "dir"),
470            Self::EcdhEs => write!(f, "ECDH-ES"),
471            Self::EcdhEsA128Kw => write!(f, "ECDH-ES+A128KW"),
472            Self::EcdhEsA192Kw => write!(f, "ECDH-ES+A192KW"),
473            Self::EcdhEsA256Kw => write!(f, "ECDH-ES+A256KW"),
474            Self::A128Gcmkw => write!(f, "A128GCMKW"),
475            Self::A192Gcmkw => write!(f, "A192GCMKW"),
476            Self::A256Gcmkw => write!(f, "A256GCMKW"),
477            Self::Pbes2Hs256A128Kw => write!(f, "PBES2-HS256+A128KW"),
478            Self::Pbes2Hs384A192Kw => write!(f, "PBES2-HS384+A192KW"),
479            Self::Pbes2Hs512A256Kw => write!(f, "PBES2-HS512+A256KW"),
480            Self::RsaOaep384 => write!(f, "RSA-OAEP-384"),
481            Self::RsaOaep512 => write!(f, "RSA-OAEP-512"),
482            Self::Unknown(value) => write!(f, "{value}"),
483        }
484    }
485}
486
487impl core::str::FromStr for JsonWebEncryptionAlg {
488    type Err = core::convert::Infallible;
489
490    fn from_str(s: &str) -> Result<Self, Self::Err> {
491        match s {
492            "RSA1_5" => Ok(Self::Rsa15),
493            "RSA-OAEP" => Ok(Self::RsaOaep),
494            "RSA-OAEP-256" => Ok(Self::RsaOaep256),
495            "A128KW" => Ok(Self::A128Kw),
496            "A192KW" => Ok(Self::A192Kw),
497            "A256KW" => Ok(Self::A256Kw),
498            "dir" => Ok(Self::Dir),
499            "ECDH-ES" => Ok(Self::EcdhEs),
500            "ECDH-ES+A128KW" => Ok(Self::EcdhEsA128Kw),
501            "ECDH-ES+A192KW" => Ok(Self::EcdhEsA192Kw),
502            "ECDH-ES+A256KW" => Ok(Self::EcdhEsA256Kw),
503            "A128GCMKW" => Ok(Self::A128Gcmkw),
504            "A192GCMKW" => Ok(Self::A192Gcmkw),
505            "A256GCMKW" => Ok(Self::A256Gcmkw),
506            "PBES2-HS256+A128KW" => Ok(Self::Pbes2Hs256A128Kw),
507            "PBES2-HS384+A192KW" => Ok(Self::Pbes2Hs384A192Kw),
508            "PBES2-HS512+A256KW" => Ok(Self::Pbes2Hs512A256Kw),
509            "RSA-OAEP-384" => Ok(Self::RsaOaep384),
510            "RSA-OAEP-512" => Ok(Self::RsaOaep512),
511            value => Ok(Self::Unknown(value.to_owned())),
512        }
513    }
514}
515
516impl<'de> serde::Deserialize<'de> for JsonWebEncryptionAlg {
517    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
518    where
519        D: serde::de::Deserializer<'de>,
520    {
521        let s = String::deserialize(deserializer)?;
522        core::str::FromStr::from_str(&s).map_err(serde::de::Error::custom)
523    }
524}
525
526impl serde::Serialize for JsonWebEncryptionAlg {
527    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
528    where
529        S: serde::ser::Serializer,
530    {
531        serializer.serialize_str(&self.to_string())
532    }
533}
534
535impl schemars::JsonSchema for JsonWebEncryptionAlg {
536    fn schema_name() -> String {
537        "JsonWebEncryptionAlg".to_owned()
538    }
539
540    #[allow(clippy::too_many_lines)]
541    fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
542        let enums = vec![
543            // ---
544            schemars::schema::SchemaObject {
545                metadata: Some(Box::new(schemars::schema::Metadata {
546                    description: Some(
547                        // ---
548                        r"RSAES-PKCS1-v1_5".to_owned(),
549                    ),
550                    ..Default::default()
551                })),
552                const_value: Some("RSA1_5".into()),
553                ..Default::default()
554            }
555            .into(),
556            // ---
557            schemars::schema::SchemaObject {
558                metadata: Some(Box::new(schemars::schema::Metadata {
559                    description: Some(
560                        // ---
561                        r"RSAES OAEP using default parameters".to_owned(),
562                    ),
563                    ..Default::default()
564                })),
565                const_value: Some("RSA-OAEP".into()),
566                ..Default::default()
567            }
568            .into(),
569            // ---
570            schemars::schema::SchemaObject {
571                metadata: Some(Box::new(schemars::schema::Metadata {
572                    description: Some(
573                        // ---
574                        r"RSAES OAEP using SHA-256 and MGF1 with SHA-256".to_owned(),
575                    ),
576                    ..Default::default()
577                })),
578                const_value: Some("RSA-OAEP-256".into()),
579                ..Default::default()
580            }
581            .into(),
582            // ---
583            schemars::schema::SchemaObject {
584                metadata: Some(Box::new(schemars::schema::Metadata {
585                    description: Some(
586                        // ---
587                        r"AES Key Wrap using 128-bit key".to_owned(),
588                    ),
589                    ..Default::default()
590                })),
591                const_value: Some("A128KW".into()),
592                ..Default::default()
593            }
594            .into(),
595            // ---
596            schemars::schema::SchemaObject {
597                metadata: Some(Box::new(schemars::schema::Metadata {
598                    description: Some(
599                        // ---
600                        r"AES Key Wrap using 192-bit key".to_owned(),
601                    ),
602                    ..Default::default()
603                })),
604                const_value: Some("A192KW".into()),
605                ..Default::default()
606            }
607            .into(),
608            // ---
609            schemars::schema::SchemaObject {
610                metadata: Some(Box::new(schemars::schema::Metadata {
611                    description: Some(
612                        // ---
613                        r"AES Key Wrap using 256-bit key".to_owned(),
614                    ),
615                    ..Default::default()
616                })),
617                const_value: Some("A256KW".into()),
618                ..Default::default()
619            }
620            .into(),
621            // ---
622            schemars::schema::SchemaObject {
623                metadata: Some(Box::new(schemars::schema::Metadata {
624                    description: Some(
625                        // ---
626                        r"Direct use of a shared symmetric key".to_owned(),
627                    ),
628                    ..Default::default()
629                })),
630                const_value: Some("dir".into()),
631                ..Default::default()
632            }
633            .into(),
634            // ---
635            schemars::schema::SchemaObject {
636                metadata: Some(Box::new(schemars::schema::Metadata {
637                    description: Some(
638                        // ---
639                        r"ECDH-ES using Concat KDF".to_owned(),
640                    ),
641                    ..Default::default()
642                })),
643                const_value: Some("ECDH-ES".into()),
644                ..Default::default()
645            }
646            .into(),
647            // ---
648            schemars::schema::SchemaObject {
649                metadata: Some(Box::new(schemars::schema::Metadata {
650                    description: Some(
651                        // ---
652                        r#"ECDH-ES using Concat KDF and "A128KW" wrapping"#.to_owned(),
653                    ),
654                    ..Default::default()
655                })),
656                const_value: Some("ECDH-ES+A128KW".into()),
657                ..Default::default()
658            }
659            .into(),
660            // ---
661            schemars::schema::SchemaObject {
662                metadata: Some(Box::new(schemars::schema::Metadata {
663                    description: Some(
664                        // ---
665                        r#"ECDH-ES using Concat KDF and "A192KW" wrapping"#.to_owned(),
666                    ),
667                    ..Default::default()
668                })),
669                const_value: Some("ECDH-ES+A192KW".into()),
670                ..Default::default()
671            }
672            .into(),
673            // ---
674            schemars::schema::SchemaObject {
675                metadata: Some(Box::new(schemars::schema::Metadata {
676                    description: Some(
677                        // ---
678                        r#"ECDH-ES using Concat KDF and "A256KW" wrapping"#.to_owned(),
679                    ),
680                    ..Default::default()
681                })),
682                const_value: Some("ECDH-ES+A256KW".into()),
683                ..Default::default()
684            }
685            .into(),
686            // ---
687            schemars::schema::SchemaObject {
688                metadata: Some(Box::new(schemars::schema::Metadata {
689                    description: Some(
690                        // ---
691                        r"Key wrapping with AES GCM using 128-bit key".to_owned(),
692                    ),
693                    ..Default::default()
694                })),
695                const_value: Some("A128GCMKW".into()),
696                ..Default::default()
697            }
698            .into(),
699            // ---
700            schemars::schema::SchemaObject {
701                metadata: Some(Box::new(schemars::schema::Metadata {
702                    description: Some(
703                        // ---
704                        r"Key wrapping with AES GCM using 192-bit key".to_owned(),
705                    ),
706                    ..Default::default()
707                })),
708                const_value: Some("A192GCMKW".into()),
709                ..Default::default()
710            }
711            .into(),
712            // ---
713            schemars::schema::SchemaObject {
714                metadata: Some(Box::new(schemars::schema::Metadata {
715                    description: Some(
716                        // ---
717                        r"Key wrapping with AES GCM using 256-bit key".to_owned(),
718                    ),
719                    ..Default::default()
720                })),
721                const_value: Some("A256GCMKW".into()),
722                ..Default::default()
723            }
724            .into(),
725            // ---
726            schemars::schema::SchemaObject {
727                metadata: Some(Box::new(schemars::schema::Metadata {
728                    description: Some(
729                        // ---
730                        r#"PBES2 with HMAC SHA-256 and "A128KW" wrapping"#.to_owned(),
731                    ),
732                    ..Default::default()
733                })),
734                const_value: Some("PBES2-HS256+A128KW".into()),
735                ..Default::default()
736            }
737            .into(),
738            // ---
739            schemars::schema::SchemaObject {
740                metadata: Some(Box::new(schemars::schema::Metadata {
741                    description: Some(
742                        // ---
743                        r#"PBES2 with HMAC SHA-384 and "A192KW" wrapping"#.to_owned(),
744                    ),
745                    ..Default::default()
746                })),
747                const_value: Some("PBES2-HS384+A192KW".into()),
748                ..Default::default()
749            }
750            .into(),
751            // ---
752            schemars::schema::SchemaObject {
753                metadata: Some(Box::new(schemars::schema::Metadata {
754                    description: Some(
755                        // ---
756                        r#"PBES2 with HMAC SHA-512 and "A256KW" wrapping"#.to_owned(),
757                    ),
758                    ..Default::default()
759                })),
760                const_value: Some("PBES2-HS512+A256KW".into()),
761                ..Default::default()
762            }
763            .into(),
764            // ---
765            schemars::schema::SchemaObject {
766                metadata: Some(Box::new(schemars::schema::Metadata {
767                    description: Some(
768                        // ---
769                        r"RSA-OAEP using SHA-384 and MGF1 with SHA-384".to_owned(),
770                    ),
771                    ..Default::default()
772                })),
773                const_value: Some("RSA-OAEP-384".into()),
774                ..Default::default()
775            }
776            .into(),
777            // ---
778            schemars::schema::SchemaObject {
779                metadata: Some(Box::new(schemars::schema::Metadata {
780                    description: Some(
781                        // ---
782                        r"RSA-OAEP using SHA-512 and MGF1 with SHA-512".to_owned(),
783                    ),
784                    ..Default::default()
785                })),
786                const_value: Some("RSA-OAEP-512".into()),
787                ..Default::default()
788            }
789            .into(),
790        ];
791
792        let description = r#"JSON Web Encryption "alg" parameter"#;
793        schemars::schema::SchemaObject {
794            metadata: Some(Box::new(schemars::schema::Metadata {
795                description: Some(description.to_owned()),
796                ..Default::default()
797            })),
798            subschemas: Some(Box::new(schemars::schema::SubschemaValidation {
799                any_of: Some(enums),
800                ..Default::default()
801            })),
802            ..Default::default()
803        }
804        .into()
805    }
806}
807
808/// JSON Web Encryption "enc" parameter
809///
810/// Source: <http://www.iana.org/assignments/jose/web-signature-encryption-algorithms.csv>
811#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
812#[non_exhaustive]
813pub enum JsonWebEncryptionEnc {
814    /// AES_128_CBC_HMAC_SHA_256 authenticated encryption algorithm
815    A128CbcHs256,
816
817    /// AES_192_CBC_HMAC_SHA_384 authenticated encryption algorithm
818    A192CbcHs384,
819
820    /// AES_256_CBC_HMAC_SHA_512 authenticated encryption algorithm
821    A256CbcHs512,
822
823    /// AES GCM using 128-bit key
824    A128Gcm,
825
826    /// AES GCM using 192-bit key
827    A192Gcm,
828
829    /// AES GCM using 256-bit key
830    A256Gcm,
831
832    /// An unknown value.
833    Unknown(String),
834}
835
836impl core::fmt::Display for JsonWebEncryptionEnc {
837    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
838        match self {
839            Self::A128CbcHs256 => write!(f, "A128CBC-HS256"),
840            Self::A192CbcHs384 => write!(f, "A192CBC-HS384"),
841            Self::A256CbcHs512 => write!(f, "A256CBC-HS512"),
842            Self::A128Gcm => write!(f, "A128GCM"),
843            Self::A192Gcm => write!(f, "A192GCM"),
844            Self::A256Gcm => write!(f, "A256GCM"),
845            Self::Unknown(value) => write!(f, "{value}"),
846        }
847    }
848}
849
850impl core::str::FromStr for JsonWebEncryptionEnc {
851    type Err = core::convert::Infallible;
852
853    fn from_str(s: &str) -> Result<Self, Self::Err> {
854        match s {
855            "A128CBC-HS256" => Ok(Self::A128CbcHs256),
856            "A192CBC-HS384" => Ok(Self::A192CbcHs384),
857            "A256CBC-HS512" => Ok(Self::A256CbcHs512),
858            "A128GCM" => Ok(Self::A128Gcm),
859            "A192GCM" => Ok(Self::A192Gcm),
860            "A256GCM" => Ok(Self::A256Gcm),
861            value => Ok(Self::Unknown(value.to_owned())),
862        }
863    }
864}
865
866impl<'de> serde::Deserialize<'de> for JsonWebEncryptionEnc {
867    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
868    where
869        D: serde::de::Deserializer<'de>,
870    {
871        let s = String::deserialize(deserializer)?;
872        core::str::FromStr::from_str(&s).map_err(serde::de::Error::custom)
873    }
874}
875
876impl serde::Serialize for JsonWebEncryptionEnc {
877    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
878    where
879        S: serde::ser::Serializer,
880    {
881        serializer.serialize_str(&self.to_string())
882    }
883}
884
885impl schemars::JsonSchema for JsonWebEncryptionEnc {
886    fn schema_name() -> String {
887        "JsonWebEncryptionEnc".to_owned()
888    }
889
890    #[allow(clippy::too_many_lines)]
891    fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
892        let enums = vec![
893            // ---
894            schemars::schema::SchemaObject {
895                metadata: Some(Box::new(schemars::schema::Metadata {
896                    description: Some(
897                        // ---
898                        r"AES_128_CBC_HMAC_SHA_256 authenticated encryption algorithm".to_owned(),
899                    ),
900                    ..Default::default()
901                })),
902                const_value: Some("A128CBC-HS256".into()),
903                ..Default::default()
904            }
905            .into(),
906            // ---
907            schemars::schema::SchemaObject {
908                metadata: Some(Box::new(schemars::schema::Metadata {
909                    description: Some(
910                        // ---
911                        r"AES_192_CBC_HMAC_SHA_384 authenticated encryption algorithm".to_owned(),
912                    ),
913                    ..Default::default()
914                })),
915                const_value: Some("A192CBC-HS384".into()),
916                ..Default::default()
917            }
918            .into(),
919            // ---
920            schemars::schema::SchemaObject {
921                metadata: Some(Box::new(schemars::schema::Metadata {
922                    description: Some(
923                        // ---
924                        r"AES_256_CBC_HMAC_SHA_512 authenticated encryption algorithm".to_owned(),
925                    ),
926                    ..Default::default()
927                })),
928                const_value: Some("A256CBC-HS512".into()),
929                ..Default::default()
930            }
931            .into(),
932            // ---
933            schemars::schema::SchemaObject {
934                metadata: Some(Box::new(schemars::schema::Metadata {
935                    description: Some(
936                        // ---
937                        r"AES GCM using 128-bit key".to_owned(),
938                    ),
939                    ..Default::default()
940                })),
941                const_value: Some("A128GCM".into()),
942                ..Default::default()
943            }
944            .into(),
945            // ---
946            schemars::schema::SchemaObject {
947                metadata: Some(Box::new(schemars::schema::Metadata {
948                    description: Some(
949                        // ---
950                        r"AES GCM using 192-bit key".to_owned(),
951                    ),
952                    ..Default::default()
953                })),
954                const_value: Some("A192GCM".into()),
955                ..Default::default()
956            }
957            .into(),
958            // ---
959            schemars::schema::SchemaObject {
960                metadata: Some(Box::new(schemars::schema::Metadata {
961                    description: Some(
962                        // ---
963                        r"AES GCM using 256-bit key".to_owned(),
964                    ),
965                    ..Default::default()
966                })),
967                const_value: Some("A256GCM".into()),
968                ..Default::default()
969            }
970            .into(),
971        ];
972
973        let description = r#"JSON Web Encryption "enc" parameter"#;
974        schemars::schema::SchemaObject {
975            metadata: Some(Box::new(schemars::schema::Metadata {
976                description: Some(description.to_owned()),
977                ..Default::default()
978            })),
979            subschemas: Some(Box::new(schemars::schema::SubschemaValidation {
980                any_of: Some(enums),
981                ..Default::default()
982            })),
983            ..Default::default()
984        }
985        .into()
986    }
987}
988
989/// JSON Web Encryption Compression Algorithm
990///
991/// Source: <http://www.iana.org/assignments/jose/web-encryption-compression-algorithms.csv>
992#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
993#[non_exhaustive]
994pub enum JsonWebEncryptionCompressionAlgorithm {
995    /// DEFLATE
996    Def,
997
998    /// An unknown value.
999    Unknown(String),
1000}
1001
1002impl core::fmt::Display for JsonWebEncryptionCompressionAlgorithm {
1003    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1004        match self {
1005            Self::Def => write!(f, "DEF"),
1006            Self::Unknown(value) => write!(f, "{value}"),
1007        }
1008    }
1009}
1010
1011impl core::str::FromStr for JsonWebEncryptionCompressionAlgorithm {
1012    type Err = core::convert::Infallible;
1013
1014    fn from_str(s: &str) -> Result<Self, Self::Err> {
1015        match s {
1016            "DEF" => Ok(Self::Def),
1017            value => Ok(Self::Unknown(value.to_owned())),
1018        }
1019    }
1020}
1021
1022impl<'de> serde::Deserialize<'de> for JsonWebEncryptionCompressionAlgorithm {
1023    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1024    where
1025        D: serde::de::Deserializer<'de>,
1026    {
1027        let s = String::deserialize(deserializer)?;
1028        core::str::FromStr::from_str(&s).map_err(serde::de::Error::custom)
1029    }
1030}
1031
1032impl serde::Serialize for JsonWebEncryptionCompressionAlgorithm {
1033    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1034    where
1035        S: serde::ser::Serializer,
1036    {
1037        serializer.serialize_str(&self.to_string())
1038    }
1039}
1040
1041impl schemars::JsonSchema for JsonWebEncryptionCompressionAlgorithm {
1042    fn schema_name() -> String {
1043        "JsonWebEncryptionCompressionAlgorithm".to_owned()
1044    }
1045
1046    #[allow(clippy::too_many_lines)]
1047    fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
1048        let enums = vec![
1049            // ---
1050            schemars::schema::SchemaObject {
1051                metadata: Some(Box::new(schemars::schema::Metadata {
1052                    description: Some(
1053                        // ---
1054                        r"DEFLATE".to_owned(),
1055                    ),
1056                    ..Default::default()
1057                })),
1058                const_value: Some("DEF".into()),
1059                ..Default::default()
1060            }
1061            .into(),
1062        ];
1063
1064        let description = r"JSON Web Encryption Compression Algorithm";
1065        schemars::schema::SchemaObject {
1066            metadata: Some(Box::new(schemars::schema::Metadata {
1067                description: Some(description.to_owned()),
1068                ..Default::default()
1069            })),
1070            subschemas: Some(Box::new(schemars::schema::SubschemaValidation {
1071                any_of: Some(enums),
1072                ..Default::default()
1073            })),
1074            ..Default::default()
1075        }
1076        .into()
1077    }
1078}
1079
1080/// JSON Web Key Type
1081///
1082/// Source: <http://www.iana.org/assignments/jose/web-key-types.csv>
1083#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1084#[non_exhaustive]
1085pub enum JsonWebKeyType {
1086    /// Elliptic Curve
1087    Ec,
1088
1089    /// RSA
1090    Rsa,
1091
1092    /// Octet sequence
1093    Oct,
1094
1095    /// Octet string key pairs
1096    Okp,
1097
1098    /// An unknown value.
1099    Unknown(String),
1100}
1101
1102impl core::fmt::Display for JsonWebKeyType {
1103    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1104        match self {
1105            Self::Ec => write!(f, "EC"),
1106            Self::Rsa => write!(f, "RSA"),
1107            Self::Oct => write!(f, "oct"),
1108            Self::Okp => write!(f, "OKP"),
1109            Self::Unknown(value) => write!(f, "{value}"),
1110        }
1111    }
1112}
1113
1114impl core::str::FromStr for JsonWebKeyType {
1115    type Err = core::convert::Infallible;
1116
1117    fn from_str(s: &str) -> Result<Self, Self::Err> {
1118        match s {
1119            "EC" => Ok(Self::Ec),
1120            "RSA" => Ok(Self::Rsa),
1121            "oct" => Ok(Self::Oct),
1122            "OKP" => Ok(Self::Okp),
1123            value => Ok(Self::Unknown(value.to_owned())),
1124        }
1125    }
1126}
1127
1128impl<'de> serde::Deserialize<'de> for JsonWebKeyType {
1129    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1130    where
1131        D: serde::de::Deserializer<'de>,
1132    {
1133        let s = String::deserialize(deserializer)?;
1134        core::str::FromStr::from_str(&s).map_err(serde::de::Error::custom)
1135    }
1136}
1137
1138impl serde::Serialize for JsonWebKeyType {
1139    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1140    where
1141        S: serde::ser::Serializer,
1142    {
1143        serializer.serialize_str(&self.to_string())
1144    }
1145}
1146
1147impl schemars::JsonSchema for JsonWebKeyType {
1148    fn schema_name() -> String {
1149        "JsonWebKeyType".to_owned()
1150    }
1151
1152    #[allow(clippy::too_many_lines)]
1153    fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
1154        let enums = vec![
1155            // ---
1156            schemars::schema::SchemaObject {
1157                metadata: Some(Box::new(schemars::schema::Metadata {
1158                    description: Some(
1159                        // ---
1160                        r"Elliptic Curve".to_owned(),
1161                    ),
1162                    ..Default::default()
1163                })),
1164                const_value: Some("EC".into()),
1165                ..Default::default()
1166            }
1167            .into(),
1168            // ---
1169            schemars::schema::SchemaObject {
1170                metadata: Some(Box::new(schemars::schema::Metadata {
1171                    description: Some(
1172                        // ---
1173                        r"RSA".to_owned(),
1174                    ),
1175                    ..Default::default()
1176                })),
1177                const_value: Some("RSA".into()),
1178                ..Default::default()
1179            }
1180            .into(),
1181            // ---
1182            schemars::schema::SchemaObject {
1183                metadata: Some(Box::new(schemars::schema::Metadata {
1184                    description: Some(
1185                        // ---
1186                        r"Octet sequence".to_owned(),
1187                    ),
1188                    ..Default::default()
1189                })),
1190                const_value: Some("oct".into()),
1191                ..Default::default()
1192            }
1193            .into(),
1194            // ---
1195            schemars::schema::SchemaObject {
1196                metadata: Some(Box::new(schemars::schema::Metadata {
1197                    description: Some(
1198                        // ---
1199                        r"Octet string key pairs".to_owned(),
1200                    ),
1201                    ..Default::default()
1202                })),
1203                const_value: Some("OKP".into()),
1204                ..Default::default()
1205            }
1206            .into(),
1207        ];
1208
1209        let description = r"JSON Web Key Type";
1210        schemars::schema::SchemaObject {
1211            metadata: Some(Box::new(schemars::schema::Metadata {
1212                description: Some(description.to_owned()),
1213                ..Default::default()
1214            })),
1215            subschemas: Some(Box::new(schemars::schema::SubschemaValidation {
1216                any_of: Some(enums),
1217                ..Default::default()
1218            })),
1219            ..Default::default()
1220        }
1221        .into()
1222    }
1223}
1224
1225/// JSON Web Key EC Elliptic Curve
1226///
1227/// Source: <http://www.iana.org/assignments/jose/web-key-elliptic-curve.csv>
1228#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1229#[non_exhaustive]
1230pub enum JsonWebKeyEcEllipticCurve {
1231    /// P-256 Curve
1232    P256,
1233
1234    /// P-384 Curve
1235    P384,
1236
1237    /// P-521 Curve
1238    P521,
1239
1240    /// SECG secp256k1 curve
1241    Secp256K1,
1242
1243    /// An unknown value.
1244    Unknown(String),
1245}
1246
1247impl core::fmt::Display for JsonWebKeyEcEllipticCurve {
1248    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1249        match self {
1250            Self::P256 => write!(f, "P-256"),
1251            Self::P384 => write!(f, "P-384"),
1252            Self::P521 => write!(f, "P-521"),
1253            Self::Secp256K1 => write!(f, "secp256k1"),
1254            Self::Unknown(value) => write!(f, "{value}"),
1255        }
1256    }
1257}
1258
1259impl core::str::FromStr for JsonWebKeyEcEllipticCurve {
1260    type Err = core::convert::Infallible;
1261
1262    fn from_str(s: &str) -> Result<Self, Self::Err> {
1263        match s {
1264            "P-256" => Ok(Self::P256),
1265            "P-384" => Ok(Self::P384),
1266            "P-521" => Ok(Self::P521),
1267            "secp256k1" => Ok(Self::Secp256K1),
1268            value => Ok(Self::Unknown(value.to_owned())),
1269        }
1270    }
1271}
1272
1273impl<'de> serde::Deserialize<'de> for JsonWebKeyEcEllipticCurve {
1274    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1275    where
1276        D: serde::de::Deserializer<'de>,
1277    {
1278        let s = String::deserialize(deserializer)?;
1279        core::str::FromStr::from_str(&s).map_err(serde::de::Error::custom)
1280    }
1281}
1282
1283impl serde::Serialize for JsonWebKeyEcEllipticCurve {
1284    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1285    where
1286        S: serde::ser::Serializer,
1287    {
1288        serializer.serialize_str(&self.to_string())
1289    }
1290}
1291
1292impl schemars::JsonSchema for JsonWebKeyEcEllipticCurve {
1293    fn schema_name() -> String {
1294        "JsonWebKeyEcEllipticCurve".to_owned()
1295    }
1296
1297    #[allow(clippy::too_many_lines)]
1298    fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
1299        let enums = vec![
1300            // ---
1301            schemars::schema::SchemaObject {
1302                metadata: Some(Box::new(schemars::schema::Metadata {
1303                    description: Some(
1304                        // ---
1305                        r"P-256 Curve".to_owned(),
1306                    ),
1307                    ..Default::default()
1308                })),
1309                const_value: Some("P-256".into()),
1310                ..Default::default()
1311            }
1312            .into(),
1313            // ---
1314            schemars::schema::SchemaObject {
1315                metadata: Some(Box::new(schemars::schema::Metadata {
1316                    description: Some(
1317                        // ---
1318                        r"P-384 Curve".to_owned(),
1319                    ),
1320                    ..Default::default()
1321                })),
1322                const_value: Some("P-384".into()),
1323                ..Default::default()
1324            }
1325            .into(),
1326            // ---
1327            schemars::schema::SchemaObject {
1328                metadata: Some(Box::new(schemars::schema::Metadata {
1329                    description: Some(
1330                        // ---
1331                        r"P-521 Curve".to_owned(),
1332                    ),
1333                    ..Default::default()
1334                })),
1335                const_value: Some("P-521".into()),
1336                ..Default::default()
1337            }
1338            .into(),
1339            // ---
1340            schemars::schema::SchemaObject {
1341                metadata: Some(Box::new(schemars::schema::Metadata {
1342                    description: Some(
1343                        // ---
1344                        r"SECG secp256k1 curve".to_owned(),
1345                    ),
1346                    ..Default::default()
1347                })),
1348                const_value: Some("secp256k1".into()),
1349                ..Default::default()
1350            }
1351            .into(),
1352        ];
1353
1354        let description = r"JSON Web Key EC Elliptic Curve";
1355        schemars::schema::SchemaObject {
1356            metadata: Some(Box::new(schemars::schema::Metadata {
1357                description: Some(description.to_owned()),
1358                ..Default::default()
1359            })),
1360            subschemas: Some(Box::new(schemars::schema::SubschemaValidation {
1361                any_of: Some(enums),
1362                ..Default::default()
1363            })),
1364            ..Default::default()
1365        }
1366        .into()
1367    }
1368}
1369
1370/// JSON Web Key OKP Elliptic Curve
1371///
1372/// Source: <http://www.iana.org/assignments/jose/web-key-elliptic-curve.csv>
1373#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1374#[non_exhaustive]
1375pub enum JsonWebKeyOkpEllipticCurve {
1376    /// Ed25519 signature algorithm key pairs
1377    Ed25519,
1378
1379    /// Ed448 signature algorithm key pairs
1380    Ed448,
1381
1382    /// X25519 function key pairs
1383    X25519,
1384
1385    /// X448 function key pairs
1386    X448,
1387
1388    /// An unknown value.
1389    Unknown(String),
1390}
1391
1392impl core::fmt::Display for JsonWebKeyOkpEllipticCurve {
1393    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1394        match self {
1395            Self::Ed25519 => write!(f, "Ed25519"),
1396            Self::Ed448 => write!(f, "Ed448"),
1397            Self::X25519 => write!(f, "X25519"),
1398            Self::X448 => write!(f, "X448"),
1399            Self::Unknown(value) => write!(f, "{value}"),
1400        }
1401    }
1402}
1403
1404impl core::str::FromStr for JsonWebKeyOkpEllipticCurve {
1405    type Err = core::convert::Infallible;
1406
1407    fn from_str(s: &str) -> Result<Self, Self::Err> {
1408        match s {
1409            "Ed25519" => Ok(Self::Ed25519),
1410            "Ed448" => Ok(Self::Ed448),
1411            "X25519" => Ok(Self::X25519),
1412            "X448" => Ok(Self::X448),
1413            value => Ok(Self::Unknown(value.to_owned())),
1414        }
1415    }
1416}
1417
1418impl<'de> serde::Deserialize<'de> for JsonWebKeyOkpEllipticCurve {
1419    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1420    where
1421        D: serde::de::Deserializer<'de>,
1422    {
1423        let s = String::deserialize(deserializer)?;
1424        core::str::FromStr::from_str(&s).map_err(serde::de::Error::custom)
1425    }
1426}
1427
1428impl serde::Serialize for JsonWebKeyOkpEllipticCurve {
1429    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1430    where
1431        S: serde::ser::Serializer,
1432    {
1433        serializer.serialize_str(&self.to_string())
1434    }
1435}
1436
1437impl schemars::JsonSchema for JsonWebKeyOkpEllipticCurve {
1438    fn schema_name() -> String {
1439        "JsonWebKeyOkpEllipticCurve".to_owned()
1440    }
1441
1442    #[allow(clippy::too_many_lines)]
1443    fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
1444        let enums = vec![
1445            // ---
1446            schemars::schema::SchemaObject {
1447                metadata: Some(Box::new(schemars::schema::Metadata {
1448                    description: Some(
1449                        // ---
1450                        r"Ed25519 signature algorithm key pairs".to_owned(),
1451                    ),
1452                    ..Default::default()
1453                })),
1454                const_value: Some("Ed25519".into()),
1455                ..Default::default()
1456            }
1457            .into(),
1458            // ---
1459            schemars::schema::SchemaObject {
1460                metadata: Some(Box::new(schemars::schema::Metadata {
1461                    description: Some(
1462                        // ---
1463                        r"Ed448 signature algorithm key pairs".to_owned(),
1464                    ),
1465                    ..Default::default()
1466                })),
1467                const_value: Some("Ed448".into()),
1468                ..Default::default()
1469            }
1470            .into(),
1471            // ---
1472            schemars::schema::SchemaObject {
1473                metadata: Some(Box::new(schemars::schema::Metadata {
1474                    description: Some(
1475                        // ---
1476                        r"X25519 function key pairs".to_owned(),
1477                    ),
1478                    ..Default::default()
1479                })),
1480                const_value: Some("X25519".into()),
1481                ..Default::default()
1482            }
1483            .into(),
1484            // ---
1485            schemars::schema::SchemaObject {
1486                metadata: Some(Box::new(schemars::schema::Metadata {
1487                    description: Some(
1488                        // ---
1489                        r"X448 function key pairs".to_owned(),
1490                    ),
1491                    ..Default::default()
1492                })),
1493                const_value: Some("X448".into()),
1494                ..Default::default()
1495            }
1496            .into(),
1497        ];
1498
1499        let description = r"JSON Web Key OKP Elliptic Curve";
1500        schemars::schema::SchemaObject {
1501            metadata: Some(Box::new(schemars::schema::Metadata {
1502                description: Some(description.to_owned()),
1503                ..Default::default()
1504            })),
1505            subschemas: Some(Box::new(schemars::schema::SubschemaValidation {
1506                any_of: Some(enums),
1507                ..Default::default()
1508            })),
1509            ..Default::default()
1510        }
1511        .into()
1512    }
1513}
1514
1515/// JSON Web Key Use
1516///
1517/// Source: <http://www.iana.org/assignments/jose/web-key-use.csv>
1518#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1519#[non_exhaustive]
1520pub enum JsonWebKeyUse {
1521    /// Digital Signature or MAC
1522    Sig,
1523
1524    /// Encryption
1525    Enc,
1526
1527    /// An unknown value.
1528    Unknown(String),
1529}
1530
1531impl core::fmt::Display for JsonWebKeyUse {
1532    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1533        match self {
1534            Self::Sig => write!(f, "sig"),
1535            Self::Enc => write!(f, "enc"),
1536            Self::Unknown(value) => write!(f, "{value}"),
1537        }
1538    }
1539}
1540
1541impl core::str::FromStr for JsonWebKeyUse {
1542    type Err = core::convert::Infallible;
1543
1544    fn from_str(s: &str) -> Result<Self, Self::Err> {
1545        match s {
1546            "sig" => Ok(Self::Sig),
1547            "enc" => Ok(Self::Enc),
1548            value => Ok(Self::Unknown(value.to_owned())),
1549        }
1550    }
1551}
1552
1553impl<'de> serde::Deserialize<'de> for JsonWebKeyUse {
1554    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1555    where
1556        D: serde::de::Deserializer<'de>,
1557    {
1558        let s = String::deserialize(deserializer)?;
1559        core::str::FromStr::from_str(&s).map_err(serde::de::Error::custom)
1560    }
1561}
1562
1563impl serde::Serialize for JsonWebKeyUse {
1564    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1565    where
1566        S: serde::ser::Serializer,
1567    {
1568        serializer.serialize_str(&self.to_string())
1569    }
1570}
1571
1572impl schemars::JsonSchema for JsonWebKeyUse {
1573    fn schema_name() -> String {
1574        "JsonWebKeyUse".to_owned()
1575    }
1576
1577    #[allow(clippy::too_many_lines)]
1578    fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
1579        let enums = vec![
1580            // ---
1581            schemars::schema::SchemaObject {
1582                metadata: Some(Box::new(schemars::schema::Metadata {
1583                    description: Some(
1584                        // ---
1585                        r"Digital Signature or MAC".to_owned(),
1586                    ),
1587                    ..Default::default()
1588                })),
1589                const_value: Some("sig".into()),
1590                ..Default::default()
1591            }
1592            .into(),
1593            // ---
1594            schemars::schema::SchemaObject {
1595                metadata: Some(Box::new(schemars::schema::Metadata {
1596                    description: Some(
1597                        // ---
1598                        r"Encryption".to_owned(),
1599                    ),
1600                    ..Default::default()
1601                })),
1602                const_value: Some("enc".into()),
1603                ..Default::default()
1604            }
1605            .into(),
1606        ];
1607
1608        let description = r"JSON Web Key Use";
1609        schemars::schema::SchemaObject {
1610            metadata: Some(Box::new(schemars::schema::Metadata {
1611                description: Some(description.to_owned()),
1612                ..Default::default()
1613            })),
1614            subschemas: Some(Box::new(schemars::schema::SubschemaValidation {
1615                any_of: Some(enums),
1616                ..Default::default()
1617            })),
1618            ..Default::default()
1619        }
1620        .into()
1621    }
1622}
1623
1624/// JSON Web Key Operation
1625///
1626/// Source: <http://www.iana.org/assignments/jose/web-key-operations.csv>
1627#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1628#[non_exhaustive]
1629pub enum JsonWebKeyOperation {
1630    /// Compute digital signature or MAC
1631    Sign,
1632
1633    /// Verify digital signature or MAC
1634    Verify,
1635
1636    /// Encrypt content
1637    Encrypt,
1638
1639    /// Decrypt content and validate decryption, if applicable
1640    Decrypt,
1641
1642    /// Encrypt key
1643    WrapKey,
1644
1645    /// Decrypt key and validate decryption, if applicable
1646    UnwrapKey,
1647
1648    /// Derive key
1649    DeriveKey,
1650
1651    /// Derive bits not to be used as a key
1652    DeriveBits,
1653
1654    /// An unknown value.
1655    Unknown(String),
1656}
1657
1658impl core::fmt::Display for JsonWebKeyOperation {
1659    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1660        match self {
1661            Self::Sign => write!(f, "sign"),
1662            Self::Verify => write!(f, "verify"),
1663            Self::Encrypt => write!(f, "encrypt"),
1664            Self::Decrypt => write!(f, "decrypt"),
1665            Self::WrapKey => write!(f, "wrapKey"),
1666            Self::UnwrapKey => write!(f, "unwrapKey"),
1667            Self::DeriveKey => write!(f, "deriveKey"),
1668            Self::DeriveBits => write!(f, "deriveBits"),
1669            Self::Unknown(value) => write!(f, "{value}"),
1670        }
1671    }
1672}
1673
1674impl core::str::FromStr for JsonWebKeyOperation {
1675    type Err = core::convert::Infallible;
1676
1677    fn from_str(s: &str) -> Result<Self, Self::Err> {
1678        match s {
1679            "sign" => Ok(Self::Sign),
1680            "verify" => Ok(Self::Verify),
1681            "encrypt" => Ok(Self::Encrypt),
1682            "decrypt" => Ok(Self::Decrypt),
1683            "wrapKey" => Ok(Self::WrapKey),
1684            "unwrapKey" => Ok(Self::UnwrapKey),
1685            "deriveKey" => Ok(Self::DeriveKey),
1686            "deriveBits" => Ok(Self::DeriveBits),
1687            value => Ok(Self::Unknown(value.to_owned())),
1688        }
1689    }
1690}
1691
1692impl<'de> serde::Deserialize<'de> for JsonWebKeyOperation {
1693    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1694    where
1695        D: serde::de::Deserializer<'de>,
1696    {
1697        let s = String::deserialize(deserializer)?;
1698        core::str::FromStr::from_str(&s).map_err(serde::de::Error::custom)
1699    }
1700}
1701
1702impl serde::Serialize for JsonWebKeyOperation {
1703    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1704    where
1705        S: serde::ser::Serializer,
1706    {
1707        serializer.serialize_str(&self.to_string())
1708    }
1709}
1710
1711impl schemars::JsonSchema for JsonWebKeyOperation {
1712    fn schema_name() -> String {
1713        "JsonWebKeyOperation".to_owned()
1714    }
1715
1716    #[allow(clippy::too_many_lines)]
1717    fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
1718        let enums = vec![
1719            // ---
1720            schemars::schema::SchemaObject {
1721                metadata: Some(Box::new(schemars::schema::Metadata {
1722                    description: Some(
1723                        // ---
1724                        r"Compute digital signature or MAC".to_owned(),
1725                    ),
1726                    ..Default::default()
1727                })),
1728                const_value: Some("sign".into()),
1729                ..Default::default()
1730            }
1731            .into(),
1732            // ---
1733            schemars::schema::SchemaObject {
1734                metadata: Some(Box::new(schemars::schema::Metadata {
1735                    description: Some(
1736                        // ---
1737                        r"Verify digital signature or MAC".to_owned(),
1738                    ),
1739                    ..Default::default()
1740                })),
1741                const_value: Some("verify".into()),
1742                ..Default::default()
1743            }
1744            .into(),
1745            // ---
1746            schemars::schema::SchemaObject {
1747                metadata: Some(Box::new(schemars::schema::Metadata {
1748                    description: Some(
1749                        // ---
1750                        r"Encrypt content".to_owned(),
1751                    ),
1752                    ..Default::default()
1753                })),
1754                const_value: Some("encrypt".into()),
1755                ..Default::default()
1756            }
1757            .into(),
1758            // ---
1759            schemars::schema::SchemaObject {
1760                metadata: Some(Box::new(schemars::schema::Metadata {
1761                    description: Some(
1762                        // ---
1763                        r"Decrypt content and validate decryption, if applicable".to_owned(),
1764                    ),
1765                    ..Default::default()
1766                })),
1767                const_value: Some("decrypt".into()),
1768                ..Default::default()
1769            }
1770            .into(),
1771            // ---
1772            schemars::schema::SchemaObject {
1773                metadata: Some(Box::new(schemars::schema::Metadata {
1774                    description: Some(
1775                        // ---
1776                        r"Encrypt key".to_owned(),
1777                    ),
1778                    ..Default::default()
1779                })),
1780                const_value: Some("wrapKey".into()),
1781                ..Default::default()
1782            }
1783            .into(),
1784            // ---
1785            schemars::schema::SchemaObject {
1786                metadata: Some(Box::new(schemars::schema::Metadata {
1787                    description: Some(
1788                        // ---
1789                        r"Decrypt key and validate decryption, if applicable".to_owned(),
1790                    ),
1791                    ..Default::default()
1792                })),
1793                const_value: Some("unwrapKey".into()),
1794                ..Default::default()
1795            }
1796            .into(),
1797            // ---
1798            schemars::schema::SchemaObject {
1799                metadata: Some(Box::new(schemars::schema::Metadata {
1800                    description: Some(
1801                        // ---
1802                        r"Derive key".to_owned(),
1803                    ),
1804                    ..Default::default()
1805                })),
1806                const_value: Some("deriveKey".into()),
1807                ..Default::default()
1808            }
1809            .into(),
1810            // ---
1811            schemars::schema::SchemaObject {
1812                metadata: Some(Box::new(schemars::schema::Metadata {
1813                    description: Some(
1814                        // ---
1815                        r"Derive bits not to be used as a key".to_owned(),
1816                    ),
1817                    ..Default::default()
1818                })),
1819                const_value: Some("deriveBits".into()),
1820                ..Default::default()
1821            }
1822            .into(),
1823        ];
1824
1825        let description = r"JSON Web Key Operation";
1826        schemars::schema::SchemaObject {
1827            metadata: Some(Box::new(schemars::schema::Metadata {
1828                description: Some(description.to_owned()),
1829                ..Default::default()
1830            })),
1831            subschemas: Some(Box::new(schemars::schema::SubschemaValidation {
1832                any_of: Some(enums),
1833                ..Default::default()
1834            })),
1835            ..Default::default()
1836        }
1837        .into()
1838    }
1839}