acme_types/v2/
authorization.rs

1#[cfg(feature = "json")]
2use serde::{Deserialize, Serialize};
3
4pub use super::Identifier as NewAuthorization;
5
6#[cfg(feature = "json")]
7impl NewAuthorization {
8    /// Deserializes a NewAuthorization object from a JSON str
9    pub fn from_str(s: &str) -> Result<NewAuthorization, serde_json::error::Error> {
10        serde_json::from_str(s)
11    }
12
13    /// Serializes a NewAuthorization object to a JSON String
14    pub fn to_string(&self) -> Result<String, serde_json::error::Error> {
15        serde_json::to_string(self)
16    }
17}
18
19/// Defines an ACME authorization resource
20///
21/// For more information, refer to [RFC 8555 § 7.1.4](https://datatracker.ietf.org/doc/html/rfc8555#section-7.1.4)
22#[derive(Clone, Debug)]
23#[cfg_attr(feature = "json", derive(Serialize, Deserialize))]
24pub struct Authorization {
25    /// Authorization identifier
26    pub identifier: super::Identifier,
27    /// Authorization status
28    pub status: AuthorizationStatus,
29    /// Authorization expiration time
30    pub expires: Option<String>,
31    /// Authorization challenge objects
32    pub challenges: Vec<Challenge>,
33    /// Present and true for authorizations for a domain name containing a wildcard
34    pub wildcard: Option<bool>,
35}
36
37#[cfg(feature = "json")]
38impl Authorization {
39    /// Deserializes an Authorization object from a JSON str
40    pub fn from_str(s: &str) -> Result<Authorization, serde_json::error::Error> {
41        serde_json::from_str(s)
42    }
43
44    /// Serializes an Authorization object to a JSON String
45    pub fn to_string(&self) -> Result<String, serde_json::error::Error> {
46        serde_json::to_string(self)
47    }
48}
49
50/// Defines an update to an Authorization resource.
51///
52/// This can be used when the ACME client wishes to relinquish authorization to issue certificates for an identifier.
53///
54/// For more information, refer to [RFC 8555 § 7.5.2](https://datatracker.ietf.org/doc/html/rfc8555#section-7.5.2)
55#[derive(Clone, Debug)]
56#[cfg_attr(feature = "json", derive(Serialize, Deserialize))]
57pub struct AuthorizationUpdate {
58    /// Authorization status
59    pub status: AuthorizationStatus,
60}
61
62#[cfg(feature = "json")]
63impl AuthorizationUpdate {
64    /// Deserializes an AuthorizationUpdate object from a JSON str
65    pub fn from_str(s: &str) -> Result<AuthorizationUpdate, serde_json::error::Error> {
66        serde_json::from_str(s)
67    }
68
69    /// Serializes an AuthorizationUpdate object to a JSON String
70    pub fn to_string(&self) -> Result<String, serde_json::error::Error> {
71        serde_json::to_string(self)
72    }
73}
74
75/// Defines an ACME authorization challenge object
76///
77/// For more information, refer to [RFC 8555 § 7.1.5](https://datatracker.ietf.org/doc/html/rfc8555#section-7.1.5)
78#[derive(Clone, Debug)]
79#[cfg_attr(feature = "json", derive(Serialize, Deserialize))]
80pub struct Challenge {
81    /// URL to respond to challenge
82    pub url: String,
83    /// Challenge type
84    #[cfg_attr(feature = "json", serde(rename = "type"))]
85    pub type_: ChallengeType,
86    /// Current status of the challenge
87    pub status: ChallengeStatus,
88    /// Optional challenge token - this may or may not be present depending on the challenge type
89    ///
90    /// For more information, refer to [RFC 8555 § 8.1](https://datatracker.ietf.org/doc/html/rfc8555#section-8.1)
91    pub token: Option<String>,
92    /// Time at which the challenge was validated
93    pub validated: Option<String>,
94    /// Error(s) encountered during challenge validation
95    pub error: Option<super::Error>,
96}
97
98#[cfg(feature = "json")]
99impl Challenge {
100    /// Deserializes a Challenge object from a JSON str
101    pub fn from_str(s: &str) -> Result<Challenge, serde_json::error::Error> {
102        serde_json::from_str(s)
103    }
104
105    /// Serializes a Challenge object to a JSON String
106    pub fn to_string(&self) -> Result<String, serde_json::error::Error> {
107        serde_json::to_string(self)
108    }
109}
110
111/// Challenge resource status values
112///
113/// For more information, refer to [RFC 8555 § 7.1.6](https://datatracker.ietf.org/doc/html/rfc8555#section-7.1.6)
114#[derive(Clone, Debug)]
115#[cfg_attr(feature = "json", derive(Serialize, Deserialize))]
116pub enum ChallengeStatus {
117    #[cfg_attr(feature = "json", serde(rename = "pending"))]
118    Pending,
119    #[cfg_attr(feature = "json", serde(rename = "processing"))]
120    Processing,
121    #[cfg_attr(feature = "json", serde(rename = "valid"))]
122    Valid,
123    #[cfg_attr(feature = "json", serde(rename = "invalid"))]
124    Invalid,
125}
126
127/// Challenge resource type values
128///
129/// For more information, refer to [RFC 8555 § 8](https://datatracker.ietf.org/doc/html/rfc8555#section-8)
130#[derive(Clone, Debug)]
131#[cfg_attr(feature = "json", derive(Serialize, Deserialize))]
132pub enum ChallengeType {
133    /// For more information about http-01 challenges, refer to [RFC 8555 § 8.3](https://datatracker.ietf.org/doc/html/rfc8555#section-8.3)
134    #[cfg_attr(feature = "json", serde(rename = "http-01"))]
135    Http01,
136    /// For more information about dns-01 challenges, refer to [RFC 8555 § 8.4](https://datatracker.ietf.org/doc/html/rfc8555#section-8.4)
137    #[cfg_attr(feature = "json", serde(rename = "dns-01"))]
138    Dns01,
139}
140
141/// Authorization resource status values
142///
143/// For more information, refer to [RFC 8555 § 7.1.6](https://datatracker.ietf.org/doc/html/rfc8555#section-7.1.6)
144#[derive(Clone, Debug)]
145#[cfg_attr(feature = "json", derive(Serialize, Deserialize))]
146pub enum AuthorizationStatus {
147    #[cfg_attr(feature = "json", serde(rename = "pending"))]
148    Pending,
149    #[cfg_attr(feature = "json", serde(rename = "expired"))]
150    Expired,
151    #[cfg_attr(feature = "json", serde(rename = "deactivated"))]
152    Deactivated,
153    #[cfg_attr(feature = "json", serde(rename = "revoked"))]
154    Revoked,
155    #[cfg_attr(feature = "json", serde(rename = "valid"))]
156    Valid,
157    #[cfg_attr(feature = "json", serde(rename = "invalid"))]
158    Invalid,
159}