domain/rdata/rfc1035/name.rs
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
//! Record data type from RFC 1035 that consist of a single domain name.
//!
//! This is a private module. It’s content is re-exported by the parent.
use crate::base::cmp::CanonicalOrd;
use crate::base::name::{ParsedName, ToName};
use crate::base::wire::ParseError;
use core::{fmt, hash, str};
use core::cmp::Ordering;
use core::str::FromStr;
use octseq::octets::{Octets, OctetsFrom};
use octseq::parse::Parser;
//------------ Cname --------------------------------------------------------
name_type_well_known! {
/// CNAME record data.
///
/// The CNAME record specifies the canonical or primary name for domain
/// name alias.
///
/// The CNAME type is defined in [RFC 1035, section 3.3.1][1].
///
/// [1]: https://tools.ietf.org/html/rfc1035#section-3.3.1
(Cname, CNAME, cname, into_cname)
}
//------------ Mb -----------------------------------------------------------
name_type_well_known! {
/// MB record data.
///
/// The experimental MB record specifies a host that serves a mailbox.
///
/// The MB record type is defined in [RFC 1035, section 3.3.3][1].
///
/// [1]: https://tools.ietf.org/html/rfc1035#section-3.3.3
(Mb, MB, madname, into_madname)
}
//------------ Md -----------------------------------------------------------
name_type_well_known! {
/// MD record data.
///
/// The MD record specifices a host which has a mail agent for
/// the domain which should be able to deliver mail for the domain.
///
/// The MD record is obsolete. It is recommended to either reject the record
/// or convert them into an Mx record at preference 0.
///
/// The MD record type is defined in [RFC 1035, section 3.3.4][1].
///
/// [1]: https://tools.ietf.org/html/rfc1035#section-3.3.4
(Md, MD, madname, into_madname)
}
//------------ Mf -----------------------------------------------------------
name_type_well_known! {
/// MF record data.
///
/// The MF record specifices a host which has a mail agent for
/// the domain which will be accept mail for forwarding to the domain.
///
/// The MF record is obsolete. It is recommended to either reject the record
/// or convert them into an Mx record at preference 10.
///
/// The MF record type is defined in [RFC 1035, section 3.3.5][1].
///
/// [1]: https://tools.ietf.org/html/rfc1035#section-3.3.5
(Mf, MF, madname, into_madname)
}
//------------ Mg -----------------------------------------------------------
name_type_well_known! {
/// MG record data.
///
/// The MG record specifices a mailbox which is a member of the mail group
/// specified by the domain name.
///
/// The MG record is experimental.
///
/// The MG record type is defined in [RFC 1035, section 3.3.6][1].
///
/// [1]: https://tools.ietf.org/html/rfc1035#section-3.3.6
(Mg, MG, madname, into_madname)
}
//------------ Mr -----------------------------------------------------------
name_type_well_known! {
/// MR record data.
///
/// The MR record specifices a mailbox which is the proper rename of the
/// specified mailbox.
///
/// The MR record is experimental.
///
/// The MR record type is defined in [RFC 1035, section 3.3.8][1].
///
/// [1]: https://tools.ietf.org/html/rfc1035#section-3.3.8
(Mr, MR, newname, into_newname)
}
//------------ Ns -----------------------------------------------------------
name_type_well_known! {
/// NS record data.
///
/// NS records specify hosts that are authoritative for a class and domain.
///
/// The NS record type is defined in [RFC 1035, section 3.3.11][1].
///
/// [1]: https://tools.ietf.org/html/rfc1035#section-3.3.11
(Ns, NS, nsdname, into_nsdname)
}
//------------ Ptr ----------------------------------------------------------
name_type_well_known! {
/// PTR record data.
///
/// PRT records are used in special domains to point to some other location
/// in the domain space.
///
/// The PTR record type is defined in [RFC 1035, section 3.3.12][1].
///
/// [1]: https://tools.ietf.org/html/rfc1035#section-3.3.12
(Ptr, PTR, ptrdname, into_ptrdname)
}
//============ Testing =======================================================
#[cfg(test)]
#[cfg(all(feature = "std", feature = "bytes"))]
mod test {
use super::*;
use crate::base::name::Name;
use crate::base::rdata::test::{
test_compose_parse, test_rdlen, test_scan,
};
use std::vec::Vec;
// We only test Cname since all the other types are exactly the same.
#[test]
#[allow(clippy::redundant_closure)] // lifetimes ...
fn cname_compose_parse_scan() {
let rdata =
Cname::<Name<Vec<u8>>>::from_str("www.example.com").unwrap();
test_rdlen(&rdata);
test_compose_parse(&rdata, |parser| Cname::parse(parser));
test_scan(&["www.example.com"], Cname::scan, &rdata);
}
}