Struct ParsedDname

Source
pub struct ParsedDname { /* 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 rest 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 Parser representing 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.

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 ParsedDname

§Conversion

For a conversion into a regular Dname, see ToDname::to_name.

Source

pub fn into_bytes(self) -> Bytes

Converts the name into a bytes value with its flat representation.

Source§

impl ParsedDname

§Properties

Source

pub fn len(&self) -> usize

Returns the length of the name in bytes.

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§

impl ParsedDname

§Working with Labels

Source

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

Returns an iterator over the labels of the name.

Source

pub fn iter_suffixes(&self) -> ParsedSuffixIter

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<'a, N: ToLabelIter<'a>>(&'a self, base: &'a N) -> bool

Determines whether base is a prefix of self.

Source

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

Determines whether base is a suffix of self.

Source

pub fn split_first(&mut self) -> Option<RelativeDname>

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.

Trait Implementations§

Source§

impl Clone for ParsedDname

Source§

fn clone(&self) -> ParsedDname

Returns a duplicate 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 Compose for ParsedDname

Source§

fn compose_len(&self) -> usize

Returns the number of bytes this value will need without compression.
Source§

fn compose<B: BufMut>(&self, buf: &mut B)

Appends the uncompressed representation of this value to buf. Read more
Source§

impl Compress for ParsedDname

Source§

fn compress(&self, buf: &mut Compressor) -> Result<(), ShortBuf>

Appends the wire-format representation of the value to buf. Read more
Source§

impl Debug for ParsedDname

Source§

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

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

impl Display for ParsedDname

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 Hash for ParsedDname

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> IntoIterator for &'a ParsedDname

Source§

type Item = &'a Label

The type of the elements being iterated over.
Source§

type IntoIter = ParsedDnameIter<'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 Ord for ParsedDname

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,

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

impl Parse for ParsedDname

Source§

fn skip(parser: &mut Parser) -> Result<(), Self::Err>

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.

Source§

type Err = ParsedDnameError

The type of an error returned when parsing fails.
Source§

fn parse(parser: &mut Parser) -> Result<Self, Self::Err>

Extracts a value from the beginning of parser. Read more
Source§

impl ParseAll for ParsedDname

Source§

type Err = ParsedDnameAllError

The type returned when parsing fails.
Source§

fn parse_all(parser: &mut Parser, len: usize) -> Result<Self, Self::Err>

Parses a value len bytes long from the beginning of the parser. Read more
Source§

impl<N: ToDname> PartialEq<N> for ParsedDname

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<N: ToDname> PartialOrd<N> for ParsedDname

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 ToDname for ParsedDname

Source§

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

Returns a byte slice of the content if possible. Read more
Source§

fn to_name(&self) -> Dname

Creates an uncompressed value of the domain name. Read more
Source§

fn name_eq<N: ToDname>(&self, other: &N) -> bool

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

fn name_cmp<N: ToDname>(&self, other: &N) -> Ordering

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

impl<'a> ToLabelIter<'a> for ParsedDname

Source§

type LabelIter = ParsedDnameIter<'a>

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

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

Returns an iterator over the labels.
Source§

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

Determines whether base is a prefix of self.
Source§

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

Determines whether base is a suffix of self.
Source§

impl Eq for ParsedDname

Auto Trait Implementations§

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, dest: *mut u8)

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

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.