Struct domain::base::name::ParsedName

source ·
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>

source

pub fn is_compressed(&self) -> bool

Returns whether the name is compressed.

source

pub fn is_root(&self) -> bool

Returns whether the name is the root label only.

source

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>

source

pub fn deref_octets(&self) -> ParsedName<Octs::Range<'a>>

source§

impl<Octs: AsRef<[u8]>> ParsedName<Octs>

§Working with Labels

source

pub fn iter(&self) -> ParsedNameIter<'_>

Returns an iterator over the labels of the name.

source

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.

source

pub fn label_count(&self) -> usize

Returns the number of labels in the domain name.

source

pub fn first(&self) -> &Label

Returns a reference to the first label.

source

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.

source

pub fn starts_with<N: ToLabelIter>(&self, base: &N) -> bool

Determines whether base is a prefix of self.

source

pub fn ends_with<N: ToLabelIter>(&self, base: &N) -> bool

Determines whether base is a suffix of self.

source

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

pub fn parent(&mut self) -> bool

Reduces the name to the parent of the current name.

If the name consists of the root label only, returns false and does nothing. Otherwise, drops the first label and returns true.

source§

impl<Octs> ParsedName<Octs>

source

pub fn parse<'a, Src: Octets<Range<'a> = Octs> + ?Sized>( parser: &mut Parser<'a, Src>, ) -> Result<Self, ParseError>

source§

impl<'a, Octs: AsRef<[u8]> + ?Sized> ParsedName<&'a Octs>

source

pub fn parse_ref(parser: &mut Parser<'a, Octs>) -> Result<Self, ParseError>

source§

impl ParsedName<()>

source

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>
where Octs: AsRef<[u8]>, N: ToName + ?Sized,

source§

fn canonical_cmp(&self, other: &N) -> Ordering

Returns the canonical ordering between self and other.
source§

fn canonical_lt(&self, other: &Rhs) -> bool

Returns whether self is canonically less than other.
source§

fn canonical_le(&self, other: &Rhs) -> bool

Returns whether self is canonically less than or equal to other.
source§

fn canonical_gt(&self, other: &Rhs) -> bool

Returns whether self is canonically greater than other.
source§

fn canonical_ge(&self, other: &Rhs) -> bool

Returns whether self is canonically greater than or equal to other.
source§

impl<Octs: Clone> Clone for ParsedName<Octs>

source§

fn clone(&self) -> ParsedName<Octs>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<Octs: AsRef<[u8]>> Debug for ParsedName<Octs>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<Octs: AsRef<[u8]>> Display for ParsedName<Octs>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the domain name.

This will produce the domain name in common display format without the trailing dot.

source§

impl<Octs, Target> FlattenInto<Name<Target>> for ParsedName<Octs>
where Octs: Octets, Target: FromBuilder, <Target as FromBuilder>::Builder: EmptyBuilder,

source§

impl<Octs: AsRef<[u8]>> From<Name<Octs>> for ParsedName<Octs>

source§

fn from(name: Name<Octs>) -> ParsedName<Octs>

Converts to this type from the input type.
source§

impl<Octs: AsRef<[u8]>> Hash for ParsedName<Octs>

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'a, Octs> IntoIterator for &'a ParsedName<Octs>
where Octs: AsRef<[u8]>,

source§

type Item = &'a Label

The type of the elements being iterated over.
source§

type IntoIter = ParsedNameIter<'a>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<Octs: AsRef<[u8]>> Ord for ParsedName<Octs>

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<Octs, N> PartialEq<N> for ParsedName<Octs>
where Octs: AsRef<[u8]>, N: ToName + ?Sized,

source§

fn eq(&self, other: &N) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<Octs, N> PartialOrd<N> for ParsedName<Octs>
where Octs: AsRef<[u8]>, N: ToName + ?Sized,

source§

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 · source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<Octs: AsRef<[u8]>> ToLabelIter for ParsedName<Octs>

source§

type LabelIter<'s> = ParsedNameIter<'s> where Octs: 's

The type of the iterator over the labels. Read more
source§

fn iter_labels(&self) -> Self::LabelIter<'_>

Returns an iterator over the labels.
source§

fn compose_len(&self) -> u16

Returns the length in octets of the encoded name.
source§

fn starts_with<N: ToLabelIter + ?Sized>(&self, base: &N) -> bool

Determines whether base is a prefix of self.
source§

fn ends_with<N: ToLabelIter + ?Sized>(&self, base: &N) -> bool

Determines whether base is a suffix of self.
source§

impl<Octs: AsRef<[u8]>> ToName for ParsedName<Octs>

source§

fn as_flat_slice(&self) -> Option<&[u8]>

Returns an octets slice of the content if possible. Read more
source§

fn try_to_name<Octets>( &self, ) -> Result<Name<Octets>, BuilderAppendError<Octets>>
where Octets: FromBuilder, <Octets as FromBuilder>::Builder: EmptyBuilder,

Converts the name into a single, uncompressed name. Read more
source§

fn to_name<Octets>(&self) -> Name<Octets>
where Octets: FromBuilder, <Octets as FromBuilder>::Builder: OctetsBuilder<AppendError = Infallible> + EmptyBuilder,

Converts the name into a single, uncompressed name. Read more
source§

fn try_to_canonical_name<Octets>( &self, ) -> Result<Name<Octets>, BuilderAppendError<Octets>>
where Octets: FromBuilder, <Octets as FromBuilder>::Builder: EmptyBuilder,

Converts the name into a single name in canonical form.
source§

fn to_canonical_name<Octets>(&self) -> Name<Octets>
where Octets: FromBuilder, <Octets as FromBuilder>::Builder: OctetsBuilder<AppendError = Infallible> + EmptyBuilder,

Converts the name into a single name in canonical form. Read more
source§

fn compose<Target: OctetsBuilder + ?Sized>( &self, target: &mut Target, ) -> Result<(), Target::AppendError>

source§

fn compose_canonical<Target: OctetsBuilder + ?Sized>( &self, target: &mut Target, ) -> Result<(), Target::AppendError>

source§

fn to_cow(&self) -> Name<Cow<'_, [u8]>>

Returns a cow of the domain name. Read more
source§

fn to_vec(&self) -> Name<Vec<u8>>

Returns the domain name assembled into a Vec<u8>.
source§

fn to_bytes(&self) -> Name<Bytes>

Returns the domain name assembled into a bytes value.
source§

fn name_eq<N: ToName + ?Sized>(&self, other: &N) -> bool

Tests whether self and other are equal. Read more
source§

fn name_cmp<N: ToName + ?Sized>(&self, other: &N) -> Ordering

Returns the ordering between self and other. Read more
source§

fn composed_cmp<N: ToName + ?Sized>(&self, other: &N) -> Ordering

Returns the composed name ordering.
source§

fn lowercase_composed_cmp<N: ToName + ?Sized>(&self, other: &N) -> Ordering

Returns the lowercase composed ordering.
source§

fn rrsig_label_count(&self) -> u8

Returns the number of labels for the RRSIG Labels field. Read more
source§

impl<Octs: Copy> Copy for ParsedName<Octs>

source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<Source, Target> OctetsInto<Target> for Source
where Target: OctetsFrom<Source>,

source§

type Error = <Target as OctetsFrom<Source>>::Error

source§

fn try_octets_into( self, ) -> Result<Target, <Source as OctetsInto<Target>>::Error>

Performs the conversion.
source§

fn octets_into(self) -> Target
where Self::Error: Into<Infallible>,

Performs an infallible conversion.
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
source§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more