]>
Commit | Line | Data |
---|---|---|
5f0ba968 WB |
1 | //! ACME Directory information. |
2 | ||
aa230682 WB |
3 | use serde::{Deserialize, Serialize}; |
4 | ||
5f0ba968 WB |
5 | /// An ACME Directory. This contains the base URL and the directory data as received via a `GET` |
6 | /// request to the URL. | |
aa230682 | 7 | pub struct Directory { |
5f0ba968 | 8 | /// The main entry point URL to the ACME directory. |
aa230682 | 9 | pub url: String, |
5f0ba968 WB |
10 | |
11 | /// The json structure received via a `GET` request to the directory URL. This contains the | |
12 | /// URLs for various API entry points. | |
aa230682 WB |
13 | pub data: DirectoryData, |
14 | } | |
15 | ||
16 | /// The ACME Directory object structure. | |
5f0ba968 WB |
17 | /// |
18 | /// The data in here is typically not relevant to the user of this crate. | |
aa230682 WB |
19 | #[derive(Deserialize, Serialize)] |
20 | #[serde(rename_all = "camelCase")] | |
21 | pub struct DirectoryData { | |
5f0ba968 | 22 | /// The entry point to create a new account. |
aa230682 | 23 | pub new_account: String, |
5f0ba968 WB |
24 | |
25 | /// The entry point to retrieve a new nonce, should be used with a `HEAD` request. | |
aa230682 | 26 | pub new_nonce: String, |
5f0ba968 WB |
27 | |
28 | /// URL to post new orders to. | |
aa230682 | 29 | pub new_order: String, |
5f0ba968 WB |
30 | |
31 | /// URL to use for certificate revocation. | |
aa230682 | 32 | pub revoke_cert: String, |
5f0ba968 WB |
33 | |
34 | /// Account key rollover URL. | |
aa230682 | 35 | pub key_change: String, |
5f0ba968 WB |
36 | |
37 | /// Metadata object, for additional information which aren't directly part of the API | |
38 | /// itself, such as the terms of service. | |
4c5d899c DC |
39 | #[serde(skip_serializing_if = "Option::is_none")] |
40 | pub meta: Option<Meta>, | |
aa230682 WB |
41 | } |
42 | ||
43 | /// The directory's "meta" object. | |
44 | #[derive(Clone, Debug, Deserialize, Serialize)] | |
45 | #[serde(rename_all = "camelCase")] | |
46 | pub struct Meta { | |
5f0ba968 | 47 | /// The terms of service. This is typically in the form of an URL. |
aa230682 WB |
48 | #[serde(skip_serializing_if = "Option::is_none")] |
49 | pub terms_of_service: Option<String>, | |
53416e35 FG |
50 | |
51 | /// Flag indicating if EAB is required, None is equivalent to false | |
52 | #[serde(skip_serializing_if = "Option::is_none")] | |
53 | pub external_account_required: Option<bool>, | |
54 | ||
55 | /// Website with information about the ACME Server | |
56 | #[serde(skip_serializing_if = "Option::is_none")] | |
57 | pub website: Option<String>, | |
58 | ||
59 | /// List of hostnames used by the CA, intended for the use with caa dns records | |
d07e4fdb WB |
60 | #[serde(default, skip_serializing_if = "Vec::is_empty")] |
61 | pub caa_identities: Vec<String>, | |
aa230682 WB |
62 | } |
63 | ||
64 | impl Directory { | |
65 | /// Create a `Directory` given the parsed `DirectoryData` of a `GET` request to the directory | |
66 | /// URL. | |
67 | pub fn from_parts(url: String, data: DirectoryData) -> Self { | |
68 | Self { url, data } | |
69 | } | |
70 | ||
71 | /// Get the ToS URL. | |
72 | pub fn terms_of_service_url(&self) -> Option<&str> { | |
4c5d899c DC |
73 | match &self.data.meta { |
74 | Some(meta) => meta.terms_of_service.as_deref(), | |
75 | None => None, | |
76 | } | |
aa230682 WB |
77 | } |
78 | ||
53416e35 FG |
79 | /// Get if external account binding is required |
80 | pub fn external_account_binding_required(&self) -> bool { | |
81 | matches!( | |
82 | &self.data.meta, | |
83 | Some(Meta { | |
84 | external_account_required: Some(true), | |
85 | .. | |
86 | }) | |
87 | ) | |
88 | } | |
89 | ||
aa230682 WB |
90 | /// Get the "newNonce" URL. Use `HEAD` requests on this to get a new nonce. |
91 | pub fn new_nonce_url(&self) -> &str { | |
92 | &self.data.new_nonce | |
93 | } | |
94 | ||
95 | pub(crate) fn new_account_url(&self) -> &str { | |
96 | &self.data.new_account | |
97 | } | |
98 | ||
99 | pub(crate) fn new_order_url(&self) -> &str { | |
100 | &self.data.new_order | |
101 | } | |
102 | ||
103 | /// Access to the in the Acme spec defined metadata structure. | |
4c5d899c DC |
104 | pub fn meta(&self) -> Option<&Meta> { |
105 | self.data.meta.as_ref() | |
aa230682 WB |
106 | } |
107 | } |