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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
//! The CNAME record data type.
use Ordering;
use crate;
use crateCanonicalName;
use crateParseMessageBytes;
use crate;
use crate;
//----------- CName ----------------------------------------------------------
/// The canonical name for this domain.
///
/// A [`CName`] record indicates that a domain name is an alias. Any data
/// associated with that domain name originates from the "canonical" domain
/// name (with a few DNSSEC-related exceptions). If a domain name is an
/// alias, it has a single canonical name (see [RFC 2181, section 10.1]); it
/// cannot have multiple distinct [`CName`] records.
///
/// [RFC 2181, section 10.1]: https://datatracker.ietf.org/doc/html/rfc2181#section-10.1
///
/// [`CName`] is specified by [RFC 1035, section 3.3.1]. The behaviour of DNS
/// lookups and name servers is specified by [RFC 1034, section 3.6.2].
///
/// [RFC 1034, section 3.6.2]: https://datatracker.ietf.org/doc/html/rfc1034#section-3.6.2
/// [RFC 1035, section 3.3.1]: https://datatracker.ietf.org/doc/html/rfc1035#section-3.3.1
///
/// ## Wire Format
///
/// The wire format of a [`CName`] record is simply the canonical domain name.
/// This domain name may be compressed in DNS messages.
///
/// ## Usage
///
/// Because [`CName`] is a record data type, it is usually handled within
/// an enum like [`RecordData`]. This section describes how to use it
/// independently (or when building new record data from scratch).
///
/// [`RecordData`]: crate::new::rdata::RecordData
///
/// In order to build a [`CName`], it's first important to choose a domain
/// name type. For short-term usage (where the [`CName`] is a local
/// variable), it is common to pick [`RevNameBuf`]. If the [`CName`] will
/// be placed on the heap, <code>Box<[`RevName`]></code> will be more
/// efficient.
///
/// [`RevName`]: crate::new::base::name::RevName
/// [`RevNameBuf`]: crate::new::base::name::RevNameBuf
///
/// The primary way to build a new [`CName`] is to construct each
/// field manually. To parse a [`CName`] from a DNS message, use
/// [`ParseMessageBytes`]. In case the input bytes don't use name
/// compression, [`ParseBytes`] can be used.
///
/// ```
/// # use domain::new::base::name::{Name, RevNameBuf};
/// # use domain::new::base::wire::{BuildBytes, ParseBytes, ParseBytesZC};
/// # use domain::new::rdata::CName;
/// #
/// // Build a 'CName' manually:
/// let manual: CName<RevNameBuf> = CName {
/// name: "example.org".parse().unwrap(),
/// };
///
/// // Its wire format serialization looks like:
/// let bytes = b"\x07example\x03org\x00";
/// # let mut buffer = [0u8; 13];
/// # manual.build_bytes(&mut buffer).unwrap();
/// # assert_eq!(*bytes, buffer);
///
/// // Parse a 'CName' from the wire format, without name decompression:
/// let from_wire: CName<RevNameBuf> = CName::parse_bytes(bytes).unwrap();
/// # assert_eq!(manual, from_wire);
///
/// // See 'ParseMessageBytes' for parsing with name decompression.
/// ```
///
/// Since [`CName`] is a sized type, and it implements [`Copy`] and [`Clone`],
/// it's straightforward to handle and move around. However, this depends on
/// the domain name type. It can be changed using [`CName::map_name()`] and
/// [`CName::map_name_by_ref()`].
///
/// For debugging, [`CName`] can be formatted using [`fmt::Debug`].
///
/// [`fmt::Debug`]: core::fmt::Debug
///
/// To serialize a [`CName`] in the wire format, use [`BuildInMessage`]
/// (which supports name compression). If name compression is not desired,
/// use [`BuildBytes`].
//--- Interaction
//--- Canonical operations
//--- Parsing from DNS messages
//--- Building into DNS messages
//--- Parsing record data