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