use rand_core::{CryptoRng, RngCore};
use trussed_core::types::{consent, reboot};
use crate::store::Store;
use crate::types::ui;
pub trait UserInterface {
fn check_user_presence(&mut self) -> consent::Level {
consent::Level::None
}
fn set_status(&mut self, status: ui::Status) {
let _ = status;
}
fn status(&self) -> ui::Status {
ui::Status::Idle
}
fn refresh(&mut self) {}
fn uptime(&mut self) -> core::time::Duration {
Default::default()
}
fn reboot(&mut self, to: reboot::To) -> ! {
let _ = to;
loop {
continue;
}
}
fn wink(&mut self, duration: core::time::Duration) {
let _ = duration;
}
}
pub trait Platform {
type R: CryptoRng + RngCore;
type S: Store;
type UI: UserInterface;
fn rng(&mut self) -> &mut Self::R;
fn store(&self) -> Self::S;
fn user_interface(&mut self) -> &mut Self::UI;
}
#[macro_export]
macro_rules! platform {
(
$PlatformName:ident,
R: $Rng:ty,
S: $Store:ty,
UI: $UserInterface:ty,
) => {
pub struct $PlatformName {
rng: $Rng,
store: $Store,
user_interface: $UserInterface,
}
impl $PlatformName {
pub fn new(rng: $Rng, store: $Store, user_interface: $UserInterface) -> Self {
Self {
rng,
store,
user_interface,
}
}
}
impl $crate::platform::Platform for $PlatformName {
type R = $Rng;
type S = $Store;
type UI = $UserInterface;
fn user_interface(&mut self) -> &mut Self::UI {
&mut self.user_interface
}
fn rng(&mut self) -> &mut Self::R {
&mut self.rng
}
fn store(&self) -> Self::S {
self.store
}
}
};
}
pub trait Syscall {
fn syscall(&mut self);
}