#[cfg(feature = "json")]
use serde::{Deserialize, Deserializer, Serialize, Serializer};
#[derive(Clone, Debug)]
#[cfg_attr(feature = "json", derive(Serialize, Deserialize))]
pub struct NewOrder {
pub identifiers: Vec<super::Identifier>,
#[cfg_attr(feature = "json", serde(skip_serializing_if = "Option::is_none"))]
#[cfg_attr(feature = "json", serde(rename = "notBefore"))]
pub not_before: Option<String>,
#[cfg_attr(feature = "json", serde(skip_serializing_if = "Option::is_none"))]
#[cfg_attr(feature = "json", serde(rename = "notAfter"))]
pub not_after: Option<String>,
}
#[cfg(feature = "json")]
impl NewOrder {
pub fn from_str(s: &str) -> Result<NewOrder, 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 Order {
pub status: OrderStatus,
pub expires: String,
pub identifiers: Vec<super::Identifier>,
#[cfg_attr(feature = "json", serde(skip_serializing_if = "Option::is_none"))]
#[cfg_attr(feature = "json", serde(rename = "notBefore"))]
pub not_before: Option<String>,
#[cfg_attr(feature = "json", serde(skip_serializing_if = "Option::is_none"))]
#[cfg_attr(feature = "json", serde(rename = "notAfter"))]
pub not_after: Option<String>,
pub error: Option<String>,
pub authorizations: Option<String>,
pub finalize: String,
pub certificate: String,
}
#[cfg(feature = "json")]
impl Order {
pub fn from_str(s: &str) -> Result<Order, 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 OrderFinalize {
#[cfg_attr(feature = "json", serde(rename = "csr"))]
pub certificate_signing_request: String,
}
#[cfg(feature = "json")]
impl OrderFinalize {
pub fn from_str(s: &str) -> Result<OrderFinalize, 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 enum OrderStatus {
#[cfg_attr(feature = "json", serde(rename = "pending"))]
Pending,
#[cfg_attr(feature = "json", serde(rename = "ready"))]
Ready,
#[cfg_attr(feature = "json", serde(rename = "processing"))]
Processing,
#[cfg_attr(feature = "json", serde(rename = "valid"))]
Valid,
#[cfg_attr(feature = "json", serde(rename = "invalid"))]
Invalid,
}
#[derive(Clone, Debug)]
#[cfg_attr(feature = "json", derive(Serialize, Deserialize))]
pub struct CertificateRevocation {
pub certificate: String,
#[cfg_attr(feature = "json", serde(skip_serializing_if = "Option::is_none"))]
#[cfg_attr(
feature = "json",
serde(serialize_with = "certificate_revocation_reason_serialize")
)]
#[cfg_attr(
feature = "json",
serde(deserialize_with = "certificate_revocation_reason_deserialize")
)]
pub reason: Option<CertificateRevocationReason>,
}
#[cfg(feature = "json")]
impl CertificateRevocation {
pub fn from_str(s: &str) -> Result<CertificateRevocation, 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 enum CertificateRevocationReason {
Unspecified,
KeyCompromise,
CertificateAuthorityCompromise,
AffiliationChanged,
Superseded,
CessationOfOperation,
CertificateHold,
RemoveFromCertificateRevocationList,
PrivilegeWithdrawn,
AuthorityAttributeCompromise,
Other(i32),
}
#[cfg(feature = "json")]
fn certificate_revocation_reason_deserialize<'de, D>(
deserializer: D,
) -> Result<Option<CertificateRevocationReason>, D::Error>
where
D: Deserializer<'de>,
{
use self::CertificateRevocationReason::*;
let n = String::deserialize(deserializer)?.parse::<i32>().unwrap();
Ok(Some(match n {
0 => Unspecified,
1 => KeyCompromise,
2 => CertificateAuthorityCompromise,
3 => AffiliationChanged,
4 => Superseded,
5 => CessationOfOperation,
6 => CertificateHold,
8 => RemoveFromCertificateRevocationList,
9 => PrivilegeWithdrawn,
10 => AuthorityAttributeCompromise,
_ => Other(n),
}))
}
#[cfg(feature = "json")]
fn certificate_revocation_reason_serialize<S>(
type_: &Option<CertificateRevocationReason>,
serializer: S,
) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
use self::CertificateRevocationReason::*;
serializer.serialize_i32(match type_.clone().unwrap() {
Other(i) => i,
Unspecified => 0,
KeyCompromise => 1,
CertificateAuthorityCompromise => 2,
AffiliationChanged => 3,
Superseded => 4,
CessationOfOperation => 5,
CertificateHold => 6,
RemoveFromCertificateRevocationList => 8,
PrivilegeWithdrawn => 9,
AuthorityAttributeCompromise => 10,
})
}