pub struct SpiffeId { /* private fields */ }Expand description
A validated [SPIFFE ID].
This type guarantees that the contained trust domain and path conform to the SPIFFE ID specification: https://github.com/spiffe/spiffe/blob/main/standards/SPIFFE-ID.md#2-spiffe-identity.
Instances of SpiffeId are always valid and can be safely compared,
formatted, and reused across the API.
Implementations§
Source§impl SpiffeId
impl SpiffeId
Sourcepub fn new(id: impl AsRef<str>) -> Result<SpiffeId, SpiffeIdError>
pub fn new(id: impl AsRef<str>) -> Result<SpiffeId, SpiffeIdError>
Attempts to parse a SPIFFE ID from the given id string.
§Arguments
id- A SPIFFE ID, e.g.spiffe://trustdomain/path/other
§Errors
If the function cannot parse the input as a SPIFFE ID, a SpiffeIdError variant will be returned.
§Examples
use spiffe::SpiffeId;
let spiffe_id = SpiffeId::new("spiffe://trustdomain/path").unwrap();
assert_eq!("trustdomain", spiffe_id.trust_domain().to_string());
assert_eq!("/path", spiffe_id.path());Sourcepub fn from_segments(
trust_domain: TrustDomain,
segments: &[&str],
) -> Result<SpiffeId, SpiffeIdError>
pub fn from_segments( trust_domain: TrustDomain, segments: &[&str], ) -> Result<SpiffeId, SpiffeIdError>
Returns a new SPIFFE ID in the given trust domain with joined
path segments. The path segments must be valid according to the SPIFFE
specification and must not contain path separators.
See https://github.com/spiffe/spiffe/blob/main/standards/SPIFFE-ID.md#22-path
§Arguments
trust_domain- ATrustDomainobject.segments- A slice of path segments.
§Errors
If the segments contain not allowed characters, a SpiffeIdError variant will be returned.
§Examples
use spiffe::{SpiffeId, TrustDomain};
let trust_domain = TrustDomain::new("trustdomain").unwrap();
let spiffe_id = SpiffeId::from_segments(trust_domain, &["path1", "path2", "path3"]).unwrap();
assert_eq!(
"spiffe://trustdomain/path1/path2/path3",
spiffe_id.to_string()
);Sourcepub fn trust_domain(&self) -> &TrustDomain
pub fn trust_domain(&self) -> &TrustDomain
Returns the trust domain of the SPIFFE ID.
§Examples
use spiffe::{SpiffeId, TrustDomain};
let spiffe_id = SpiffeId::new("spiffe://example.org/service")?;
let trust_domain = spiffe_id.trust_domain();
assert_eq!(trust_domain.to_string(), "example.org");Sourcepub fn trust_domain_name(&self) -> &str
pub fn trust_domain_name(&self) -> &str
Returns the trust domain name of this SPIFFE ID.
This is equivalent to self.trust_domain().as_str() and does not
allocate. The returned string is guaranteed to be a valid SPIFFE
trust domain.
Sourcepub fn path(&self) -> &str
pub fn path(&self) -> &str
Returns the path of the SPIFFE ID.
§Examples
use spiffe::SpiffeId;
let spiffe_id = SpiffeId::new("spiffe://example.org/service/api")?;
assert_eq!(spiffe_id.path(), "/service/api");
let spiffe_id = SpiffeId::new("spiffe://example.org")?;
assert_eq!(spiffe_id.path(), "");Sourcepub fn is_member_of(&self, trust_domain: &TrustDomain) -> bool
pub fn is_member_of(&self, trust_domain: &TrustDomain) -> bool
Returns true if this SPIFFE ID has the given TrustDomain.
§Examples
use spiffe::{SpiffeId, TrustDomain};
let spiffe_id = SpiffeId::new("spiffe://example.org/service")?;
let trust_domain = TrustDomain::new("example.org")?;
assert!(spiffe_id.is_member_of(&trust_domain));
let other_domain = TrustDomain::new("other.org")?;
assert!(!spiffe_id.is_member_of(&other_domain));Trait Implementations§
Source§impl Ord for SpiffeId
impl Ord for SpiffeId
Source§impl PartialOrd for SpiffeId
impl PartialOrd for SpiffeId
impl Eq for SpiffeId
impl StructuralPartialEq for SpiffeId
Auto Trait Implementations§
impl Freeze for SpiffeId
impl RefUnwindSafe for SpiffeId
impl Send for SpiffeId
impl Sync for SpiffeId
impl Unpin for SpiffeId
impl UnwindSafe for SpiffeId
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request