2023-05-17 13:47:40 +00:00
|
|
|
pub mod acme;
|
2023-05-07 15:06:51 +00:00
|
|
|
pub mod checker;
|
2023-05-07 16:07:31 +00:00
|
|
|
pub mod config;
|
2023-05-10 11:34:33 +00:00
|
|
|
pub mod manager;
|
2023-05-12 13:19:24 +00:00
|
|
|
|
|
|
|
use std::str::FromStr;
|
|
|
|
|
|
|
|
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
|
|
|
|
use trust_dns_client::rr as trust_dns_rr;
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
/// Validated representation of a domain name
|
|
|
|
pub struct Name {
|
|
|
|
inner: trust_dns_rr::Name,
|
|
|
|
utf8_str: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Name {
|
|
|
|
fn as_str(&self) -> &str {
|
|
|
|
self.utf8_str.as_str()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for Name {
|
|
|
|
type Err = <trust_dns_rr::Name as FromStr>::Err;
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
let mut n = trust_dns_rr::Name::from_str(s)?;
|
|
|
|
let utf8_str = n.clone().to_utf8();
|
|
|
|
|
|
|
|
n.set_fqdn(true);
|
|
|
|
|
|
|
|
Ok(Name { inner: n, utf8_str })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Serialize for Name {
|
|
|
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
|
|
where
|
|
|
|
S: Serializer,
|
|
|
|
{
|
|
|
|
serializer.serialize_str(self.as_str())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct NameVisitor;
|
|
|
|
|
|
|
|
impl<'de> de::Visitor<'de> for NameVisitor {
|
|
|
|
type Value = Name;
|
|
|
|
|
|
|
|
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
|
|
write!(formatter, "a valid domain name")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_str<E>(self, s: &str) -> Result<Self::Value, E>
|
|
|
|
where
|
|
|
|
E: de::Error,
|
|
|
|
{
|
|
|
|
match Name::from_str(s) {
|
|
|
|
Ok(n) => Ok(n),
|
|
|
|
Err(e) => Err(E::custom(format!("invalid domain name: {}", e))),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'de> Deserialize<'de> for Name {
|
|
|
|
fn deserialize<D>(deserializer: D) -> Result<Name, D::Error>
|
|
|
|
where
|
|
|
|
D: Deserializer<'de>,
|
|
|
|
{
|
|
|
|
deserializer.deserialize_str(NameVisitor)
|
|
|
|
}
|
|
|
|
}
|