pub struct LowerName(/* private fields */);
Expand description
TODO: all LowerNames should be stored in a global “intern” space, and then everything that uses them should be through references. As a workaround the Strings are all Rc as well as the array
Implementations§
Source§impl LowerName
impl LowerName
Sourcepub fn is_root(&self) -> bool
pub fn is_root(&self) -> bool
Returns true if there are no labels, i.e. it’s empty.
In DNS the root is represented by .
§Examples
use hickory_proto::rr::{LowerName, Name};
let root = LowerName::from(Name::root());
assert_eq!(&root.to_string(), ".");
Sourcepub fn is_fqdn(&self) -> bool
pub fn is_fqdn(&self) -> bool
Returns true if the name is a fully qualified domain name.
If this is true, it has effects like only querying for this single name, as opposed to building up a search list in resolvers.
warning: this interface is unstable and may change in the future
§Examples
use std::str::FromStr;
use hickory_proto::rr::{LowerName, Name};
let name = LowerName::from(Name::from_str("www").unwrap());
assert!(!name.is_fqdn());
let name = LowerName::from(Name::from_str("www.example.com").unwrap());
assert!(!name.is_fqdn());
let name = LowerName::from(Name::from_str("www.example.com.").unwrap());
assert!(name.is_fqdn());
Sourcepub fn base_name(&self) -> Self
pub fn base_name(&self) -> Self
Trims off the first part of the name, to help with searching for the domain piece
§Examples
use std::str::FromStr;
use hickory_proto::rr::{LowerName, Name};
let example_com = LowerName::from(Name::from_str("example.com").unwrap());
assert_eq!(example_com.base_name(), LowerName::from(Name::from_str("com.").unwrap()));
assert_eq!(LowerName::from(Name::from_str("com.").unwrap().base_name()), LowerName::from(Name::root()));
assert_eq!(LowerName::from(Name::root().base_name()), LowerName::from(Name::root()));
Sourcepub fn zone_of(&self, name: &Self) -> bool
pub fn zone_of(&self, name: &Self) -> bool
returns true if the name components of self are all present at the end of name
§Example
use std::str::FromStr;
use hickory_proto::rr::{LowerName, Name};
let name = LowerName::from(Name::from_str("www.example.com").unwrap());
let zone = LowerName::from(Name::from_str("example.com").unwrap());
let another = LowerName::from(Name::from_str("example.net").unwrap());
assert!(zone.zone_of(&name));
assert!(!another.zone_of(&name));
Sourcepub fn num_labels(&self) -> u8
pub fn num_labels(&self) -> u8
Returns the number of labels in the name, discounting *
.
§Examples
use std::str::FromStr;
use hickory_proto::rr::{LowerName, Name};
let root = LowerName::from(Name::root());
assert_eq!(root.num_labels(), 0);
let example_com = LowerName::from(Name::from_str("example.com").unwrap());
assert_eq!(example_com.num_labels(), 2);
let star_example_com = LowerName::from(Name::from_str("*.example.com").unwrap());
assert_eq!(star_example_com.num_labels(), 2);
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
returns the length in bytes of the labels. ‘.’ counts as 1
This can be used as an estimate, when serializing labels, they will often be compressed and/or escaped causing the exact length to be different.
Sourcepub fn emit_as_canonical(
&self,
encoder: &mut BinEncoder<'_>,
canonical: bool,
) -> Result<(), ProtoError>
pub fn emit_as_canonical( &self, encoder: &mut BinEncoder<'_>, canonical: bool, ) -> Result<(), ProtoError>
Emits the canonical version of the name to the encoder.
In canonical form, there will be no pointers written to the encoder (i.e. no compression).
Sourcepub fn is_wildcard(&self) -> bool
pub fn is_wildcard(&self) -> bool
Pass through for Name::is_wildcard
Sourcepub fn into_wildcard(self) -> Self
pub fn into_wildcard(self) -> Self
Replaces the first label with the wildcard character, “*”
Methods from Deref<Target = Name>§
Sourcepub fn is_root(&self) -> bool
pub fn is_root(&self) -> bool
Returns true if there are no labels, i.e. it’s empty.
In DNS the root is represented by .
§Examples
use hickory_proto::rr::domain::Name;
let root = Name::root();
assert_eq!(&root.to_string(), ".");
Sourcepub fn is_fqdn(&self) -> bool
pub fn is_fqdn(&self) -> bool
Returns true if the name is a fully qualified domain name.
If this is true, it has effects like only querying for this single name, as opposed to building up a search list in resolvers.
warning: this interface is unstable and may change in the future
§Examples
use std::str::FromStr;
use hickory_proto::rr::domain::Name;
let name = Name::from_str("www").unwrap();
assert!(!name.is_fqdn());
let name = Name::from_str("www.example.com").unwrap();
assert!(!name.is_fqdn());
let name = Name::from_str("www.example.com.").unwrap();
assert!(name.is_fqdn());
Sourcepub fn prepend_label<L: IntoLabel>(&self, label: L) -> Result<Self, ProtoError>
pub fn prepend_label<L: IntoLabel>(&self, label: L) -> Result<Self, ProtoError>
Prepends the label to the beginning of this name
§Example
use std::str::FromStr;
use hickory_proto::rr::domain::Name;
let name = Name::from_str("example.com").unwrap();
let name = name.prepend_label("www").unwrap();
assert_eq!(name, Name::from_str("www.example.com").unwrap());
Sourcepub fn to_lowercase(&self) -> Self
pub fn to_lowercase(&self) -> Self
Creates a new Name with all labels lowercased
§Examples
use std::cmp::Ordering;
use std::str::FromStr;
use hickory_proto::rr::domain::{Label, Name};
let example_com = Name::from_ascii("Example.Com").unwrap();
assert_eq!(example_com.cmp_case(&Name::from_str("example.com").unwrap()), Ordering::Less);
assert!(example_com.to_lowercase().eq_case(&Name::from_str("example.com").unwrap()));
Sourcepub fn base_name(&self) -> Self
pub fn base_name(&self) -> Self
Trims off the first part of the name, to help with searching for the domain piece
§Examples
use std::str::FromStr;
use hickory_proto::rr::domain::Name;
let example_com = Name::from_str("example.com.").unwrap();
assert_eq!(example_com.base_name(), Name::from_str("com.").unwrap());
assert_eq!(Name::from_str("com.").unwrap().base_name(), Name::root());
assert_eq!(Name::root().base_name(), Name::root());
Sourcepub fn trim_to(&self, num_labels: usize) -> Self
pub fn trim_to(&self, num_labels: usize) -> Self
Trims to the number of labels specified
§Examples
use std::str::FromStr;
use hickory_proto::rr::domain::Name;
let example_com = Name::from_str("example.com.").unwrap();
assert_eq!(example_com.trim_to(2), Name::from_str("example.com.").unwrap());
assert_eq!(example_com.trim_to(1), Name::from_str("com.").unwrap());
assert_eq!(example_com.trim_to(0), Name::root());
assert_eq!(example_com.trim_to(3), Name::from_str("example.com.").unwrap());
Sourcepub fn zone_of_case(&self, name: &Self) -> bool
pub fn zone_of_case(&self, name: &Self) -> bool
same as zone_of
allows for case sensitive call
Sourcepub fn zone_of(&self, name: &Self) -> bool
pub fn zone_of(&self, name: &Self) -> bool
returns true if the name components of self are all present at the end of name
§Example
use std::str::FromStr;
use hickory_proto::rr::domain::Name;
let name = Name::from_str("www.example.com").unwrap();
let zone = Name::from_str("example.com").unwrap();
let another = Name::from_str("example.net").unwrap();
assert!(zone.zone_of(&name));
assert!(!name.zone_of(&zone));
assert!(!another.zone_of(&name));
Sourcepub fn num_labels(&self) -> u8
pub fn num_labels(&self) -> u8
Returns the number of labels in the name, discounting *
.
§Examples
use std::str::FromStr;
use hickory_proto::rr::domain::Name;
let root = Name::root();
assert_eq!(root.num_labels(), 0);
let example_com = Name::from_str("example.com").unwrap();
assert_eq!(example_com.num_labels(), 2);
let star_example_com = Name::from_str("*.example.com.").unwrap();
assert_eq!(star_example_com.num_labels(), 2);
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
returns the length in bytes of the labels. ‘.’ counts as 1
This can be used as an estimate, when serializing labels, they will often be compressed and/or escaped causing the exact length to be different.
§Examples
use std::str::FromStr;
use hickory_proto::rr::domain::Name;
assert_eq!(Name::from_str("www.example.com.").unwrap().len(), 16);
assert_eq!(Name::from_str(".").unwrap().len(), 1);
assert_eq!(Name::root().len(), 1);
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns whether the length of the labels, in bytes is 0. In practice, since ‘.’ counts as 1, this is never the case so the method returns false.
Sourcepub fn emit_as_canonical(
&self,
encoder: &mut BinEncoder<'_>,
canonical: bool,
) -> Result<(), ProtoError>
pub fn emit_as_canonical( &self, encoder: &mut BinEncoder<'_>, canonical: bool, ) -> Result<(), ProtoError>
Emits the canonical version of the name to the encoder.
In canonical form, there will be no pointers written to the encoder (i.e. no compression).
Sourcepub fn emit_with_lowercase(
&self,
encoder: &mut BinEncoder<'_>,
lowercase: bool,
) -> Result<(), ProtoError>
pub fn emit_with_lowercase( &self, encoder: &mut BinEncoder<'_>, lowercase: bool, ) -> Result<(), ProtoError>
Writes the labels, as lower case, to the encoder
§Arguments
encoder
- encoder for writing this namelowercase
- if true the name will be lowercased, otherwise it will not be changed when writing
Sourcepub fn to_ascii(&self) -> String
pub fn to_ascii(&self) -> String
Converts this name into an ascii safe string.
If the name is an IDNA name, then the name labels will be returned with the xn--
prefix.
see to_utf8
or the Display
impl for methods which convert labels to utf8.
Sourcepub fn to_utf8(&self) -> String
pub fn to_utf8(&self) -> String
Converts the Name labels to the utf8 String form.
This converts the name to an unescaped format, that could be used with parse. If, the name is
is followed by the final .
, e.g. as in www.example.com.
, which represents a fully
qualified Name.
Sourcepub fn parse_arpa_name(&self) -> Result<IpNet, ProtoError>
pub fn parse_arpa_name(&self) -> Result<IpNet, ProtoError>
Converts a *.arpa Name in a PTR record back into an IpNet if possible.
Sourcepub fn is_localhost(&self) -> bool
pub fn is_localhost(&self) -> bool
Returns true if the Name
is either localhost or in the localhost zone.
§Example
use std::str::FromStr;
use hickory_proto::rr::Name;
let name = Name::from_str("localhost").unwrap();
assert!(name.is_localhost());
let name = Name::from_str("localhost.").unwrap();
assert!(name.is_localhost());
let name = Name::from_str("my.localhost.").unwrap();
assert!(name.is_localhost());
Sourcepub fn is_wildcard(&self) -> bool
pub fn is_wildcard(&self) -> bool
True if the first label of this name is the wildcard, i.e. ‘*’
§Example
use std::str::FromStr;
use hickory_proto::rr::Name;
let name = Name::from_str("www.example.com").unwrap();
assert!(!name.is_wildcard());
let name = Name::from_str("*.example.com").unwrap();
assert!(name.is_wildcard());
let name = Name::root();
assert!(!name.is_wildcard());
Trait Implementations§
Source§impl<'r> BinDecodable<'r> for LowerName
impl<'r> BinDecodable<'r> for LowerName
Source§fn read(decoder: &mut BinDecoder<'r>) -> Result<Self, ProtoError>
fn read(decoder: &mut BinDecoder<'r>) -> Result<Self, ProtoError>
parses the chain of labels this has a max of 255 octets, with each label being less than 63. all names will be stored lowercase internally. This will consume the portions of the Vec which it is reading…
Source§fn from_bytes(bytes: &'r [u8]) -> Result<Self, ProtoError>
fn from_bytes(bytes: &'r [u8]) -> Result<Self, ProtoError>
Source§impl BinEncodable for LowerName
impl BinEncodable for LowerName
Source§fn emit(&self, encoder: &mut BinEncoder<'_>) -> Result<(), ProtoError>
fn emit(&self, encoder: &mut BinEncoder<'_>) -> Result<(), ProtoError>
Source§impl<'de> Deserialize<'de> for LowerName
Available on crate feature serde
only.
impl<'de> Deserialize<'de> for LowerName
serde
only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Ord for LowerName
impl Ord for LowerName
Source§fn cmp(&self, other: &Self) -> Ordering
fn cmp(&self, other: &Self) -> Ordering
Given two lower cased names, this performs a case sensitive comparison.
RFC 4034 DNSSEC Resource Records March 2005
6.1. Canonical DNS LowerName Order
For the purposes of DNS security, owner names are ordered by treating
individual labels as unsigned left-justified octet strings. The
absence of a octet sorts before a zero value octet, and uppercase
US-ASCII letters are treated as if they were lowercase US-ASCII
letters.
To compute the canonical ordering of a set of DNS names, start by
sorting the names according to their most significant (rightmost)
labels. For names in which the most significant label is identical,
continue sorting according to their next most significant label, and
so forth.
For example, the following names are sorted in canonical DNS name
order. The most significant label is "example". At this level,
"example" sorts first, followed by names ending in "a.example", then
by names ending "z.example". The names within each level are sorted
in the same way.
example
a.example
yljkjljk.a.example
Z.a.example
zABC.a.EXAMPLE
z.example
\001.z.example
*.z.example
\200.z.example
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for LowerName
impl PartialOrd for LowerName
impl Eq for LowerName
Auto Trait Implementations§
impl Freeze for LowerName
impl RefUnwindSafe for LowerName
impl Send for LowerName
impl Sync for LowerName
impl Unpin for LowerName
impl UnwindSafe for LowerName
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§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.