domain/base/iana/
class.rs

1//! DNS CLASSes.
2
3//------------ Class ---------------------------------------------------------
4
5int_enum! {
6    /// DNS CLASSes.
7    ///
8    /// The domain name space is partitioned into separate classes for different
9    /// network types. That is, each class has its own separate record tree
10    /// starting at the root. However, in practice, only the IN class is really
11    /// relevant.
12    ///
13    /// In addition, there are query classes or QCLASSes that are used in
14    /// questions or UPDATE queries, namely NONE and ANY (or *).
15    ///
16    /// Classes are represented by a 16 bit value. The enum wraps these values.
17    ///
18    /// See [RFC 1034] for the introduction of classes, section 3.2 of
19    /// [RFC 6895] for a discussion of the current state of afairs, and
20    /// the [DNS CLASSes IANA registry] for an overview of assigned values.
21    /// This type is complete as of the registry update of 2019-01-28.
22    ///
23    /// [RFC 1034]: https://tools.ietf.org/html/rfc1034
24    /// [RFC 6895]: https://tools.ietf.org/html/rfc6895
25    /// [DNS CLASSes IANA registry]: http://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-2
26    =>
27    Class, u16;
28
29    /// Internet (IN).
30    ///
31    /// This class is defined in RFC 1035 and really the only one relevant
32    /// at all.
33    (IN => 1, "IN")
34
35    /// Chaosnet (CH).
36    ///
37    /// A network protocol developed at MIT in the 1970s. Reused by BIND for
38    /// built-in server information zones.",
39    (CH => 3, "CH")
40
41    /// Hesiod (HS).
42    ///
43    /// A system information protocol part of MIT's Project Athena.",
44    (HS => 4, "HS")
45
46    /// Query class None.
47    ///
48    /// Defined in RFC 2136, this class is used in UPDATE queries to
49    /// require that an RRset does not exist prior to the update.",
50    (NONE => 0xFE, "NONE")
51
52    /// Query class * (ANY).
53    ///
54    /// This class can be used in a query to indicate that records for the
55    /// given name from any class are requested.",
56    (ANY => 0xFF, "*")
57}
58
59int_enum_str_with_prefix!(Class, "CLASS", b"CLASS", u16, "unknown class");
60int_enum_zonefile_fmt_with_prefix!(Class, "CLASS");
61
62//============ Tests =========================================================
63
64#[cfg(test)]
65mod test {
66
67    #[cfg(feature = "serde")]
68    #[test]
69    fn ser_de() {
70        use super::Class;
71        use serde_test::{assert_tokens, Configure, Token};
72
73        assert_tokens(&Class::IN.readable(), &[Token::Str("IN")]);
74        assert_tokens(&Class(5).readable(), &[Token::Str("CLASS5")]);
75        assert_tokens(&Class::IN.compact(), &[Token::U16(1)]);
76        assert_tokens(&Class(5).compact(), &[Token::U16(5)]);
77    }
78
79    #[cfg(feature = "std")]
80    #[test]
81    fn debug() {
82        use super::Class;
83
84        assert_eq!(format!("{:?}", Class::IN), "Class::IN");
85        assert_eq!(format!("{:?}", Class(69)), "Class(69)");
86    }
87}