wire_e2e_identity/acme/
directory.rs

1use crate::acme::prelude::*;
2
3impl RustyAcme {
4    /// First, call the directory endpoint `GET /acme/{provisioner_name}/directory`.
5    /// Then pass the response to this method to deserialize it
6    /// see [RFC 8555 Section 7.1.1](https://www.rfc-editor.org/rfc/rfc8555.html#section-7.1.1)
7    pub fn acme_directory_response(response: serde_json::Value) -> RustyAcmeResult<AcmeDirectory> {
8        let directory = serde_json::from_value::<AcmeDirectory>(response)
9            .map_err(|_| RustyAcmeError::SmallstepImplementationError("Invalid directory response"))?;
10        Ok(directory)
11    }
12}
13
14#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
15#[serde(rename_all = "camelCase")]
16/// See [RFC 8555 Section 7.1.1](https://www.rfc-editor.org/rfc/rfc8555.html#section-7.1.1)
17pub struct AcmeDirectory {
18    /// URL for fetching the initial nonce used to create an account
19    pub new_nonce: url::Url,
20    /// URL for creating an account
21    pub new_account: url::Url,
22    /// URL for creating an order
23    pub new_order: url::Url,
24    /// URL for revoking a certificate
25    pub revoke_cert: url::Url,
26}
27
28#[cfg(test)]
29pub mod tests {
30    use wasm_bindgen_test::*;
31
32    use super::*;
33
34    wasm_bindgen_test_configure!(run_in_browser);
35
36    #[test]
37    #[wasm_bindgen_test]
38    fn can_deserialize_rfc_sample() {
39        let rfc_sample = serde_json::json!({
40            "newNonce": "https://example.com/acme/new-nonce",
41            "newAccount": "https://example.com/acme/new-account",
42            "newOrder": "https://example.com/acme/new-order",
43            "newAuthz": "https://example.com/acme/new-authz",
44            "revokeCert": "https://example.com/acme/revoke-cert",
45            "keyChange": "https://example.com/acme/key-change",
46            "meta": {
47                "termsOfService": "https://example.com/acme/terms/2017-5-30",
48                "website": "https://www.example.com/",
49                "caaIdentities": ["example.com"],
50                "externalAccountRequired": false
51            }
52        });
53        assert!(serde_json::from_value::<AcmeDirectory>(rfc_sample).is_ok());
54    }
55}