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