Skip to main content

dns_update_lite/
lib.rs

1#![doc = include_str!("../README.md")]
2
3#[cfg(any(feature = "ring", feature = "aws-lc-rs"))]
4use providers::ovh::OvhProvider;
5
6#[cfg(feature = "test_provider")]
7use providers::in_memory::InMemoryProvider;
8
9pub use hickory_proto::dnssec;
10use providers::{
11    bunny::BunnyProvider, cloudflare::CloudflareProvider, desec::DesecProvider,
12    digitalocean::DigitalOceanProvider, dnsimple::DNSimpleProvider, porkbun::PorkBunProvider,
13    rfc2136::Rfc2136Provider, route53::Route53Provider, spaceship::SpaceshipProvider,
14};
15
16use std::{
17    borrow::Cow,
18    net::{Ipv4Addr, Ipv6Addr},
19};
20
21use crate::providers::google_cloud_dns::GoogleCloudDnsProvider;
22
23pub mod bind;
24pub mod config;
25pub mod crypto;
26pub mod http;
27pub mod jwt;
28pub mod providers;
29pub mod tests;
30pub mod update;
31pub mod utils;
32
33#[derive(Debug)]
34pub enum Error {
35    Protocol(String),
36    Parse(String),
37    Client(String),
38    Response(String),
39    Api(String),
40    Serialize(String),
41    Unauthorized,
42    NotFound,
43    BadRequest,
44    Unsupported(String),
45}
46
47/// A DNS record type.
48#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
49pub enum DnsRecordType {
50    A,
51    AAAA,
52    CNAME,
53    NS,
54    MX,
55    TXT,
56    SRV,
57    TLSA,
58    CAA,
59    HTTPS,
60}
61
62/// A named DNS record, which consists of a name and a DNS record.
63#[derive(Clone, Debug, PartialEq, Eq, Hash)]
64pub struct NamedDnsRecord {
65    pub name: String,
66    pub record: DnsRecord,
67}
68
69/// A DNS record type with a value.
70#[derive(Clone, Debug, PartialEq, Eq, Hash)]
71pub enum DnsRecord {
72    A(Ipv4Addr),
73    AAAA(Ipv6Addr),
74    CNAME(String),
75    NS(String),
76    MX(MXRecord),
77    TXT(String),
78    SRV(SRVRecord),
79    TLSA(TLSARecord),
80    CAA(CAARecord),
81    HTTPS(HTTPSRecord),
82}
83
84// An MX record, which consists of an exchange string and a priority.
85#[derive(Clone, Debug, PartialEq, Eq, Hash)]
86pub struct MXRecord {
87    pub exchange: String,
88    pub priority: u16,
89}
90
91// A SRV record, which consists of a target string, priority, weight, and port.
92#[derive(Clone, Debug, PartialEq, Eq, Hash)]
93pub struct SRVRecord {
94    pub target: String,
95    pub priority: u16,
96    pub weight: u16,
97    pub port: u16,
98}
99
100// A TLSA record, which consists of a certificate usage, selector, matching type, and certificate data.
101#[derive(Clone, Debug, PartialEq, Eq, Hash)]
102pub struct TLSARecord {
103    pub cert_usage: TlsaCertUsage,
104    pub selector: TlsaSelector,
105    pub matching: TlsaMatching,
106    pub cert_data: Vec<u8>,
107}
108
109#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
110pub enum TlsaCertUsage {
111    PkixTa,
112    PkixEe,
113    DaneTa,
114    DaneEe,
115    Private,
116}
117
118#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
119pub enum TlsaSelector {
120    Full,
121    Spki,
122    Private,
123}
124
125#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
126pub enum TlsaMatching {
127    Raw,
128    Sha256,
129    Sha512,
130    Private,
131}
132
133// A CAA record, which can be either an Issue, IssueWild, or Iodef record.
134#[derive(Clone, Debug, PartialEq, Eq, Hash)]
135pub enum CAARecord {
136    Issue {
137        issuer_critical: bool,
138        name: Option<String>,
139        options: Vec<KeyValue>,
140    },
141    IssueWild {
142        issuer_critical: bool,
143        name: Option<String>,
144        options: Vec<KeyValue>,
145    },
146    Iodef {
147        issuer_critical: bool,
148        url: String,
149    },
150}
151
152/// An HTTPS record, as defined in [RFC 9460](https://datatracker.ietf.org/doc/html/rfc9460).
153#[derive(Clone, Debug, PartialEq, Eq, Hash)]
154pub struct HTTPSRecord {
155    pub svc_priority: u16,
156    pub target_name: String,
157    pub svc_params: Vec<KeyValue>,
158}
159
160#[derive(Clone, Debug, PartialEq, Eq, Hash)]
161pub struct KeyValue {
162    pub key: String,
163    pub value: String,
164}
165
166/// A TSIG algorithm.
167pub enum TsigAlgorithm {
168    HmacMd5,
169    Gss,
170    HmacSha1,
171    HmacSha224,
172    HmacSha256,
173    HmacSha256_128,
174    HmacSha384,
175    HmacSha384_192,
176    HmacSha512,
177    HmacSha512_256,
178}
179
180/// A DNSSEC algorithm.
181pub enum Algorithm {
182    RSASHA256,
183    RSASHA512,
184    ECDSAP256SHA256,
185    ECDSAP384SHA384,
186    ED25519,
187}
188
189pub type Result<T> = std::result::Result<T, Error>;
190
191#[derive(Clone)]
192#[non_exhaustive]
193pub enum DnsUpdater {
194    Rfc2136(Rfc2136Provider),
195    Cloudflare(CloudflareProvider),
196    DigitalOcean(DigitalOceanProvider),
197    Desec(DesecProvider),
198    #[cfg(any(feature = "ring", feature = "aws-lc-rs"))]
199    Ovh(OvhProvider),
200    Bunny(BunnyProvider),
201    Porkbun(PorkBunProvider),
202    Spaceship(SpaceshipProvider),
203    DNSimple(DNSimpleProvider),
204    GoogleCloudDns(GoogleCloudDnsProvider),
205    #[cfg(feature = "test_provider")]
206    InMemory(InMemoryProvider),
207    Route53(Route53Provider),
208}
209
210pub trait IntoFqdn<'x> {
211    fn into_fqdn(self) -> Cow<'x, str>;
212    fn into_name(self) -> Cow<'x, str>;
213}