pub struct ParsedDname<Ref> { /* private fields */ }
Expand description
A domain name parsed from a DNS message.
In an attempt to keep messages small, DNS uses a procedure called ‘name compression.’ It tries to minimize the space used for repeatedly appearing domain names by simply refering to the first occurence of the name. This works not only for complete names but also for suffixes. In this case, the first unique labels of the name are included and then a pointer is included for the remainder of the name.
A consequence of this is that when parsing a domain name, its labels can be scattered all over the message and we would need to allocate some space to re-assemble the original name. However, in many cases we don’t need the complete name. Many operations can be performed by just iterating over the labels which we can do in place.
ParsedDname
deals with such names. It takes a copy of a Parser
representing a reference to the underlying DNS message and, if nedded,
traverses over the name starting at the current position of the parser.
When being created, the type quickly walks over the name to check that it
is, indeed, a valid name. While this does take a bit of time, it spares
you having to deal with possible parse errors later on.
ParsedDname
implementes the ToDname
trait, so you can use it
everywhere where a generic absolute domain name is accepted. In
particular, you can compare it to other names or chain it to the end of a
relative name. If necessary, ToDname::to_name
can be used to produce
a flat, self-contained Dname
.
Implementations
sourceimpl<Ref> ParsedDname<Ref>
impl<Ref> ParsedDname<Ref>
sourceimpl<Ref: AsRef<[u8]>> ParsedDname<Ref>
impl<Ref: AsRef<[u8]>> ParsedDname<Ref>
sourcepub fn iter(&self) -> ParsedDnameIter<'_>ⓘNotable traits for ParsedDnameIter<'a>impl<'a> Iterator for ParsedDnameIter<'a> type Item = &'a Label;
pub fn iter(&self) -> ParsedDnameIter<'_>ⓘNotable traits for ParsedDnameIter<'a>impl<'a> Iterator for ParsedDnameIter<'a> type Item = &'a Label;
Returns an iterator over the labels of the name.
sourcepub fn iter_suffixes(&self) -> ParsedSuffixIter<Ref>ⓘNotable traits for ParsedSuffixIter<Ref>impl<Ref: AsRef<[u8]> + Clone> Iterator for ParsedSuffixIter<Ref> type Item = ParsedDname<Ref>;
where
Ref: Clone,
pub fn iter_suffixes(&self) -> ParsedSuffixIter<Ref>ⓘNotable traits for ParsedSuffixIter<Ref>impl<Ref: AsRef<[u8]> + Clone> Iterator for ParsedSuffixIter<Ref> type Item = ParsedDname<Ref>;
where
Ref: Clone,
Returns an iterator over the suffixes of the name.
The returned iterator starts with the full name and then for each additional step returns a name with the left-most label stripped off until it reaches the root label.
sourcepub fn label_count(&self) -> usize
pub fn label_count(&self) -> usize
Returns the number of labels in the domain name.
sourcepub fn last(&self) -> &'static Label
pub fn last(&self) -> &'static Label
Returns a reference to the last label.
Because the last label in an absolute name is always the root label, this method can return a static reference. It is also a wee bit silly, but here for completeness.
sourcepub fn starts_with<'a, N: ToLabelIter<'a>>(&'a self, base: &'a N) -> bool
pub fn starts_with<'a, N: ToLabelIter<'a>>(&'a self, base: &'a N) -> bool
Determines whether base
is a prefix of self
.
sourcepub fn ends_with<'a, N: ToLabelIter<'a>>(&'a self, base: &'a N) -> bool
pub fn ends_with<'a, N: ToLabelIter<'a>>(&'a self, base: &'a N) -> bool
Determines whether base
is a suffix of self
.
sourcepub fn split_first(&mut self) -> Option<RelativeDname<Ref::Range>>where
Ref: OctetsRef,
pub fn split_first(&mut self) -> Option<RelativeDname<Ref::Range>>where
Ref: OctetsRef,
Splits off the first label.
If this name is longer than just the root label, returns the first
label as a relative name and removes it from the name itself. If the
name is only the root label, returns None
and does nothing.
sourceimpl<Ref: OctetsRef> ParsedDname<Ref>
impl<Ref: OctetsRef> ParsedDname<Ref>
sourcepub fn flatten_into<Octets>(self) -> Result<Dname<Octets>, PushError>where
Octets: OctetsFrom<Ref::Range> + FromBuilder,
<Octets as FromBuilder>::Builder: EmptyBuilder,
pub fn flatten_into<Octets>(self) -> Result<Dname<Octets>, PushError>where
Octets: OctetsFrom<Ref::Range> + FromBuilder,
<Octets as FromBuilder>::Builder: EmptyBuilder,
Flatten ParsedDname
into a Dname
in case it is compressed,
otherwise cheap copy the underlying octets.
Trait Implementations
sourceimpl<Ref, N> CanonicalOrd<N> for ParsedDname<Ref>where
Ref: AsRef<[u8]>,
N: ToDname + ?Sized,
impl<Ref, N> CanonicalOrd<N> for ParsedDname<Ref>where
Ref: AsRef<[u8]>,
N: ToDname + ?Sized,
sourcefn canonical_cmp(&self, other: &N) -> Ordering
fn canonical_cmp(&self, other: &N) -> Ordering
self
and other
.sourcefn canonical_lt(&self, other: &Rhs) -> bool
fn canonical_lt(&self, other: &Rhs) -> bool
self
is canonically less than other
.sourcefn canonical_le(&self, other: &Rhs) -> bool
fn canonical_le(&self, other: &Rhs) -> bool
self
is canonically less than or equal to other
.sourcefn canonical_gt(&self, other: &Rhs) -> bool
fn canonical_gt(&self, other: &Rhs) -> bool
self
is canonically greater than other
.sourcefn canonical_ge(&self, other: &Rhs) -> bool
fn canonical_ge(&self, other: &Rhs) -> bool
self
is canonically greater than or equal to other
.sourceimpl<Ref: Clone> Clone for ParsedDname<Ref>
impl<Ref: Clone> Clone for ParsedDname<Ref>
sourcefn clone(&self) -> ParsedDname<Ref>
fn clone(&self) -> ParsedDname<Ref>
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl<Ref: AsRef<[u8]>> Compose for ParsedDname<Ref>
impl<Ref: AsRef<[u8]>> Compose for ParsedDname<Ref>
sourcefn compose<T: OctetsBuilder + AsMut<[u8]>>(
&self,
target: &mut T
) -> Result<(), ShortBuf>
fn compose<T: OctetsBuilder + AsMut<[u8]>>(
&self,
target: &mut T
) -> Result<(), ShortBuf>
sourcefn compose_canonical<T: OctetsBuilder + AsMut<[u8]>>(
&self,
target: &mut T
) -> Result<(), ShortBuf>
fn compose_canonical<T: OctetsBuilder + AsMut<[u8]>>(
&self,
target: &mut T
) -> Result<(), ShortBuf>
sourceimpl<Ref: AsRef<[u8]>> Debug for ParsedDname<Ref>
impl<Ref: AsRef<[u8]>> Debug for ParsedDname<Ref>
sourceimpl<Ref: AsRef<[u8]>> Display for ParsedDname<Ref>
impl<Ref: AsRef<[u8]>> Display for ParsedDname<Ref>
sourceimpl<Ref: AsRef<[u8]>> From<Dname<Ref>> for ParsedDname<Ref>
impl<Ref: AsRef<[u8]>> From<Dname<Ref>> for ParsedDname<Ref>
sourcefn from(name: Dname<Ref>) -> ParsedDname<Ref>
fn from(name: Dname<Ref>) -> ParsedDname<Ref>
sourceimpl<Ref: AsRef<[u8]>> Hash for ParsedDname<Ref>
impl<Ref: AsRef<[u8]>> Hash for ParsedDname<Ref>
sourceimpl<'a, Ref: AsRef<[u8]>> IntoIterator for &'a ParsedDname<Ref>
impl<'a, Ref: AsRef<[u8]>> IntoIterator for &'a ParsedDname<Ref>
sourceimpl<Ref: AsRef<[u8]>> Ord for ParsedDname<Ref>
impl<Ref: AsRef<[u8]>> Ord for ParsedDname<Ref>
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
sourceimpl<Ref> Parse<Ref> for ParsedDname<Ref>where
Ref: AsRef<[u8]> + Clone,
impl<Ref> Parse<Ref> for ParsedDname<Ref>where
Ref: AsRef<[u8]> + Clone,
sourcefn skip(parser: &mut Parser<Ref>) -> Result<(), ParseError>
fn skip(parser: &mut Parser<Ref>) -> Result<(), ParseError>
Skip over a domain name.
This will only check the uncompressed part of the name. If the name is compressed but the compression pointer is invalid or the name pointed to is invalid or too long, the function will still succeed.
If you need to check that the name you are skipping over is valid, you
will have to use parse
and drop the result.
sourceimpl<Ref, N> PartialEq<N> for ParsedDname<Ref>where
Ref: AsRef<[u8]>,
N: ToDname + ?Sized,
impl<Ref, N> PartialEq<N> for ParsedDname<Ref>where
Ref: AsRef<[u8]>,
N: ToDname + ?Sized,
sourceimpl<Ref, N> PartialOrd<N> for ParsedDname<Ref>where
Ref: AsRef<[u8]>,
N: ToDname + ?Sized,
impl<Ref, N> PartialOrd<N> for ParsedDname<Ref>where
Ref: AsRef<[u8]>,
N: ToDname + ?Sized,
sourcefn partial_cmp(&self, other: &N) -> Option<Ordering>
fn partial_cmp(&self, other: &N) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresourceimpl<Ref: AsRef<[u8]>> ToDname for ParsedDname<Ref>
impl<Ref: AsRef<[u8]>> ToDname for ParsedDname<Ref>
sourcefn as_flat_slice(&self) -> Option<&[u8]>
fn as_flat_slice(&self) -> Option<&[u8]>
sourcefn to_dname<Octets>(&self) -> Result<Dname<Octets>, PushError>where
Octets: FromBuilder,
<Octets as FromBuilder>::Builder: OctetsBuilder + EmptyBuilder,
fn to_dname<Octets>(&self) -> Result<Dname<Octets>, PushError>where
Octets: FromBuilder,
<Octets as FromBuilder>::Builder: OctetsBuilder + EmptyBuilder,
sourcefn composed_cmp<N: ToDname + ?Sized>(&self, other: &N) -> Ordering
fn composed_cmp<N: ToDname + ?Sized>(&self, other: &N) -> Ordering
sourcefn lowercase_composed_cmp<N: ToDname + ?Sized>(&self, other: &N) -> Ordering
fn lowercase_composed_cmp<N: ToDname + ?Sized>(&self, other: &N) -> Ordering
sourcefn rrsig_label_count(&self) -> u8
fn rrsig_label_count(&self) -> u8
sourceimpl<'a, Ref: AsRef<[u8]>> ToLabelIter<'a> for ParsedDname<Ref>
impl<'a, Ref: AsRef<[u8]>> ToLabelIter<'a> for ParsedDname<Ref>
type LabelIter = ParsedDnameIter<'a>
type LabelIter = ParsedDnameIter<'a>
sourcefn iter_labels(&'a self) -> Self::LabelIter
fn iter_labels(&'a self) -> Self::LabelIter
sourcefn starts_with<N: ToLabelIter<'a> + ?Sized>(&'a self, base: &'a N) -> bool
fn starts_with<N: ToLabelIter<'a> + ?Sized>(&'a self, base: &'a N) -> bool
base
is a prefix of self
.