1use crate::DnsError;
8use crate::{Error, IprevResult};
9use std::borrow::Cow;
10
11pub mod auth_results;
12pub mod base32;
13pub mod cache;
14pub mod crypto;
15#[cfg(feature = "dns-doh")]
16pub mod doh;
17pub mod headers;
18pub mod message;
19pub mod parse;
20pub mod resolver;
21pub mod verify;
22
23pub fn to_a_label(domain: &str) -> Cow<'_, str> {
24 if !domain.is_ascii() {
25 idna::domain_to_ascii(domain)
26 .map(Cow::Owned)
27 .unwrap_or(Cow::Borrowed(domain))
28 } else if domain.bytes().any(|byte| byte.is_ascii_uppercase()) {
29 Cow::Owned(domain.to_ascii_lowercase())
30 } else {
31 Cow::Borrowed(domain)
32 }
33}
34
35impl From<Error> for IprevResult {
36 fn from(err: Error) -> Self {
37 if matches!(&err, Error::Dns(DnsError::Resolver(_))) {
38 IprevResult::TempError(err)
39 } else {
40 IprevResult::PermError(err)
41 }
42 }
43}