Skip to main content

acme/api/
account.rs

1use serde::{Deserialize, Serialize};
2
3/// An ACME account resource.
4///
5/// Represents a set of metadata associated with an account.
6///
7/// See [RFC 8555 §7.1.2].
8///
9/// # Example JSON
10///
11/// ```json
12/// {
13///   "status": "valid",
14///   "contact": [
15///     "mailto:cert-admin@example.com",
16///     "mailto:admin@example.com"
17///   ],
18///   "termsOfServiceAgreed": true,
19///   "orders": "https://example.com/acme/acct/evOfKhNU60wg/orders"
20/// }
21/// ```
22///
23/// [RFC 8555 §7.1.2]: https://datatracker.ietf.org/doc/html/rfc8555#section-7.1.2
24#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
25#[serde(rename_all = "camelCase")]
26pub struct Account {
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub status: Option<String>,
29
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub contact: Option<Vec<String>>,
32
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub external_account_binding: Option<String>,
35
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub terms_of_service_agreed: Option<bool>,
38
39    #[serde(skip_serializing_if = "Option::is_none")]
40    pub only_return_existing: Option<bool>,
41
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub orders: Option<String>,
44}
45
46impl Account {
47    pub fn is_status_valid(&self) -> bool {
48        self.status.as_ref().map(|s| s.as_ref()) == Some("valid")
49    }
50
51    pub fn is_status_deactivated(&self) -> bool {
52        self.status.as_ref().map(|s| s.as_ref()) == Some("deactivated")
53    }
54
55    pub fn is_status_revoked(&self) -> bool {
56        self.status.as_ref().map(|s| s.as_ref()) == Some("revoked")
57    }
58
59    pub fn terms_of_service_agreed(&self) -> bool {
60        self.terms_of_service_agreed.unwrap_or(false)
61    }
62}