acme_types/v2/
order.rs

1#[cfg(feature = "json")]
2use serde::{Deserialize, Deserializer, Serialize, Serializer};
3
4/// Defines a new ACME order object
5///
6/// For more information, refer to [RFC 8555 § 7.4](https://datatracker.ietf.org/doc/html/rfc8555#section-7.4)
7#[derive(Clone, Debug)]
8#[cfg_attr(feature = "json", derive(Serialize, Deserialize))]
9pub struct NewOrder {
10    /// Array of requested identifiers
11    pub identifiers: Vec<super::Identifier>,
12    /// Requested value for certificate's notBefore value
13    #[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    /// Requested value for certificate's notAfter value
17    #[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    /// Deserializes a NewOrder object from a JSON str
25    pub fn from_str(s: &str) -> Result<NewOrder, serde_json::error::Error> {
26        serde_json::from_str(s)
27    }
28
29    /// Serializes a NewOrder object to a JSON String
30    pub fn to_string(&self) -> Result<String, serde_json::error::Error> {
31        serde_json::to_string(self)
32    }
33}
34
35/// Defines a new ACME order resource
36///
37/// For more information, refer to [RFC 8555 § 9.7.2](https://datatracker.ietf.org/doc/html/rfc8555#section-9.7.2)
38#[derive(Clone, Debug)]
39#[cfg_attr(feature = "json", derive(Serialize, Deserialize))]
40pub struct Order {
41    /// Order status
42    pub status: OrderStatus,
43    /// Order expiration time
44    pub expires: String,
45    /// Array of requested identifiers
46    pub identifiers: Vec<super::Identifier>,
47    /// Requested value for certificate's notBefore value
48    #[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    /// Requested value for certificate's notAfter value
52    #[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    /// Error encountered during domain validation, certificate issuance, etc.
56    pub error: Option<String>,
57    /// Authorizations which need to be completed in order to finalize the order
58    pub authorizations: Option<String>,
59    /// URL to finalize order
60    pub finalize: String,
61    /// URL to retrieve certificate issued by ACME provider
62    pub certificate: String,
63}
64
65#[cfg(feature = "json")]
66impl Order {
67    /// Deserializes an Order object from a JSON str
68    pub fn from_str(s: &str) -> Result<Order, serde_json::error::Error> {
69        serde_json::from_str(s)
70    }
71
72    /// Serializes an Order object to a JSON String
73    pub fn to_string(&self) -> Result<String, serde_json::error::Error> {
74        serde_json::to_string(self)
75    }
76}
77
78/// Defines an ACME order finalize object
79///
80/// For more information, refer to [RFC 8555 § 7.4](https://datatracker.ietf.org/doc/html/rfc8555#section-7.4)
81#[derive(Clone, Debug)]
82#[cfg_attr(feature = "json", derive(Serialize, Deserialize))]
83pub struct OrderFinalize {
84    /// CSR for the requested certificate (base64url-encoding of the DER-encoded CSR)
85    #[cfg_attr(feature = "json", serde(rename = "csr"))]
86    pub certificate_signing_request: String,
87}
88
89#[cfg(feature = "json")]
90impl OrderFinalize {
91    /// Deserializes an OrderFinalize object from a JSON str
92    pub fn from_str(s: &str) -> Result<OrderFinalize, serde_json::error::Error> {
93        serde_json::from_str(s)
94    }
95
96    /// Serializes an OrderFinalize object to a JSON String
97    pub fn to_string(&self) -> Result<String, serde_json::error::Error> {
98        serde_json::to_string(self)
99    }
100}
101
102/// Order resource status values
103///
104/// For more information, refer to [RFC 8555 § 7.1.6](https://datatracker.ietf.org/doc/html/rfc8555#section-7.1.6)
105#[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/// Defines a certificate revocation request
121///
122/// For more information, refer to [RFC 8555 § 7.6](https://datatracker.ietf.org/doc/html/rfc8555#section-7.6)
123#[derive(Clone, Debug)]
124#[cfg_attr(feature = "json", derive(Serialize, Deserialize))]
125pub struct CertificateRevocation {
126    /// base64url-encoding of the DER-encoded certificate to revoke
127    pub certificate: String,
128    /// Reason for certificate revocation
129    ///
130    /// For more information, refer to [RFC 5280 § 5.3.1](https://datatracker.ietf.org/doc/html/rfc5280#section-5.3.1)
131    #[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    /// Deserializes a CertificateRevocation object from a JSON str
146    pub fn from_str(s: &str) -> Result<CertificateRevocation, serde_json::error::Error> {
147        serde_json::from_str(s)
148    }
149
150    /// Serializes a CertificateRevocation object to a JSON String
151    pub fn to_string(&self) -> Result<String, serde_json::error::Error> {
152        serde_json::to_string(self)
153    }
154}
155
156/// Certificate revocation reason values
157///
158/// For more information, refer to [RFC 5280 § 5.3.1](https://datatracker.ietf.org/doc/html/rfc5280#section-5.3.1)
159#[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}