1#[cfg(feature = "json")]
2use serde::{Deserialize, Serialize};
3
4#[derive(Clone, Debug)]
8#[cfg_attr(feature = "json", derive(Serialize, Deserialize))]
9pub struct JsonWebKey {
10 #[cfg_attr(feature = "json", serde(rename = "kty"))]
11 pub key_type: String,
12 #[cfg_attr(feature = "json", serde(rename = "e"))]
13 pub exponent: String,
14 #[cfg_attr(feature = "json", serde(rename = "n"))]
15 pub modulus: String,
16}
17
18#[cfg(feature = "json")]
19impl JsonWebKey {
20 pub fn from_str(s: &str) -> Result<JsonWebKey, serde_json::error::Error> {
22 serde_json::from_str(s)
23 }
24
25 pub fn to_string(&self) -> Result<String, serde_json::error::Error> {
27 serde_json::to_string(self)
28 }
29}
30
31#[derive(Clone, Debug)]
35#[cfg_attr(feature = "json", derive(Serialize, Deserialize))]
36pub struct JsonWebSignature {
37 pub protected: String,
38 pub payload: String,
39 pub signature: String,
40}
41
42#[cfg(feature = "json")]
43impl JsonWebSignature {
44 pub fn from_str(s: &str) -> Result<JsonWebSignature, serde_json::error::Error> {
46 serde_json::from_str(s)
47 }
48
49 pub fn to_string(&self) -> Result<String, serde_json::error::Error> {
51 serde_json::to_string(self)
52 }
53}
54
55#[derive(Clone, Debug)]
59#[cfg_attr(feature = "json", derive(Serialize, Deserialize))]
60pub struct JsonWebSignatureProtected {
61 #[cfg_attr(feature = "json", serde(rename = "alg"))]
62 pub algorithm: String,
63 #[cfg_attr(feature = "json", serde(skip_serializing_if = "Option::is_none"))]
64 pub nonce: Option<String>,
65 pub url: String,
66 #[cfg_attr(feature = "json", serde(skip_serializing_if = "Option::is_none"))]
67 #[cfg_attr(feature = "json", serde(rename = "jwk"))]
68 pub json_web_key: Option<JsonWebKey>,
69 #[cfg_attr(feature = "json", serde(skip_serializing_if = "Option::is_none"))]
70 #[cfg_attr(feature = "json", serde(rename = "kid"))]
71 pub key_id: Option<String>,
72}
73
74#[cfg(feature = "json")]
75impl JsonWebSignatureProtected {
76 pub fn from_str(s: &str) -> Result<JsonWebSignatureProtected, serde_json::error::Error> {
78 serde_json::from_str(s)
79 }
80
81 pub fn to_string(&self) -> Result<String, serde_json::error::Error> {
83 serde_json::to_string(self)
84 }
85}