use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Directory {
#[serde(rename = "newAccount")]
pub new_account: String,
#[serde(rename = "newOrder")]
pub new_order: String,
#[serde(rename = "newNonce")]
pub new_nonce: String,
#[serde(rename = "revokeCert")]
pub revoke_cert: String,
#[serde(rename = "keyChange", skip_serializing_if = "Option::is_none")]
pub key_change: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub meta: Option<DirectoryMeta>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DirectoryMeta {
#[serde(rename = "termsOfService", skip_serializing_if = "Option::is_none")]
pub terms_of_service: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub website: Option<String>,
#[serde(rename = "caaIdentities", skip_serializing_if = "Option::is_none")]
pub caa_identities: Option<Vec<String>>,
#[serde(
rename = "externalAccountRequired",
skip_serializing_if = "Option::is_none"
)]
pub external_account_required: Option<bool>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_directory_deserialization() {
let json = r#"{
"newAccount": "https://example.com/acme/new-account",
"newOrder": "https://example.com/acme/new-order",
"newNonce": "https://example.com/acme/new-nonce",
"revokeCert": "https://example.com/acme/revoke-cert"
}"#;
let directory: Directory = serde_json::from_str(json).unwrap();
assert_eq!(
directory.new_account,
"https://example.com/acme/new-account"
);
assert_eq!(directory.new_order, "https://example.com/acme/new-order");
}
#[test]
fn test_directory_with_meta() {
let json = r#"{
"newAccount": "https://example.com/acme/new-account",
"newOrder": "https://example.com/acme/new-order",
"newNonce": "https://example.com/acme/new-nonce",
"revokeCert": "https://example.com/acme/revoke-cert",
"meta": {
"termsOfService": "https://example.com/tos",
"externalAccountRequired": true
}
}"#;
let directory: Directory = serde_json::from_str(json).unwrap();
assert!(directory.meta.is_some());
let meta = directory.meta.unwrap();
assert_eq!(
meta.terms_of_service,
Some("https://example.com/tos".to_string())
);
assert_eq!(meta.external_account_required, Some(true));
}
}