kubizone_common/
type.rs

1use std::fmt::Display;
2
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6/// Domain Name System type.
7#[allow(clippy::upper_case_acronyms)]
8#[derive(
9    Default,
10    Serialize,
11    Deserialize,
12    JsonSchema,
13    Clone,
14    Copy,
15    Debug,
16    Hash,
17    PartialEq,
18    Eq,
19    PartialOrd,
20    Ord,
21)]
22pub enum Type {
23    /// Address record
24    ///
25    /// Returns a 32-bit IPv4 address, most commonly used to map hostnames to an IP address of the host, but it is also used for DNSBLs, storing subnet masks in RFC 1101, etc.
26    ///
27    /// [1035](https://datatracker.ietf.org/doc/html/rfc1035)
28    #[default]
29    A,
30    /// IPv6 address record
31    ///
32    /// Returns a 128-bit IPv6 address, most commonly used to map hostnames to an IP address of the host.
33    ///
34    /// [3596](https://datatracker.ietf.org/doc/html/rfc3596)
35    AAAA,
36    /// AFS database record
37    ///
38    /// Location of database servers of an AFS cell. This record is commonly used by AFS clients to contact AFS cells outside their local domain. A subtype of this record is used by the obsolete DCE/DFS file system.
39    ///
40    /// [1183](https://datatracker.ietf.org/doc/html/rfc1183)
41    AFSDB,
42    /// Address Prefix List
43    ///
44    /// Specify lists of address ranges, e.g. in CIDR format, for various address families. Experimental.
45    ///
46    /// [3123](https://datatracker.ietf.org/doc/html/rfc3123)
47    APL,
48    /// Certification Authority Authorization
49    ///
50    /// DNS Certification Authority Authorization, constraining acceptable CAs for a host/domain
51    ///
52    /// [6844](https://datatracker.ietf.org/doc/html/rfc6844)
53    CAA,
54    /// Child copy of DNSKEY record, for transfer to parent
55    ///
56    /// [7344](https://datatracker.ietf.org/doc/html/rfc7344)
57    CDNSKEY,
58    /// Child DS
59    ///
60    /// Child copy of DS record, for transfer to parent
61    ///
62    /// [7344](https://datatracker.ietf.org/doc/html/rfc7344)
63    CDS,
64    /// Certificate record
65    ///
66    /// Stores PKIX, SPKI, PGP, etc.
67    ///
68    /// [4398](https://datatracker.ietf.org/doc/html/rfc4398)
69    CERT,
70    /// Canonical name record
71    ///
72    /// Alias of one name to another: the DNS lookup will continue by retrying the lookup with the new name.
73    ///
74    /// [1035](https://datatracker.ietf.org/doc/html/rfc1035)
75    CNAME,
76    /// Child-to-Parent Synchronization
77    ///
78    /// Specify a synchronization mechanism between a child and a parent DNS zone. Typical example is declaring the same NS records in the parent and the child zone
79    ///
80    /// [7477](https://datatracker.ietf.org/doc/html/rfc7477)
81    CSYNC,
82    /// DHCP identifier
83    ///
84    /// Used in conjunction with the FQDN option to DHCP
85    ///
86    /// [4701](https://datatracker.ietf.org/doc/html/rfc4701)
87    DHCID,
88    /// DNSSEC Lookaside Validation record
89    ///
90    /// For publishing DNSSEC trust anchors outside of the DNS delegation chain. Uses the same format as the DS record. RFC 5074 describes a way of using these records.
91    ///
92    /// [4431](https://datatracker.ietf.org/doc/html/rfc4431)
93    DLV,
94    /// Delegation name record
95    ///
96    /// Alias for a name and all its subnames, unlike CNAME, which is an alias for only the exact name. Like a CNAME record, the DNS lookup will continue by retrying the lookup with the new name.
97    ///
98    /// [6672](https://datatracker.ietf.org/doc/html/rfc6672)
99    DNAME,
100    /// DNS Key record
101    ///
102    /// The key record used in DNSSEC. Uses the same format as the KEY record.
103    ///
104    /// [4034](https://datatracker.ietf.org/doc/html/rfc4034)
105    DNSKEY,
106    /// Delegation signer
107    ///
108    /// The record used to identify the DNSSEC signing key of a delegated zone
109    ///
110    /// [4034](https://datatracker.ietf.org/doc/html/rfc4034)
111    DS,
112    /// MAC address (EUI-48)
113    ///
114    /// A 48-bit IEEE Extended Unique Identifier.
115    ///
116    /// [7043](https://datatracker.ietf.org/doc/html/rfc7043)
117    EUI48,
118    /// MAC address (EUI-64)
119    ///
120    /// A 64-bit IEEE Extended Unique Identifier.
121    ///
122    /// [7043](https://datatracker.ietf.org/doc/html/rfc7043)
123    EUI64,
124    /// Host Information
125    ///
126    /// Providing Minimal-Sized Responses to DNS Queries That Have QTYPE=ANY
127    ///
128    /// [8482](https://datatracker.ietf.org/doc/html/rfc8482)
129    HINFO,
130    /// Host Identity Protocol
131    ///
132    /// Method of separating the end-point identifier and locator roles of IP addresses.
133    ///
134    /// [8005](https://datatracker.ietf.org/doc/html/rfc8005)
135    HIP,
136    /// HTTPS Binding
137    ///
138    /// RR that improves performance for clients that need to resolve many resources to access a domain.
139    ///
140    /// [9460](https://datatracker.ietf.org/doc/html/rfc9460)
141    HTTPS,
142    /// IPsec Key
143    ///
144    /// Key record that can be used with IPsec
145    ///
146    /// [4025](https://datatracker.ietf.org/doc/html/rfc4025)
147    IPSECKEY,
148    /// Key record
149    ///
150    /// Used only for SIG(0) (RFC 2931) and TKEY (RFC 2930).[5] RFC 3445 eliminated their use for application keys and limited their use to DNSSEC.[6] RFC 3755 designates DNSKEY as the replacement within DNSSEC.[7] RFC 4025 designates IPSECKEY as the replacement for use with IPsec.[8]
151    ///
152    /// [2535](https://datatracker.ietf.org/doc/html/rfc2535)
153    /// [2930](https://datatracker.ietf.org/doc/html/rfc2930)
154    KEY,
155    /// Key Exchanger record
156    ///
157    /// Used with some cryptographic systems (not including DNSSEC) to identify a key management agent for the associated domain-name. Note that this has nothing to do with DNS Security. It is Informational status, rather than being on the IETF standards-track. It has always had limited deployment, but is still in use.
158    ///
159    /// [2230](https://datatracker.ietf.org/doc/html/rfc2230)
160    KX,
161    /// Location record
162    ///
163    /// Specifies a geographical location associated with a domain name
164    ///
165    /// [1876](https://datatracker.ietf.org/doc/html/rfc1876)
166    LOC,
167    /// Mail exchange record
168    ///
169    /// List of mail exchange servers that accept email for a domain
170    ///
171    /// [1035](https://datatracker.ietf.org/doc/html/rfc1035)
172    /// [7505](https://datatracker.ietf.org/doc/html/rfc7505)
173    MX,
174    /// Naming Authority Pointer
175    ///
176    /// Allows regular-expression-based rewriting of domain names which can then be used as URIs, further domain names to lookups, etc.
177    ///
178    /// [3403](https://datatracker.ietf.org/doc/html/rfc3403)
179    NAPTR,
180    /// Name server record
181    ///
182    /// Delegates a DNS zone to use the given authoritative name servers
183    ///
184    /// [1035](https://datatracker.ietf.org/doc/html/rfc1035)
185    NS,
186    /// Next Secure record
187    ///
188    /// Part of DNSSEC—used to prove a name does not exist. Uses the same format as the (obsolete) NXT record.
189    ///
190    /// [4034](https://datatracker.ietf.org/doc/html/rfc4034)
191    NSEC,
192    /// Next Secure record version 3
193    ///
194    /// An extension to DNSSEC that allows proof of nonexistence for a name without permitting zonewalking
195    ///
196    /// [5155](https://datatracker.ietf.org/doc/html/rfc5155)
197    NSEC3,
198    /// NSEC3 parameters
199    ///
200    /// Parameter record for use with NSEC3
201    ///
202    /// [5155](https://datatracker.ietf.org/doc/html/rfc5155)
203    NSEC3PARAM,
204    /// OpenPGP public key record
205    ///
206    /// A DNS-based Authentication of Named Entities (DANE) method for publishing and locating OpenPGP public keys in DNS for a specific email address using an OPENPGPKEY DNS resource record.
207    ///
208    /// [7929](https://datatracker.ietf.org/doc/html/rfc7929)
209    OPENPGPKEY,
210    /// PTR Resource Record
211    ///
212    /// Pointer to a canonical name. Unlike a CNAME, DNS processing stops and just the name is returned. The most common use is for implementing reverse DNS lookups, but other uses include such things as DNS-SD.
213    ///
214    /// [1035](https://datatracker.ietf.org/doc/html/rfc1035)
215    PTR,
216    /// DNSSEC signature
217    ///
218    /// Signature for a DNSSEC-secured record set. Uses the same format as the SIG record.
219    ///
220    /// [4034](https://datatracker.ietf.org/doc/html/rfc4034)
221    RRSIG,
222    /// Responsible Person
223    ///
224    /// Information about the responsible person(s) for the domain. Usually an email address with the @ replaced by a .
225    ///
226    /// [1183](https://datatracker.ietf.org/doc/html/rfc1183)
227    RP,
228    /// Signature
229    ///
230    /// Signature record used in SIG(0) (RFC 2931) and TKEY (RFC 2930).[7] RFC 3755 designated RRSIG as the replacement for SIG for use within DNSSEC.[7]
231    ///
232    /// [2535](https://datatracker.ietf.org/doc/html/rfc2535)
233    SIG,
234    /// S/MIME cert association
235    ///
236    /// Associates an S/MIME certificate with a domain name for sender authentication.
237    ///
238    /// [8162](https://datatracker.ietf.org/doc/html/rfc8162)
239    SMIMEA,
240    /// Start of [a zone of] authority record
241    ///
242    /// Specifies authoritative information about a DNS zone, including the primary name server, the email of the domain administrator, the domain serial number, and several timers relating to refreshing the zone.
243    ///
244    /// [1035](https://datatracker.ietf.org/doc/html/rfc1035)
245    /// [2308](https://datatracker.ietf.org/doc/html/rfc2308)
246    SOA,
247    /// Service locator
248    ///
249    /// Generalized service location record, used for newer protocols instead of creating protocol-specific records such as MX.
250    ///
251    /// [2782](https://datatracker.ietf.org/doc/html/rfc2782)
252    SRV,
253    /// SSH Public Key Fingerprint
254    ///
255    /// Resource record for publishing SSH public host key fingerprints in the DNS, in order to aid in verifying the authenticity of the host. RFC 6594 defines ECC SSH keys and SHA-256 hashes. See the IANA SSHFP RR parameters registry for details.
256    ///
257    /// [4255](https://datatracker.ietf.org/doc/html/rfc4255)
258    SSHFP,
259    /// Service Binding
260    ///
261    /// RR that improves performance for clients that need to resolve many resources to access a domain.
262    ///
263    /// [9460](https://datatracker.ietf.org/doc/html/rfc9460)
264    SVCB,
265    /// DNSSEC Trust Authorities
266    ///
267    /// Part of a deployment proposal for DNSSEC without a signed DNS root. See the IANA database and Weiler Spec for details. Uses the same format as the DS record.
268    TA,
269    /// Transaction Key record
270    ///
271    /// A method of providing keying material to be used with TSIG that is encrypted under the public key in an accompanying KEY RR.[12]
272    ///
273    /// [2930](https://datatracker.ietf.org/doc/html/rfc2930)
274    TKEY,
275    /// TLSA certificate association
276    ///
277    /// A record for DANE. RFC 6698 defines "The TLSA DNS resource record is used to associate a TLS server certificate or public key with the domain name where the record is found, thus forming a 'TLSA certificate association'".
278    ///
279    /// [6698](https://datatracker.ietf.org/doc/html/rfc6698)
280    TLSA,
281    /// Transaction Signature
282    ///
283    /// Can be used to authenticate dynamic updates as coming from an approved client, or to authenticate responses as coming from an approved recursive name server[13] similar to DNSSEC.
284    ///
285    /// [2845](https://datatracker.ietf.org/doc/html/rfc2845)
286    TSIG,
287    /// Text record
288    ///
289    /// Originally for arbitrary human-readable text in a DNS record. Since the early 1990s, however, this record more often carries machine-readable data, such as specified by RFC 1464, opportunistic encryption, Sender Policy Framework, DKIM, DMARC, DNS-SD, etc.
290    ///
291    /// [1035](https://datatracker.ietf.org/doc/html/rfc1035)
292    TXT,
293    /// Uniform Resource Identifier
294    ///
295    /// Can be used for publishing mappings from hostnames to URIs.
296    ///
297    /// [7553](https://datatracker.ietf.org/doc/html/rfc7553)
298    URI,
299    /// Message Digests for DNS Zones
300    ///
301    /// Provides a cryptographic message digest over DNS zone data at rest.
302    ///
303    /// [8976](https://datatracker.ietf.org/doc/html/rfc8976)
304    ZONEMD,
305}
306
307impl Type {
308    pub fn is_a(&self) -> bool {
309        *self == Self::A
310    }
311    pub fn is_aaaa(&self) -> bool {
312        *self == Self::AAAA
313    }
314    pub fn is_afsdb(&self) -> bool {
315        *self == Self::AFSDB
316    }
317    pub fn is_apl(&self) -> bool {
318        *self == Self::APL
319    }
320    pub fn is_caa(&self) -> bool {
321        *self == Self::CAA
322    }
323    pub fn is_cdnskey(&self) -> bool {
324        *self == Self::CDNSKEY
325    }
326    pub fn is_cds(&self) -> bool {
327        *self == Self::CDS
328    }
329    pub fn is_cert(&self) -> bool {
330        *self == Self::CERT
331    }
332    pub fn is_cname(&self) -> bool {
333        *self == Self::CNAME
334    }
335    pub fn is_csync(&self) -> bool {
336        *self == Self::CSYNC
337    }
338    pub fn is_dhcid(&self) -> bool {
339        *self == Self::DHCID
340    }
341    pub fn is_dlv(&self) -> bool {
342        *self == Self::DLV
343    }
344    pub fn is_dname(&self) -> bool {
345        *self == Self::DNAME
346    }
347    pub fn is_dnskey(&self) -> bool {
348        *self == Self::DNSKEY
349    }
350    pub fn is_ds(&self) -> bool {
351        *self == Self::DS
352    }
353    pub fn is_eui48(&self) -> bool {
354        *self == Self::EUI48
355    }
356    pub fn is_eui64(&self) -> bool {
357        *self == Self::EUI64
358    }
359    pub fn is_hinfo(&self) -> bool {
360        *self == Self::HINFO
361    }
362    pub fn is_hip(&self) -> bool {
363        *self == Self::HIP
364    }
365    pub fn is_https(&self) -> bool {
366        *self == Self::HTTPS
367    }
368    pub fn is_ipseckey(&self) -> bool {
369        *self == Self::IPSECKEY
370    }
371    pub fn is_key(&self) -> bool {
372        *self == Self::KEY
373    }
374    pub fn is_kx(&self) -> bool {
375        *self == Self::KX
376    }
377    pub fn is_loc(&self) -> bool {
378        *self == Self::LOC
379    }
380    pub fn is_mx(&self) -> bool {
381        *self == Self::MX
382    }
383    pub fn is_naptr(&self) -> bool {
384        *self == Self::NAPTR
385    }
386    pub fn is_ns(&self) -> bool {
387        *self == Self::NS
388    }
389    pub fn is_nsec(&self) -> bool {
390        *self == Self::NSEC
391    }
392    pub fn is_nsec3(&self) -> bool {
393        *self == Self::NSEC3
394    }
395    pub fn is_nsec3param(&self) -> bool {
396        *self == Self::NSEC3PARAM
397    }
398    pub fn is_openpgpkey(&self) -> bool {
399        *self == Self::OPENPGPKEY
400    }
401    pub fn is_ptr(&self) -> bool {
402        *self == Self::PTR
403    }
404    pub fn is_rrsig(&self) -> bool {
405        *self == Self::RRSIG
406    }
407    pub fn is_rp(&self) -> bool {
408        *self == Self::RP
409    }
410    pub fn is_sig(&self) -> bool {
411        *self == Self::SIG
412    }
413    pub fn is_smimea(&self) -> bool {
414        *self == Self::SMIMEA
415    }
416    pub fn is_soa(&self) -> bool {
417        *self == Self::SOA
418    }
419    pub fn is_srv(&self) -> bool {
420        *self == Self::SRV
421    }
422    pub fn is_sshfp(&self) -> bool {
423        *self == Self::SSHFP
424    }
425    pub fn is_svcb(&self) -> bool {
426        *self == Self::SVCB
427    }
428    pub fn is_ta(&self) -> bool {
429        *self == Self::TA
430    }
431    pub fn is_tkey(&self) -> bool {
432        *self == Self::TKEY
433    }
434    pub fn is_tlsa(&self) -> bool {
435        *self == Self::TLSA
436    }
437    pub fn is_tsig(&self) -> bool {
438        *self == Self::TSIG
439    }
440    pub fn is_txt(&self) -> bool {
441        *self == Self::TXT
442    }
443    pub fn is_uri(&self) -> bool {
444        *self == Self::URI
445    }
446    pub fn is_zonemd(&self) -> bool {
447        *self == Self::ZONEMD
448    }
449}
450
451impl Display for Type {
452    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
453        match self {
454            Self::A => f.write_str("A"),
455            Self::AAAA => f.write_str("AAAA"),
456            Self::AFSDB => f.write_str("AFSDB"),
457            Self::APL => f.write_str("APL"),
458            Self::CAA => f.write_str("CAA"),
459            Self::CDNSKEY => f.write_str("CDNSKEY"),
460            Self::CDS => f.write_str("CDS"),
461            Self::CERT => f.write_str("CERT"),
462            Self::CNAME => f.write_str("CNAME"),
463            Self::CSYNC => f.write_str("CSYNC"),
464            Self::DHCID => f.write_str("DHCID"),
465            Self::DLV => f.write_str("DLV"),
466            Self::DNAME => f.write_str("DNAME"),
467            Self::DNSKEY => f.write_str("DNSKEY"),
468            Self::DS => f.write_str("DS"),
469            Self::EUI48 => f.write_str("EUI48"),
470            Self::EUI64 => f.write_str("EUI64"),
471            Self::HINFO => f.write_str("HINFO"),
472            Self::HIP => f.write_str("HIP"),
473            Self::HTTPS => f.write_str("HTTPS"),
474            Self::IPSECKEY => f.write_str("IPSECKEY"),
475            Self::KEY => f.write_str("KEY"),
476            Self::KX => f.write_str("KX"),
477            Self::LOC => f.write_str("LOC"),
478            Self::MX => f.write_str("MX"),
479            Self::NAPTR => f.write_str("NAPTR"),
480            Self::NS => f.write_str("NS"),
481            Self::NSEC => f.write_str("NSEC"),
482            Self::NSEC3 => f.write_str("NSEC3"),
483            Self::NSEC3PARAM => f.write_str("NSEC3PARAM"),
484            Self::OPENPGPKEY => f.write_str("OPENPGPKEY"),
485            Self::PTR => f.write_str("PTR"),
486            Self::RRSIG => f.write_str("RRSIG"),
487            Self::RP => f.write_str("RP"),
488            Self::SIG => f.write_str("SIG"),
489            Self::SMIMEA => f.write_str("SMIMEA"),
490            Self::SOA => f.write_str("SOA"),
491            Self::SRV => f.write_str("SRV"),
492            Self::SSHFP => f.write_str("SSHFP"),
493            Self::SVCB => f.write_str("SVCB"),
494            Self::TA => f.write_str("TA"),
495            Self::TKEY => f.write_str("TKEY"),
496            Self::TLSA => f.write_str("TLSA"),
497            Self::TSIG => f.write_str("TSIG"),
498            Self::TXT => f.write_str("TXT"),
499            Self::URI => f.write_str("URI"),
500            Self::ZONEMD => f.write_str("ZONEMD"),
501        }
502    }
503}