#![allow(non_snake_case)]
#![allow(non_camel_case_types)]
use serde::{
ser::{SerializeMap, Serializer},
Deserialize, Serialize,
};
pub struct ApiEmptyString;
impl Serialize for ApiEmptyString {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str("")
}
}
pub struct ApiEmptyObject;
impl Serialize for ApiEmptyObject {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let m = serializer.serialize_map(Some(0))?;
m.end()
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
pub struct ApiProblem {
#[serde(rename = "type")]
pub _type: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub detail: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub subproblems: Option<Vec<ApiSubproblem>>,
}
impl ApiProblem {
pub fn is_bad_nonce(&self) -> bool {
self._type == "badNonce"
}
pub fn is_jwt_verification_error(&self) -> bool {
self._type == "urn:acme:error:malformed"
&& self
.detail
.as_ref()
.map(|s| s == "JWS verification error")
.unwrap_or(false)
}
}
impl ::std::fmt::Display for ApiProblem {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
if let Some(detail) = &self.detail {
write!(f, "{}: {}", self._type, detail)
} else {
write!(f, "{}", self._type)
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
pub struct ApiSubproblem {
#[serde(rename = "type")]
pub _type: String,
pub detail: Option<String>,
pub identifier: Option<ApiIdentifier>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
pub struct ApiDirectory {
pub newNonce: String,
pub newAccount: String,
pub newOrder: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub newAuthz: Option<String>,
pub revokeCert: String,
pub keyChange: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub meta: Option<ApiDirectoryMeta>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
pub struct ApiDirectoryMeta {
#[serde(skip_serializing_if = "Option::is_none")]
pub termsOfService: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub website: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caaIdentities: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub externalAccountRequired: Option<bool>,
}
impl ApiDirectoryMeta {
pub fn externalAccountRequired(&self) -> bool {
self.externalAccountRequired.unwrap_or(false)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
pub struct ApiAccount {
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<String>,
pub contact: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub termsOfServiceAgreed: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub orders: Option<String>,
}
impl ApiAccount {
pub fn is_status_valid(&self) -> bool {
self.status.as_ref().map(|s| s.as_ref()) == Some("valid")
}
pub fn is_status_deactivated(&self) -> bool {
self.status.as_ref().map(|s| s.as_ref()) == Some("deactivated")
}
pub fn is_status_revoked(&self) -> bool {
self.status.as_ref().map(|s| s.as_ref()) == Some("revoked")
}
pub fn termsOfServiceAgreed(&self) -> bool {
self.termsOfServiceAgreed.unwrap_or(false)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
pub struct ApiOrder {
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub expires: Option<String>,
pub identifiers: Vec<ApiIdentifier>,
pub notBefore: Option<String>,
pub notAfter: Option<String>,
pub error: Option<ApiProblem>,
pub authorizations: Option<Vec<String>>,
pub finalize: String,
pub certificate: Option<String>,
}
impl ApiOrder {
pub fn is_status_pending(&self) -> bool {
self.status.as_ref().map(|s| s.as_ref()) == Some("pending")
}
pub fn is_status_ready(&self) -> bool {
self.status.as_ref().map(|s| s.as_ref()) == Some("ready")
}
pub fn is_status_processing(&self) -> bool {
self.status.as_ref().map(|s| s.as_ref()) == Some("processing")
}
pub fn is_status_valid(&self) -> bool {
self.status.as_ref().map(|s| s.as_ref()) == Some("valid")
}
pub fn is_status_invalid(&self) -> bool {
self.status.as_ref().map(|s| s.as_ref()) == Some("invalid")
}
pub fn domains(&self) -> Vec<&str> {
self.identifiers.iter().map(|i| i.value.as_ref()).collect()
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ApiIdentifier {
#[serde(rename = "type")]
pub _type: String,
pub value: String,
}
impl ApiIdentifier {
pub fn is_type_dns(&self) -> bool {
self._type == "dns"
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ApiAuth {
pub identifier: ApiIdentifier,
pub status: Option<String>,
pub expires: Option<String>,
pub challenges: Vec<ApiChallenge>,
pub wildcard: Option<bool>,
}
impl ApiAuth {
pub fn is_status_pending(&self) -> bool {
self.status.as_ref().map(|s| s.as_ref()) == Some("pending")
}
pub fn is_status_valid(&self) -> bool {
self.status.as_ref().map(|s| s.as_ref()) == Some("valid")
}
pub fn is_status_invalid(&self) -> bool {
self.status.as_ref().map(|s| s.as_ref()) == Some("invalid")
}
pub fn is_status_deactivated(&self) -> bool {
self.status.as_ref().map(|s| s.as_ref()) == Some("deactivated")
}
pub fn is_status_expired(&self) -> bool {
self.status.as_ref().map(|s| s.as_ref()) == Some("expired")
}
pub fn is_status_revoked(&self) -> bool {
self.status.as_ref().map(|s| s.as_ref()) == Some("revoked")
}
pub fn wildcard(&self) -> bool {
self.wildcard.unwrap_or(false)
}
pub fn http_challenge(&self) -> Option<&ApiChallenge> {
self.challenges.iter().find(|c| c._type == "http-01")
}
pub fn dns_challenge(&self) -> Option<&ApiChallenge> {
self.challenges.iter().find(|c| c._type == "dns-01")
}
pub fn tls_alpn_challenge(&self) -> Option<&ApiChallenge> {
self.challenges.iter().find(|c| c._type == "tls-alpn-01")
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ApiChallenge {
pub url: String,
#[serde(rename = "type")]
pub _type: String,
pub status: String,
pub token: String,
pub validated: Option<String>,
pub error: Option<ApiProblem>,
}
impl ApiChallenge {
pub fn is_status_pending(&self) -> bool {
&self.status == "pending"
}
pub fn is_status_processing(&self) -> bool {
&self.status == "processing"
}
pub fn is_status_valid(&self) -> bool {
&self.status == "valid"
}
pub fn is_status_invalid(&self) -> bool {
&self.status == "invalid"
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ApiFinalize {
pub csr: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ApiRevocation {
pub certificate: String,
pub reason: usize,
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_api_empty_string() {
let x = serde_json::to_string(&ApiEmptyString).unwrap();
assert_eq!("\"\"", x);
}
#[test]
fn test_api_empty_object() {
let x = serde_json::to_string(&ApiEmptyObject).unwrap();
assert_eq!("{}", x);
}
}