pub struct X509Context { /* private fields */ }Expand description
Represents all X.509 materials fetched from the Workload API.
An X509Context contains the set of X.509 SVIDs issued to the workload
along with the corresponding trust bundles.
Implementations§
Source§impl X509Context
impl X509Context
Sourcepub fn new(
svids: impl IntoIterator<Item = Arc<X509Svid>>,
bundle_set: impl Into<Arc<X509BundleSet>>,
) -> Self
pub fn new( svids: impl IntoIterator<Item = Arc<X509Svid>>, bundle_set: impl Into<Arc<X509BundleSet>>, ) -> Self
Creates a new X509Context.
The provided SVIDs are collected and stored internally.
The bundle set is shared internally via Arc.
§Examples
use spiffe::{TrustDomain, X509Bundle, X509BundleSet, X509Context, X509Svid};
use std::sync::Arc;
// In practice, you would parse SVIDs from DER:
// let svid = X509Svid::parse_from_der(cert_chain_der, private_key_der)?;
let trust_domain = TrustDomain::new("example.org")?;
let bundle = X509Bundle::new(trust_domain.clone());
let bundle_set = X509BundleSet::new();
let svid = Arc::new(X509Svid::parse_from_der(&[], &[])?);
let context = X509Context::new([svid], bundle_set);Sourcepub fn default_svid(&self) -> Option<&Arc<X509Svid>>
pub fn default_svid(&self) -> Option<&Arc<X509Svid>>
Returns the default X509Svid, if present.
The default SVID is the first SVID returned by the Workload API.
§Examples
use spiffe::{X509Context, X509BundleSet, X509Svid};
use std::sync::Arc;
// In practice, you would get context from WorkloadApiClient:
// let context = client.fetch_x509_context().await?;
let svid = Arc::new(X509Svid::parse_from_der(&[], &[])?);
let context = X509Context::new([svid.clone()], X509BundleSet::new());
if let Some(default_svid) = context.default_svid() {
println!("Default SVID: {}", default_svid.spiffe_id());
}Sourcepub const fn svids(&self) -> &[Arc<X509Svid>]
pub const fn svids(&self) -> &[Arc<X509Svid>]
Returns all X.509 SVIDs in this context.
§Examples
use spiffe::{X509Context, X509BundleSet, X509Svid};
use std::sync::Arc;
// In practice, you would get context from WorkloadApiClient:
// let context = client.fetch_x509_context().await?;
let svid = Arc::new(X509Svid::parse_from_der(&[], &[])?);
let context = X509Context::new([svid.clone()], X509BundleSet::new());
for svid in context.svids() {
println!("SVID: {}", svid.spiffe_id());
if let Some(hint) = svid.hint() {
println!(" Hint: {}", hint);
}
}Sourcepub const fn bundle_set(&self) -> &Arc<X509BundleSet> ⓘ
pub const fn bundle_set(&self) -> &Arc<X509BundleSet> ⓘ
Returns the set of X.509 bundles associated with this context.
§Examples
use spiffe::{TrustDomain, X509Context, X509BundleSet, X509Svid};
use std::sync::Arc;
// In practice, you would get context from WorkloadApiClient:
// let context = client.fetch_x509_context().await?;
let svid = Arc::new(X509Svid::parse_from_der(&[], &[])?);
let context = X509Context::new([svid], X509BundleSet::new());
let bundle_set = context.bundle_set();
let trust_domain = TrustDomain::new("example.org")?;
if let Some(bundle) = bundle_set.get(&trust_domain) {
println!("Bundle has {} authorities", bundle.authorities().len());
}Trait Implementations§
Source§impl Clone for X509Context
impl Clone for X509Context
Source§impl Debug for X509Context
impl Debug for X509Context
impl Eq for X509Context
Source§impl PartialEq for X509Context
impl PartialEq for X509Context
impl StructuralPartialEq for X509Context
Auto Trait Implementations§
impl Freeze for X509Context
impl RefUnwindSafe for X509Context
impl Send for X509Context
impl Sync for X509Context
impl Unpin for X509Context
impl UnsafeUnpin for X509Context
impl UnwindSafe for X509Context
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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
Compare self to
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>
Wrap the input message
T in a tonic::Request