Struct domain::base::ParsedDname
source · [−]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.
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
Returns the canonical ordering between self
and other
.
sourcefn canonical_lt(&self, other: &Rhs) -> bool
fn canonical_lt(&self, other: &Rhs) -> bool
Returns whether self
is canonically less than other
.
sourcefn canonical_le(&self, other: &Rhs) -> bool
fn canonical_le(&self, other: &Rhs) -> bool
Returns whether self
is canonically less than or equal to other
.
sourcefn canonical_gt(&self, other: &Rhs) -> bool
fn canonical_gt(&self, other: &Rhs) -> bool
Returns whether self
is canonically greater than other
.
sourcefn canonical_ge(&self, other: &Rhs) -> bool
fn canonical_ge(&self, other: &Rhs) -> bool
Returns whether 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>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<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>
Appends the concrete representation of the value to the target. Read more
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>
Appends the canonical representation of the value to the target. Read more
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>
Converts to this type from the input type.
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
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
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>,
Restrict a value to a certain interval. Read more
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>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl<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]>
Returns an octets slice of the content if possible. Read more
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,
Converts the name into a single, uncompressed name. Read more
sourcefn name_eq<N: ToDname + ?Sized>(&self, other: &N) -> bool
fn name_eq<N: ToDname + ?Sized>(&self, other: &N) -> bool
Tests whether self
and other
are equal. Read more
sourcefn name_cmp<N: ToDname + ?Sized>(&self, other: &N) -> Ordering
fn name_cmp<N: ToDname + ?Sized>(&self, other: &N) -> Ordering
Returns the ordering between self
and other
. Read more
sourcefn composed_cmp<N: ToDname + ?Sized>(&self, other: &N) -> Ordering
fn composed_cmp<N: ToDname + ?Sized>(&self, other: &N) -> Ordering
Returns the composed name ordering.
sourcefn lowercase_composed_cmp<N: ToDname + ?Sized>(&self, other: &N) -> Ordering
fn lowercase_composed_cmp<N: ToDname + ?Sized>(&self, other: &N) -> Ordering
Returns the lowercase composed ordering.
sourcefn rrsig_label_count(&self) -> u8
fn rrsig_label_count(&self) -> u8
Returns the number of labels for the RRSIG Labels field. Read more
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>
The type of the iterator over the labels. Read more
sourcefn iter_labels(&'a self) -> Self::LabelIter
fn iter_labels(&'a self) -> Self::LabelIter
Returns an iterator over the labels.
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
Determines whether base
is a prefix of self
.
impl<Ref: Copy> Copy for ParsedDname<Ref>
impl<Ref: AsRef<[u8]>> Eq for ParsedDname<Ref>
Auto Trait Implementations
impl<Ref> RefUnwindSafe for ParsedDname<Ref>where
Ref: RefUnwindSafe,
impl<Ref> Send for ParsedDname<Ref>where
Ref: Send,
impl<Ref> Sync for ParsedDname<Ref>where
Ref: Sync,
impl<Ref> Unpin for ParsedDname<Ref>where
Ref: Unpin,
impl<Ref> UnwindSafe for ParsedDname<Ref>where
Ref: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Source, Target> OctetsInto<Target> for Sourcewhere
Target: OctetsFrom<Source>,
impl<Source, Target> OctetsInto<Target> for Sourcewhere
Target: OctetsFrom<Source>,
sourcefn octets_into(self) -> Result<Target, ShortBuf>
fn octets_into(self) -> Result<Target, ShortBuf>
Performs the conversion.