spiffe/workload_api/
x509_context.rs

1//! Defines a type that holds all the X.509 materials for a workload (i.e. X.509 SVIDs and bundles)
2
3use crate::constants::DEFAULT_SVID;
4use crate::{X509BundleSet, X509Svid};
5
6/// Represents all X.509 materials fetched from the Workload API.
7#[derive(Debug, Clone, Eq, PartialEq)]
8pub struct X509Context {
9    svids: Vec<X509Svid>,
10    bundle_set: X509BundleSet,
11}
12
13impl X509Context {
14    /// Creates a new [`X509Context`].
15    pub fn new(svids: Vec<X509Svid>, bundle_set: X509BundleSet) -> Self {
16        Self { svids, bundle_set }
17    }
18
19    /// Returns the default [`X509Svid`], i.e. the first in the list.
20    pub fn default_svid(&self) -> Option<&X509Svid> {
21        self.svids.get(DEFAULT_SVID)
22    }
23
24    /// Returns the list of [`X509Svid`] in the context.
25    pub fn svids(&self) -> &Vec<X509Svid> {
26        &self.svids
27    }
28
29    /// Returns the [`X509BundleSet`] in the context.
30    pub fn bundle_set(&self) -> &X509BundleSet {
31        &self.bundle_set
32    }
33}