1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use crate::base::cmp::CanonicalOrd;
use crate::base::name::{ParsedDname, ToDname};
use crate::base::wire::ParseError;
use core::cmp::Ordering;
use core::str::FromStr;
use core::{fmt, hash};
use octseq::octets::{Octets, OctetsFrom};
use octseq::parse::Parser;

//------------ Dname --------------------------------------------------------

dname_type_canonical! {
    /// DNAME record data.
    ///
    /// The DNAME record provides redirection for a subtree of the domain
    /// name tree in the DNS.
    ///
    /// The DNAME type is defined in RFC 6672.
    (Dname, Dname, dname, into_dname)
}

//============ Testing ======================================================

#[cfg(test)]
#[cfg(all(feature = "std", feature = "bytes"))]
mod test {
    use super::*;
    use crate::base::name::Dname as Name;
    use crate::base::rdata::test::{
        test_compose_parse, test_rdlen, test_scan,
    };
    use core::str::FromStr;
    use std::vec::Vec;

    #[test]
    fn create_dname() {
        let name = Name::<Vec<u8>>::from_str("bar.example.com").unwrap();
        let rdata = Dname::new(name.clone());
        assert_eq!(rdata.dname(), &name);
    }
    // This covers all the other generated types, too.

    #[test]
    #[allow(clippy::redundant_closure)] // lifetimes ...
    fn dname_compose_parse_scan() {
        let rdata =
            Dname::<Name<Vec<u8>>>::from_str("www.example.com").unwrap();
        test_rdlen(&rdata);
        test_compose_parse(&rdata, |parser| Dname::parse(parser));
        test_scan(&["www.example.com"], Dname::scan, &rdata);
    }
}