#[cfg(feature = "json")]
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug)]
#[cfg_attr(feature = "json", derive(Serialize, Deserialize))]
pub struct JsonWebKey {
#[cfg_attr(feature = "json", serde(rename = "kty"))]
pub key_type: String,
#[cfg_attr(feature = "json", serde(rename = "e"))]
pub exponent: String,
#[cfg_attr(feature = "json", serde(rename = "n"))]
pub modulus: String,
}
#[cfg(feature = "json")]
impl JsonWebKey {
pub fn from_str(s: &str) -> Result<JsonWebKey, serde_json::error::Error> {
serde_json::from_str(s)
}
pub fn to_string(&self) -> Result<String, serde_json::error::Error> {
serde_json::to_string(self)
}
}
#[derive(Clone, Debug)]
#[cfg_attr(feature = "json", derive(Serialize, Deserialize))]
pub struct JsonWebSignature {
pub protected: String,
pub payload: String,
pub signature: String,
}
#[cfg(feature = "json")]
impl JsonWebSignature {
pub fn from_str(s: &str) -> Result<JsonWebSignature, serde_json::error::Error> {
serde_json::from_str(s)
}
pub fn to_string(&self) -> Result<String, serde_json::error::Error> {
serde_json::to_string(self)
}
}
#[derive(Clone, Debug)]
#[cfg_attr(feature = "json", derive(Serialize, Deserialize))]
pub struct JsonWebSignatureProtected {
#[cfg_attr(feature = "json", serde(rename = "alg"))]
pub algorithm: String,
#[cfg_attr(feature = "json", serde(skip_serializing_if = "Option::is_none"))]
pub nonce: Option<String>,
pub url: String,
#[cfg_attr(feature = "json", serde(skip_serializing_if = "Option::is_none"))]
#[cfg_attr(feature = "json", serde(rename = "jwk"))]
pub json_web_key: Option<JsonWebKey>,
#[cfg_attr(feature = "json", serde(skip_serializing_if = "Option::is_none"))]
#[cfg_attr(feature = "json", serde(rename = "kid"))]
pub key_id: Option<String>,
}
#[cfg(feature = "json")]
impl JsonWebSignatureProtected {
pub fn from_str(s: &str) -> Result<JsonWebSignatureProtected, serde_json::error::Error> {
serde_json::from_str(s)
}
pub fn to_string(&self) -> Result<String, serde_json::error::Error> {
serde_json::to_string(self)
}
}