Struct domain::base::name::ParsedDname
source · pub struct ParsedDname<Octs> { /* 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§
source§impl<Octs> ParsedDname<Octs>
impl<Octs> ParsedDname<Octs>
sourcepub fn is_compressed(&self) -> bool
pub fn is_compressed(&self) -> bool
Returns whether the name is compressed.
sourcepub fn ref_octets(&self) -> ParsedDname<&Octs>
pub fn ref_octets(&self) -> ParsedDname<&Octs>
Returns an equivalent name for a reference to the contained octets.
source§impl<'a, Octs: Octets + ?Sized> ParsedDname<&'a Octs>
impl<'a, Octs: Octets + ?Sized> ParsedDname<&'a Octs>
pub fn deref_octets(&self) -> ParsedDname<Octs::Range<'a>>
source§impl<Octs: AsRef<[u8]>> ParsedDname<Octs>
impl<Octs: AsRef<[u8]>> ParsedDname<Octs>
§Working with Labels
sourcepub fn iter(&self) -> ParsedDnameIter<'_> ⓘ
pub fn iter(&self) -> ParsedDnameIter<'_> ⓘ
Returns an iterator over the labels of the name.
sourcepub fn iter_suffixes(&self) -> ParsedSuffixIter<'_, Octs> ⓘ
pub fn iter_suffixes(&self) -> ParsedSuffixIter<'_, Octs> ⓘ
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<N: ToLabelIter>(&self, base: &N) -> bool
pub fn starts_with<N: ToLabelIter>(&self, base: &N) -> bool
Determines whether base
is a prefix of self
.
sourcepub fn ends_with<N: ToLabelIter>(&self, base: &N) -> bool
pub fn ends_with<N: ToLabelIter>(&self, base: &N) -> bool
Determines whether base
is a suffix of self
.
sourcepub fn split_first(&mut self) -> Option<RelativeDname<Octs::Range<'_>>>where
Octs: Octets,
pub fn split_first(&mut self) -> Option<RelativeDname<Octs::Range<'_>>>where
Octs: Octets,
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.
source§impl<Octs> ParsedDname<Octs>
impl<Octs> ParsedDname<Octs>
source§impl<'a, Octs: AsRef<[u8]> + ?Sized> ParsedDname<&'a Octs>
impl<'a, Octs: AsRef<[u8]> + ?Sized> ParsedDname<&'a Octs>
pub fn parse_ref(parser: &mut Parser<'a, Octs>) -> Result<Self, ParseError>
source§impl ParsedDname<()>
impl ParsedDname<()>
sourcepub fn skip<Src: AsRef<[u8]> + ?Sized>(
parser: &mut Parser<'_, Src>,
) -> Result<(), ParseError>
pub fn skip<Src: AsRef<[u8]> + ?Sized>( parser: &mut Parser<'_, Src>, ) -> 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.
Trait Implementations§
source§impl<Octs, N> CanonicalOrd<N> for ParsedDname<Octs>
impl<Octs, N> CanonicalOrd<N> for ParsedDname<Octs>
source§fn canonical_cmp(&self, other: &N) -> Ordering
fn canonical_cmp(&self, other: &N) -> Ordering
self
and other
.source§fn canonical_lt(&self, other: &Rhs) -> bool
fn canonical_lt(&self, other: &Rhs) -> bool
self
is canonically less than other
.source§fn canonical_le(&self, other: &Rhs) -> bool
fn canonical_le(&self, other: &Rhs) -> bool
self
is canonically less than or equal to other
.source§fn canonical_gt(&self, other: &Rhs) -> bool
fn canonical_gt(&self, other: &Rhs) -> bool
self
is canonically greater than other
.source§fn canonical_ge(&self, other: &Rhs) -> bool
fn canonical_ge(&self, other: &Rhs) -> bool
self
is canonically greater than or equal to other
.source§impl<Octs: Clone> Clone for ParsedDname<Octs>
impl<Octs: Clone> Clone for ParsedDname<Octs>
source§fn clone(&self) -> ParsedDname<Octs>
fn clone(&self) -> ParsedDname<Octs>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<Octs, Target> FlattenInto<Dname<Target>> for ParsedDname<Octs>
impl<Octs, Target> FlattenInto<Dname<Target>> for ParsedDname<Octs>
type AppendError = <<Target as FromBuilder>::Builder as OctetsBuilder>::AppendError
fn try_flatten_into(self) -> Result<Dname<Target>, Self::AppendError>
source§impl<Octs: AsRef<[u8]>> From<Dname<Octs>> for ParsedDname<Octs>
impl<Octs: AsRef<[u8]>> From<Dname<Octs>> for ParsedDname<Octs>
source§fn from(name: Dname<Octs>) -> ParsedDname<Octs>
fn from(name: Dname<Octs>) -> ParsedDname<Octs>
source§impl<'a, Octs> IntoIterator for &'a ParsedDname<Octs>
impl<'a, Octs> IntoIterator for &'a ParsedDname<Octs>
source§impl<Octs: AsRef<[u8]>> Ord for ParsedDname<Octs>
impl<Octs: AsRef<[u8]>> Ord for ParsedDname<Octs>
source§impl<Octs, N> PartialEq<N> for ParsedDname<Octs>
impl<Octs, N> PartialEq<N> for ParsedDname<Octs>
source§impl<Octs, N> PartialOrd<N> for ParsedDname<Octs>
impl<Octs, N> PartialOrd<N> for ParsedDname<Octs>
source§impl<Octs: AsRef<[u8]>> ToDname for ParsedDname<Octs>
impl<Octs: AsRef<[u8]>> ToDname for ParsedDname<Octs>
source§fn as_flat_slice(&self) -> Option<&[u8]>
fn as_flat_slice(&self) -> Option<&[u8]>
source§fn to_dname<Octets>(&self) -> Result<Dname<Octets>, BuilderAppendError<Octets>>
fn to_dname<Octets>(&self) -> Result<Dname<Octets>, BuilderAppendError<Octets>>
source§fn to_canonical_dname<Octets>(
&self,
) -> Result<Dname<Octets>, BuilderAppendError<Octets>>
fn to_canonical_dname<Octets>( &self, ) -> Result<Dname<Octets>, BuilderAppendError<Octets>>
fn compose<Target: OctetsBuilder + ?Sized>( &self, target: &mut Target, ) -> Result<(), Target::AppendError>
fn compose_canonical<Target: OctetsBuilder + ?Sized>( &self, target: &mut Target, ) -> Result<(), Target::AppendError>
source§fn composed_cmp<N: ToDname + ?Sized>(&self, other: &N) -> Ordering
fn composed_cmp<N: ToDname + ?Sized>(&self, other: &N) -> Ordering
source§fn lowercase_composed_cmp<N: ToDname + ?Sized>(&self, other: &N) -> Ordering
fn lowercase_composed_cmp<N: ToDname + ?Sized>(&self, other: &N) -> Ordering
source§fn rrsig_label_count(&self) -> u8
fn rrsig_label_count(&self) -> u8
source§impl<Octs: AsRef<[u8]>> ToLabelIter for ParsedDname<Octs>
impl<Octs: AsRef<[u8]>> ToLabelIter for ParsedDname<Octs>
source§type LabelIter<'s> = ParsedDnameIter<'s>
where
Octs: 's
type LabelIter<'s> = ParsedDnameIter<'s> where Octs: 's
source§fn iter_labels(&self) -> Self::LabelIter<'_>
fn iter_labels(&self) -> Self::LabelIter<'_>
source§fn compose_len(&self) -> u16
fn compose_len(&self) -> u16
source§fn starts_with<N: ToLabelIter + ?Sized>(&self, base: &N) -> bool
fn starts_with<N: ToLabelIter + ?Sized>(&self, base: &N) -> bool
base
is a prefix of self
.impl<Octs: Copy> Copy for ParsedDname<Octs>
impl<Octs: AsRef<[u8]>> Eq for ParsedDname<Octs>
Auto Trait Implementations§
impl<Octs> Freeze for ParsedDname<Octs>where
Octs: Freeze,
impl<Octs> RefUnwindSafe for ParsedDname<Octs>where
Octs: RefUnwindSafe,
impl<Octs> Send for ParsedDname<Octs>where
Octs: Send,
impl<Octs> Sync for ParsedDname<Octs>where
Octs: Sync,
impl<Octs> Unpin for ParsedDname<Octs>where
Octs: Unpin,
impl<Octs> UnwindSafe for ParsedDname<Octs>where
Octs: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)