1#[cfg(feature = "json")]
2use serde::{Deserialize, Deserializer, Serialize, Serializer};
3
4#[derive(Clone, Debug)]
8#[cfg_attr(feature = "json", derive(Serialize, Deserialize))]
9pub struct NewOrder {
10 pub identifiers: Vec<super::Identifier>,
12 #[cfg_attr(feature = "json", serde(skip_serializing_if = "Option::is_none"))]
14 #[cfg_attr(feature = "json", serde(rename = "notBefore"))]
15 pub not_before: Option<String>,
16 #[cfg_attr(feature = "json", serde(skip_serializing_if = "Option::is_none"))]
18 #[cfg_attr(feature = "json", serde(rename = "notAfter"))]
19 pub not_after: Option<String>,
20}
21
22#[cfg(feature = "json")]
23impl NewOrder {
24 pub fn from_str(s: &str) -> Result<NewOrder, serde_json::error::Error> {
26 serde_json::from_str(s)
27 }
28
29 pub fn to_string(&self) -> Result<String, serde_json::error::Error> {
31 serde_json::to_string(self)
32 }
33}
34
35#[derive(Clone, Debug)]
39#[cfg_attr(feature = "json", derive(Serialize, Deserialize))]
40pub struct Order {
41 pub status: OrderStatus,
43 pub expires: String,
45 pub identifiers: Vec<super::Identifier>,
47 #[cfg_attr(feature = "json", serde(skip_serializing_if = "Option::is_none"))]
49 #[cfg_attr(feature = "json", serde(rename = "notBefore"))]
50 pub not_before: Option<String>,
51 #[cfg_attr(feature = "json", serde(skip_serializing_if = "Option::is_none"))]
53 #[cfg_attr(feature = "json", serde(rename = "notAfter"))]
54 pub not_after: Option<String>,
55 pub error: Option<String>,
57 pub authorizations: Option<String>,
59 pub finalize: String,
61 pub certificate: String,
63}
64
65#[cfg(feature = "json")]
66impl Order {
67 pub fn from_str(s: &str) -> Result<Order, serde_json::error::Error> {
69 serde_json::from_str(s)
70 }
71
72 pub fn to_string(&self) -> Result<String, serde_json::error::Error> {
74 serde_json::to_string(self)
75 }
76}
77
78#[derive(Clone, Debug)]
82#[cfg_attr(feature = "json", derive(Serialize, Deserialize))]
83pub struct OrderFinalize {
84 #[cfg_attr(feature = "json", serde(rename = "csr"))]
86 pub certificate_signing_request: String,
87}
88
89#[cfg(feature = "json")]
90impl OrderFinalize {
91 pub fn from_str(s: &str) -> Result<OrderFinalize, serde_json::error::Error> {
93 serde_json::from_str(s)
94 }
95
96 pub fn to_string(&self) -> Result<String, serde_json::error::Error> {
98 serde_json::to_string(self)
99 }
100}
101
102#[derive(Clone, Debug)]
106#[cfg_attr(feature = "json", derive(Serialize, Deserialize))]
107pub enum OrderStatus {
108 #[cfg_attr(feature = "json", serde(rename = "pending"))]
109 Pending,
110 #[cfg_attr(feature = "json", serde(rename = "ready"))]
111 Ready,
112 #[cfg_attr(feature = "json", serde(rename = "processing"))]
113 Processing,
114 #[cfg_attr(feature = "json", serde(rename = "valid"))]
115 Valid,
116 #[cfg_attr(feature = "json", serde(rename = "invalid"))]
117 Invalid,
118}
119
120#[derive(Clone, Debug)]
124#[cfg_attr(feature = "json", derive(Serialize, Deserialize))]
125pub struct CertificateRevocation {
126 pub certificate: String,
128 #[cfg_attr(feature = "json", serde(skip_serializing_if = "Option::is_none"))]
132 #[cfg_attr(
133 feature = "json",
134 serde(serialize_with = "certificate_revocation_reason_serialize")
135 )]
136 #[cfg_attr(
137 feature = "json",
138 serde(deserialize_with = "certificate_revocation_reason_deserialize")
139 )]
140 pub reason: Option<CertificateRevocationReason>,
141}
142
143#[cfg(feature = "json")]
144impl CertificateRevocation {
145 pub fn from_str(s: &str) -> Result<CertificateRevocation, serde_json::error::Error> {
147 serde_json::from_str(s)
148 }
149
150 pub fn to_string(&self) -> Result<String, serde_json::error::Error> {
152 serde_json::to_string(self)
153 }
154}
155
156#[derive(Clone, Debug)]
160#[cfg_attr(feature = "json", derive(Serialize, Deserialize))]
161pub enum CertificateRevocationReason {
162 Unspecified,
163 KeyCompromise,
164 CertificateAuthorityCompromise,
165 AffiliationChanged,
166 Superseded,
167 CessationOfOperation,
168 CertificateHold,
169 RemoveFromCertificateRevocationList,
170 PrivilegeWithdrawn,
171 AuthorityAttributeCompromise,
172 Other(i32),
173}
174
175#[cfg(feature = "json")]
176fn certificate_revocation_reason_deserialize<'de, D>(
177 deserializer: D,
178) -> Result<Option<CertificateRevocationReason>, D::Error>
179where
180 D: Deserializer<'de>,
181{
182 use self::CertificateRevocationReason::*;
183
184 let n = String::deserialize(deserializer)?.parse::<i32>().unwrap();
185
186 Ok(Some(match n {
187 0 => Unspecified,
188 1 => KeyCompromise,
189 2 => CertificateAuthorityCompromise,
190 3 => AffiliationChanged,
191 4 => Superseded,
192 5 => CessationOfOperation,
193 6 => CertificateHold,
194 8 => RemoveFromCertificateRevocationList,
195 9 => PrivilegeWithdrawn,
196 10 => AuthorityAttributeCompromise,
197 _ => Other(n),
198 }))
199}
200
201#[cfg(feature = "json")]
202fn certificate_revocation_reason_serialize<S>(
203 type_: &Option<CertificateRevocationReason>,
204 serializer: S,
205) -> Result<S::Ok, S::Error>
206where
207 S: Serializer,
208{
209 use self::CertificateRevocationReason::*;
210
211 serializer.serialize_i32(match type_.clone().unwrap() {
212 Other(i) => i,
213 Unspecified => 0,
214 KeyCompromise => 1,
215 CertificateAuthorityCompromise => 2,
216 AffiliationChanged => 3,
217 Superseded => 4,
218 CessationOfOperation => 5,
219 CertificateHold => 6,
220 RemoveFromCertificateRevocationList => 8,
221 PrivilegeWithdrawn => 9,
222 AuthorityAttributeCompromise => 10,
223 })
224}