diff --git a/Cargo.toml b/Cargo.toml index 14dd9ce..c04584f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ untrusted = "0.9" [dev-dependencies] littlefs2 = "0.3.2" rand_core = { version = "0.6", features = ["getrandom"] } +trussed = { version = "0.1.0", features = ["virt"] } [features] default = [] diff --git a/tests/setup/mod.rs b/tests/setup/mod.rs index edea91c..2f081af 100644 --- a/tests/setup/mod.rs +++ b/tests/setup/mod.rs @@ -1,10 +1,3 @@ -trussed::platform!( - Platform, - R: rand_core::OsRng, //chacha20::ChaCha8Rng, - S: store::Store, - UI: ui::UserInterface, -); - const COMMAND_SIZE: usize = 3072; #[macro_export] @@ -14,83 +7,13 @@ macro_rules! cmd { }; } -pub type Piv<'service> = piv_authenticator::Authenticator< - trussed::ClientImplementation<&'service mut trussed::service::Service>, - COMMAND_SIZE, ->; +use trussed::virt::{Client, Ram}; + +pub type Piv<'service> = piv_authenticator::Authenticator, COMMAND_SIZE>; pub fn piv(test: impl FnOnce(&mut Piv) -> R) -> R { - use trussed::Interchange as _; - unsafe { - trussed::pipe::TrussedInterchange::reset_claims(); - } - let trussed_platform = init_platform(); - let mut trussed_service = trussed::service::Service::new(trussed_platform); - let client_id = "test"; - let trussed_client = trussed_service.try_as_new_client(client_id).unwrap(); - let mut piv_app = piv_authenticator::Authenticator::new(trussed_client); - test(&mut piv_app) -} - -pub fn init_platform() -> Platform { - let rng = rand_core::OsRng; - let store = store::Store::format( - store::InternalStorage::new(), - store::ExternalStorage::new(), - store::VolatileStorage::new(), - ); - let ui = ui::UserInterface::new(); - - - - Platform::new(rng, store, ui) -} - -pub mod ui { - use trussed::platform::{consent, reboot, ui}; - pub struct UserInterface { - start_time: std::time::Instant, - } - - impl UserInterface { - pub fn new() -> Self { - Self { - start_time: std::time::Instant::now(), - } - } - } - - impl trussed::platform::UserInterface for UserInterface { - fn check_user_presence(&mut self) -> consent::Level { - consent::Level::Normal - } - fn set_status(&mut self, _status: ui::Status) {} - fn refresh(&mut self) {} - fn uptime(&mut self) -> core::time::Duration { - self.start_time.elapsed() - } - fn reboot(&mut self, _to: reboot::To) -> ! { - loop { - continue; - } - } - } -} - -pub mod store { - use littlefs2::{ - const_ram_storage, - }; - use trussed::types::{LfsResult, LfsStorage}; - - const_ram_storage!(InternalStorage, 8192); - const_ram_storage!(ExternalStorage, 8192); - const_ram_storage!(VolatileStorage, 8192); - - trussed::store!( - Store, - Internal: InternalStorage, - External: ExternalStorage, - Volatile: VolatileStorage - ); + trussed::virt::with_ram_client("test", |client| { + let mut piv_app = piv_authenticator::Authenticator::new(client); + test(&mut piv_app) + }) }