use core::fmt::Debug;
use trussed_core::try_syscall;
use crate::error::Error;
#[derive(Clone)]
pub struct Backend<T: crate::card::Client> {
client: T,
}
impl<T: crate::card::Client> Debug for Backend<T> {
fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let Self { client: _client } = self;
fmt.debug_struct("Backend").finish()
}
}
impl<T: crate::card::Client> Backend<T> {
pub fn new(client: T) -> Self {
Self { client }
}
pub fn client_mut(&mut self) -> &mut T {
&mut self.client
}
pub fn confirm_user_present(&mut self) -> Result<bool, Error> {
try_syscall!(self.client_mut().confirm_user_present(15_000))
.map_err(|_err| {
error!("Failed to confirm user presence {_err:?}");
Error::UserInteraction
})
.map(|r| r.result.is_ok())
}
}