mirror of
https://github.com/trussed-dev/trussed.git
synced 2026-06-09 06:07:49 +00:00
48 lines
1.0 KiB
Rust
48 lines
1.0 KiB
Rust
mod backends {
|
|
use trussed::backend::Backend;
|
|
|
|
#[derive(Default)]
|
|
pub struct ABackend;
|
|
|
|
impl Backend for ABackend {
|
|
type Context = ();
|
|
}
|
|
}
|
|
|
|
enum Backend {
|
|
A,
|
|
}
|
|
|
|
#[derive(Default, trussed_derive::Dispatch)]
|
|
#[dispatch(backend_id = "Backend")]
|
|
struct Dispatch {
|
|
a: backends::ABackend,
|
|
}
|
|
|
|
fn main() {
|
|
use trussed::{
|
|
backend::BackendId,
|
|
virt::{self, StoreConfig},
|
|
};
|
|
use trussed_core::{try_syscall, CryptoClient, Error};
|
|
|
|
fn run(backends: &'static [BackendId<Backend>], expected: Option<Error>) {
|
|
virt::with_platform(StoreConfig::ram(), |platform| {
|
|
platform.run_client_with_backends(
|
|
"test",
|
|
Dispatch::default(),
|
|
backends,
|
|
|mut client| {
|
|
assert_eq!(try_syscall!(client.random_bytes(42)).err(), expected);
|
|
},
|
|
)
|
|
});
|
|
}
|
|
|
|
run(&[BackendId::Core], None);
|
|
run(
|
|
&[BackendId::Custom(Backend::A)],
|
|
Some(Error::RequestNotAvailable),
|
|
);
|
|
}
|