macro_rules! backend_capabilities {
($($(#[$attr:meta])* $method:ident : $trait:ident),* $(,)?) => { ... };
}Expand description
Implement the as_*_mut upcasting helpers on a backend struct.
Each Backend implementor must return Some(self) for every trait it
supports and None for those it does not. Without this macro that is four
lines of boilerplate per capability. The macro expands to those lines
automatically and allows attaching per-capability doc comments.
§Usage
use rite_sdk::{
backend_capabilities, Backend, BackendError, KeyId, RandomBackend, SignAlgorithm,
SignBackend,
};
struct MyBackend {
name: String,
}
impl Backend for MyBackend {
fn name(&self) -> &str { &self.name }
fn provider(&self) -> &str { "software" }
fn fingerprint(&self) -> String { "sha256:...".to_string() }
backend_capabilities!(
/// Signs with software-held RSA and ECDSA keys.
as_sign_mut: SignBackend,
/// Draws ceremony randomness from the OS CSPRNG.
as_random_mut: RandomBackend,
);
}
impl SignBackend for MyBackend {
fn sign(&mut self, _key: &KeyId, _msg: &[u8], _alg: SignAlgorithm)
-> Result<Vec<u8>, BackendError> { Ok(Vec::new()) }
}
impl RandomBackend for MyBackend {
fn generate_random(&mut self, len: usize) -> Result<Vec<u8>, BackendError> {
Ok(vec![0u8; len])
}
}Capabilities not listed here are not overridden, so they inherit the trait’s
default doc (“Not supported by this backend.”) and return None.
The trait names passed to the macro must be in scope at the call site.
Note: #[macro_export] places this macro at the crate root
(rite_sdk::backend_capabilities!), not in the backend module.
This is standard Rust macro scoping.