Add write to the environment

This commit is contained in:
Julien Cretin
2022-03-04 15:09:44 +01:00
parent dcc053c6cb
commit f09e5a77e8
6 changed files with 152 additions and 88 deletions

15
src/env/test/mod.rs vendored
View File

@@ -17,6 +17,14 @@ pub struct TestUserPresence {
check: Box<dyn Fn(ChannelID) -> Result<(), Ctap2StatusCode>>,
}
pub struct TestWrite;
impl core::fmt::Write for TestWrite {
fn write_str(&mut self, _: &str) -> core::fmt::Result {
Ok(())
}
}
impl TestEnv {
pub fn new() -> Self {
let rng = ThreadRng256 {};
@@ -34,7 +42,7 @@ impl TestUserPresence {
}
impl UserPresence for TestUserPresence {
fn check(&self, cid: ChannelID) -> Result<(), Ctap2StatusCode> {
fn check(&mut self, cid: ChannelID) -> Result<(), Ctap2StatusCode> {
(self.check)(cid)
}
}
@@ -51,6 +59,7 @@ impl Env for TestEnv {
type Storage = BufferStorage;
type UpgradeStorage = BufferUpgradeStorage;
type FirmwareProtection = Self;
type Write = TestWrite;
fn rng(&mut self) -> &mut Self::Rng {
&mut self.rng
@@ -82,4 +91,8 @@ impl Env for TestEnv {
fn firmware_protection(&mut self) -> &mut Self::FirmwareProtection {
self
}
fn write(&mut self) -> Self::Write {
TestWrite
}
}