domain/base/name/mod.rs
1//! Domain names.
2//!
3//! This module provides various types for working with domain names.
4//!
5//! Main types: [`Dname`], [`RelativeDname`], [`ParsedDname`],
6//! [`UncertainDname`], [`DnameBuilder`].<br/>
7//! Main traits: [`ToDname`], [`ToRelativeDname`].
8//!
9//! Domain names are a hierarchical description of the location of
10//! records in a tree. They are formed from a sequence of *labels* that
11//! describe the path through the tree upward from the leaf node to the root.
12//!
13//! ## Domain name representations
14//!
15//! Domain names have multiple representations.
16//!
17//! The *wire format* representation is a binary encoding that is used when
18//! including domain names in messages. In it, labels are just sequences of
19//! octets prefixed by a length octet. The root of the tree is an empty label
20//! and – because it always comes last when walking up the tree – implicitly
21//! marks the end of the domain name. This label is often called the *root
22//! label*. The entire name, including the root label, can be at most 255
23//! octets long.
24//!
25//! This crate stores all domain names internally in this wire format. Thus,
26//! all conversions from and to octets will always expect or provide octets
27//! sequences containing domain names in wire format.
28//!
29//! The *presentation format* is a human readable representation of the domain
30//! name. In it, the octets of each label are interpreted as ASCII characters
31//! or, if there isn’t a printable one, as an escape sequence formed by a
32//! backslash followed by the three-digit decimal value of the octet. Labels
33//! are separated by dots. If a dot (or a backslash) appears as an octet in
34//! a label, they can be escaped by preceding them with a backslash.
35//!
36//! This crate uses the presentation format when converting domain names from
37//! and to strings.
38//!
39//! Finally, *internationalized domain names* (or IDN) is a way to encode
40//! Unicode strings in labels using only ASCII characters. This encoding is
41//! called _punicode._
42//!
43//! This crate currently does not support conversion from and to IDN
44//! representations of domain names. This will be added in future versions.
45//!
46//!
47//! ## Absolute, relative, and ‘uncertain’ domain names
48//!
49//! In some cases, it is useful to have a domain name that doesn’t end with
50//! the root label. Such a name is called a *relative domain name* and,
51//! conversely, a name that does end with the root label is called an
52//! *abolute name*. Because these behave slightly differently, for instance,
53//! you can’t include a relative name in a message, there are different
54//! types for those two cases, [`Dname`] for absolute names and
55//! [`RelativeDname`] for relative names.
56//!
57//! Sometimes, it isn’t quite clear if a domain name is absolute or relative.
58//! This happens in presentation format where the final dot at the end
59//! separating the empty and thus invisible root label is often omitted. For
60//! instance, instead of the strictly correct `www.example.com.` the slightly
61//! shorter `www.example.com` is accepted as an absolute name if it is clear
62//! from context that the name is absolute. The [`UncertainDname`] type
63//! provides a means to keep such a name that may be absolute or relative.
64//!
65//! ## Name compression and parsed names.
66//!
67//! In order to save space in DNS messages (which were originally limited to
68//! 512 bytes for most cases), a name can end in a pointer to another name
69//! stored elsewhere in the message. This makes lazy message parsing somewhat
70//! difficult since you need to carry around a reference to the original
71//! message until actual parsing happens. The type [`ParsedDname`] takes care
72//! of all that and will be returned when parsing a name from a message.
73//!
74//! ## Chained domain names and the name traits.
75//!
76//! When making a relative name absolute to be included in a message, you
77//! often append a suffix to it. In order to avoid having to copy octets
78//! around and make this cheap, the [`Chain`] type allows combining two
79//! other name values. To make this work, the two traits [`ToDname`]
80//! and [`ToRelativeDname`] allow writing code that is generic over any kind
81//! of either absolute or relative domain name.
82//!
83//!
84//! ## Building domain names
85//!
86//! You can create a domain name value from its presentation format using
87//! the `FromStr` trait. Alternatively, the [`DnameBuilder`] type allows you
88//! to construct a name from scratch by appending octets, slices, or complete
89//! labels.
90
91pub use self::builder::{
92 DnameBuilder, FromStrError, PushError, PushNameError,
93};
94pub use self::chain::{Chain, ChainIter, LongChainError, UncertainChainIter};
95pub use self::dname::{Dname, DnameError};
96pub use self::label::{
97 Label, LabelTypeError, LongLabelError, OwnedLabel, SliceLabelsIter,
98 SplitLabelError,
99};
100pub use self::parsed::{ParsedDname, ParsedDnameIter, ParsedSuffixIter};
101pub use self::relative::{
102 DnameIter, RelativeDname, RelativeDnameError, RelativeFromStrError,
103 StripSuffixError,
104};
105pub use self::traits::{FlattenInto, ToDname, ToLabelIter, ToRelativeDname};
106pub use self::uncertain::UncertainDname;
107
108mod builder;
109mod chain;
110mod dname;
111mod label;
112mod parsed;
113mod relative;
114mod traits;
115mod uncertain;