Skip to main content

BackendRegistry

Struct BackendRegistry 

Source
pub struct BackendRegistry { /* private fields */ }
Expand description

Backend registry that owns all backend lifecycle state.

Provides typed accessor methods for different backend traits. Backends are declared at startup (via declare) and initialized lazily on first use.

Note: This uses Box<dyn Backend> for storage to avoid circular dependencies between rite-runtime and rite-stdlib. Concrete backend implementations live in rite-stdlib.

Implementations§

Source§

impl BackendRegistry

Source

pub fn with_factory(factory: BackendFactory) -> Self

Create a new registry with a backend factory.

The factory is called the first time a declared backend is used.

§Example
use rite_runtime::BackendRegistry;
use rite_sdk::BackendError;

// A factory resolves a declared backend name + config into a live
// backend. This one has none, so every lookup reports NotFound.
let registry = BackendRegistry::with_factory(Box::new(|name, _config| {
    Err(BackendError::NotFound(name))
}));
Source

pub fn new() -> Self

Create an empty registry without a factory (for tests).

The factory always returns BackendError::NotFound. Use register to insert fully-initialized backends directly.

Source

pub fn declare(&mut self, name: String, config: BackendConfig)

Declare a backend from YAML configuration (lazy; no hardware touched).

Stores the config only. The backend is not initialized until first use.

If a backend with the same name already exists, it will be replaced.

Source

pub fn register(&mut self, backend: Box<dyn Backend>)

Register a fully-initialized backend directly (for tests).

If a backend with the same name already exists, it will be replaced.

Source

pub fn get(&self, name: &str) -> Option<&dyn Backend>

Get backend by name (immutable).

Only returns backends that are already in the Ready state. Does not trigger initialization. Primarily for testing.

Source

pub fn get_mut(&mut self, name: &str) -> Result<&mut dyn Backend, BackendError>

Get backend by name (mutable), initializing it lazily if needed.

Returns the backend on success, Err(NotFound) if the backend was never declared, or the factory’s error if initialization failed (in which case a later call probes the hardware again).

Source

pub fn get_keystore( &mut self, name: &str, ) -> Result<&mut dyn KeyStoreBackend, BackendError>

Get backend as KeyStoreBackend trait.

Source

pub fn get_sign( &mut self, name: &str, ) -> Result<&mut dyn SignBackend, BackendError>

Get backend as SignBackend trait.

Source

pub fn get_attest_mut( &mut self, name: &str, ) -> Result<&mut dyn AttestationBackend, BackendError>

Get backend as AttestationBackend trait (mutable).

Source

pub fn get_piv( &mut self, name: &str, ) -> Result<&mut dyn PivBackend, BackendError>

Get backend as PivBackend trait (mutable).

Source

pub fn get_yubikey( &mut self, name: &str, ) -> Result<&mut dyn YubikeyBackend, BackendError>

Get backend as YubikeyBackend trait (mutable).

Source

pub fn get_transport( &mut self, name: &str, ) -> Result<&mut dyn KeyTransportBackend, BackendError>

Get backend as KeyTransportBackend trait (mutable).

Source

pub fn get_certstore( &mut self, name: &str, ) -> Result<&mut dyn CertStoreBackend, BackendError>

Get backend as CertStoreBackend trait (mutable).

Source

pub fn get_random( &mut self, name: &str, ) -> Result<&mut dyn RandomBackend, BackendError>

Get backend as RandomBackend trait (mutable).

Source

pub fn get_pkcs11( &mut self, name: &str, ) -> Result<&mut dyn Pkcs11Backend, BackendError>

Get backend as Pkcs11Backend trait (mutable).

Source

pub fn get_pkcs11_admin( &mut self, name: &str, ) -> Result<&mut dyn Pkcs11AdminBackend, BackendError>

Get backend as Pkcs11AdminBackend trait (mutable).

Source

pub fn get_tpm( &mut self, name: &str, ) -> Result<&mut dyn TpmBackend, BackendError>

Get backend as TpmBackend trait (mutable).

Source

pub fn backend_names(&self) -> impl Iterator<Item = &String>

List all registered backend names.

Trait Implementations§

Source§

impl Default for BackendRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.