pub struct ParsedName<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.
ParsedName
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.
ParsedName
implementes the ToName
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, ToName::to_name
can be used to produce
a flat, self-contained Name
.
Implementations§
source§impl<Octs> ParsedName<Octs>
impl<Octs> ParsedName<Octs>
sourcepub fn is_compressed(&self) -> bool
pub fn is_compressed(&self) -> bool
Returns whether the name is compressed.
sourcepub fn ref_octets(&self) -> ParsedName<&Octs>
pub fn ref_octets(&self) -> ParsedName<&Octs>
Returns an equivalent name for a reference to the contained octets.
source§impl<'a, Octs: Octets + ?Sized> ParsedName<&'a Octs>
impl<'a, Octs: Octets + ?Sized> ParsedName<&'a Octs>
pub fn deref_octets(&self) -> ParsedName<Octs::Range<'a>>
source§impl<Octs: AsRef<[u8]>> ParsedName<Octs>
impl<Octs: AsRef<[u8]>> ParsedName<Octs>
§Working with Labels
sourcepub fn iter(&self) -> ParsedNameIter<'_> ⓘ
pub fn iter(&self) -> ParsedNameIter<'_> ⓘ
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<RelativeName<Octs::Range<'_>>>where
Octs: Octets,
pub fn split_first(&mut self) -> Option<RelativeName<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> ParsedName<Octs>
impl<Octs> ParsedName<Octs>
source§impl<'a, Octs: AsRef<[u8]> + ?Sized> ParsedName<&'a Octs>
impl<'a, Octs: AsRef<[u8]> + ?Sized> ParsedName<&'a Octs>
pub fn parse_ref(parser: &mut Parser<'a, Octs>) -> Result<Self, ParseError>
source§impl ParsedName<()>
impl ParsedName<()>
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 ParsedName<Octs>
impl<Octs, N> CanonicalOrd<N> for ParsedName<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 ParsedName<Octs>
impl<Octs: Clone> Clone for ParsedName<Octs>
source§fn clone(&self) -> ParsedName<Octs>
fn clone(&self) -> ParsedName<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<Name<Target>> for ParsedName<Octs>
impl<Octs, Target> FlattenInto<Name<Target>> for ParsedName<Octs>
type AppendError = <<Target as FromBuilder>::Builder as OctetsBuilder>::AppendError
fn try_flatten_into(self) -> Result<Name<Target>, Self::AppendError>
source§impl<Octs: AsRef<[u8]>> From<Name<Octs>> for ParsedName<Octs>
impl<Octs: AsRef<[u8]>> From<Name<Octs>> for ParsedName<Octs>
source§fn from(name: Name<Octs>) -> ParsedName<Octs>
fn from(name: Name<Octs>) -> ParsedName<Octs>
source§impl<'a, Octs> IntoIterator for &'a ParsedName<Octs>
impl<'a, Octs> IntoIterator for &'a ParsedName<Octs>
source§impl<Octs: AsRef<[u8]>> Ord for ParsedName<Octs>
impl<Octs: AsRef<[u8]>> Ord for ParsedName<Octs>
source§impl<Octs, N> PartialEq<N> for ParsedName<Octs>
impl<Octs, N> PartialEq<N> for ParsedName<Octs>
source§impl<Octs, N> PartialOrd<N> for ParsedName<Octs>
impl<Octs, N> PartialOrd<N> for ParsedName<Octs>
source§impl<Octs: AsRef<[u8]>> ToLabelIter for ParsedName<Octs>
impl<Octs: AsRef<[u8]>> ToLabelIter for ParsedName<Octs>
source§type LabelIter<'s> = ParsedNameIter<'s>
where
Octs: 's
type LabelIter<'s> = ParsedNameIter<'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
.source§impl<Octs: AsRef<[u8]>> ToName for ParsedName<Octs>
impl<Octs: AsRef<[u8]>> ToName for ParsedName<Octs>
source§fn as_flat_slice(&self) -> Option<&[u8]>
fn as_flat_slice(&self) -> Option<&[u8]>
source§fn try_to_name<Octets>(
&self,
) -> Result<Name<Octets>, BuilderAppendError<Octets>>
fn try_to_name<Octets>( &self, ) -> Result<Name<Octets>, BuilderAppendError<Octets>>
source§fn to_name<Octets>(&self) -> Name<Octets>where
Octets: FromBuilder,
<Octets as FromBuilder>::Builder: OctetsBuilder<AppendError = Infallible> + EmptyBuilder,
fn to_name<Octets>(&self) -> Name<Octets>where
Octets: FromBuilder,
<Octets as FromBuilder>::Builder: OctetsBuilder<AppendError = Infallible> + EmptyBuilder,
source§fn try_to_canonical_name<Octets>(
&self,
) -> Result<Name<Octets>, BuilderAppendError<Octets>>
fn try_to_canonical_name<Octets>( &self, ) -> Result<Name<Octets>, BuilderAppendError<Octets>>
source§fn to_canonical_name<Octets>(&self) -> Name<Octets>where
Octets: FromBuilder,
<Octets as FromBuilder>::Builder: OctetsBuilder<AppendError = Infallible> + EmptyBuilder,
fn to_canonical_name<Octets>(&self) -> Name<Octets>where
Octets: FromBuilder,
<Octets as FromBuilder>::Builder: OctetsBuilder<AppendError = Infallible> + EmptyBuilder,
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: ToName + ?Sized>(&self, other: &N) -> Ordering
fn composed_cmp<N: ToName + ?Sized>(&self, other: &N) -> Ordering
source§fn lowercase_composed_cmp<N: ToName + ?Sized>(&self, other: &N) -> Ordering
fn lowercase_composed_cmp<N: ToName + ?Sized>(&self, other: &N) -> Ordering
source§fn rrsig_label_count(&self) -> u8
fn rrsig_label_count(&self) -> u8
impl<Octs: Copy> Copy for ParsedName<Octs>
impl<Octs: AsRef<[u8]>> Eq for ParsedName<Octs>
Auto Trait Implementations§
impl<Octs> Freeze for ParsedName<Octs>where
Octs: Freeze,
impl<Octs> RefUnwindSafe for ParsedName<Octs>where
Octs: RefUnwindSafe,
impl<Octs> Send for ParsedName<Octs>where
Octs: Send,
impl<Octs> Sync for ParsedName<Octs>where
Octs: Sync,
impl<Octs> Unpin for ParsedName<Octs>where
Octs: Unpin,
impl<Octs> UnwindSafe for ParsedName<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
)