pub struct TrustRoot { /* private fields */ }Expand description
A validated trust root (authority) from an agent URI.
The trust root identifies the authority that vouches for an agent’s identity and capabilities. It consists of a host (domain or IP) and an optional port.
§Examples
use agent_uri::TrustRoot;
let root = TrustRoot::parse("anthropic.com").unwrap();
assert_eq!(root.host_str(), "anthropic.com");
assert!(root.port().is_none());
let root = TrustRoot::parse("localhost:8472").unwrap();
assert_eq!(root.host_str(), "localhost");
assert_eq!(root.port(), Some(8472));§Internationalized names
A trust root is ASCII. Converting an internationalized name to A-label form is the caller’s job, and this type will not tell you whether you did it right. Three consequences, none of them accidents:
- A non-ASCII name is rejected, not converted.
münchen.deis an error, not a synonym forxn--mnchen-3ya.de. Doing the conversion here would mean shipping a Unicode normalization table and a version of UTS #46 inside an identity type, and two versions of that table disagreeing would make one name two identities. Refusing is the smaller surface. - An
xn--label is opaque ASCII. It is checked as a DNS label and nothing more: no Punycode decode, no IDNA validity check, no bidirectional or script rules.xn--zzzzzzis not valid Punycode and parses anyway. If a name reaches here already broken, it stays broken. - Nothing here detects confusables.
аpple.comwith a Cyrillicаis rejected only because it is not ASCII; its A-label form,xn--pple-43d.com, is accepted and is a different trust root thanapple.com. Two names that a person cannot tell apart are two identities, and only the second ever reaches this type. Homograph defence belongs where names are shown to people and where keys are fetched, not in a parser that sees ASCII.
A trailing dot is rejected rather than stripped, so the DNS root-anchored
example.com. is not a spelling of example.com; only the latter names
that identity. ASCII case is folded, per RFC 4343.
use agent_uri::TrustRoot;
// Convert before you get here.
assert!(TrustRoot::parse("münchen.de").is_err());
assert!(TrustRoot::parse("xn--mnchen-3ya.de").is_ok());
// Which means a name that was converted wrongly is accepted as written.
assert!(TrustRoot::parse("xn--zzzzzz").is_ok());
// And a trailing dot is a different string, so it is not a trust root.
assert!(TrustRoot::parse("example.com.").is_err());See Section 8.11 of the specification for the threat this leaves to the caller.
Implementations§
Source§impl TrustRoot
impl TrustRoot
Sourcepub fn parse(input: &str) -> Result<Self, TrustRootError>
pub fn parse(input: &str) -> Result<Self, TrustRootError>
Parses a trust root from a string.
§Errors
Returns TrustRootError if:
- The input is empty
- The input exceeds 128 characters
- The domain contains invalid characters or labels
- A host of exactly four dotted numeric labels has an IPv4 octet outside 0-255 or an octet with a leading zero; this shape is parsed as IPv4 and is never treated as a domain
- The port is invalid (not numeric or out of range)
Sourcepub fn is_localhost(&self) -> bool
pub fn is_localhost(&self) -> bool
Returns true if this is a localhost address.
Sourcepub fn with_port(&self, port: u16) -> Result<Self, TrustRootError>
pub fn with_port(&self, port: u16) -> Result<Self, TrustRootError>
Returns a new trust root with the given port.
§Errors
Returns TrustRootError if the resulting trust root would exceed
the maximum length.
§Examples
use agent_uri::TrustRoot;
let root = TrustRoot::parse("localhost").unwrap();
let with_port = root.with_port(8472).unwrap();
assert_eq!(with_port.port(), Some(8472));Sourcepub fn without_port(&self) -> Self
pub fn without_port(&self) -> Self
Returns a new trust root without a port.
§Examples
use agent_uri::TrustRoot;
let root = TrustRoot::parse("localhost:8472").unwrap();
let without_port = root.without_port();
assert!(without_port.port().is_none());Trait Implementations§
Source§impl<'de> Deserialize<'de> for TrustRoot
Available on crate feature serde only.
impl<'de> Deserialize<'de> for TrustRoot
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>,
impl Eq for TrustRoot
Source§impl Ord for TrustRoot
impl Ord for TrustRoot
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for TrustRoot
impl PartialOrd for TrustRoot
impl StructuralPartialEq for TrustRoot
Auto Trait Implementations§
impl Freeze for TrustRoot
impl RefUnwindSafe for TrustRoot
impl Send for TrustRoot
impl Sync for TrustRoot
impl Unpin for TrustRoot
impl UnsafeUnpin for TrustRoot
impl UnwindSafe for TrustRoot
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> PrefixFactory for T
impl<T> PrefixFactory for T
Source§fn create_prefix_sanitized(&self) -> TypeIdPrefix
fn create_prefix_sanitized(&self) -> TypeIdPrefix
TypeIdPrefix. Read moreSource§fn try_create_prefix(&self) -> Result<TypeIdPrefix, ValidationError>
fn try_create_prefix(&self) -> Result<TypeIdPrefix, ValidationError>
TypeIdPrefix from the input without modifying it. Read more