introduces Transport and Channel (#444)

This commit is contained in:
kaczmarczyck
2022-03-14 18:40:24 +01:00
committed by GitHub
parent 1372fd0b1a
commit ba0c583617
8 changed files with 141 additions and 101 deletions

4
src/env/mod.rs vendored
View File

@@ -1,7 +1,7 @@
use crate::api::firmware_protection::FirmwareProtection;
use crate::api::upgrade_storage::UpgradeStorage;
use crate::ctap::hid::ChannelID;
use crate::ctap::status_code::Ctap2StatusCode;
use crate::ctap::Channel;
use crypto::rng256::Rng256;
use persistent_store::{Storage, Store};
@@ -13,7 +13,7 @@ pub trait UserPresence {
/// Blocks for user presence.
///
/// Returns an error in case of timeout or keepalive error.
fn check(&mut self, cid: ChannelID) -> Result<(), Ctap2StatusCode>;
fn check(&mut self, channel: Channel) -> Result<(), Ctap2StatusCode>;
}
/// Describes what CTAP needs to function.

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

@@ -1,7 +1,7 @@
use self::upgrade_storage::BufferUpgradeStorage;
use crate::api::firmware_protection::FirmwareProtection;
use crate::ctap::hid::ChannelID;
use crate::ctap::status_code::Ctap2StatusCode;
use crate::ctap::Channel;
use crate::env::{Env, UserPresence};
use crypto::rng256::ThreadRng256;
use persistent_store::{BufferOptions, BufferStorage, Store};
@@ -16,7 +16,7 @@ pub struct TestEnv {
}
pub struct TestUserPresence {
check: Box<dyn Fn(ChannelID) -> Result<(), Ctap2StatusCode>>,
check: Box<dyn Fn(Channel) -> Result<(), Ctap2StatusCode>>,
}
pub struct TestWrite;
@@ -65,14 +65,14 @@ impl TestEnv {
}
impl TestUserPresence {
pub fn set(&mut self, check: impl Fn(ChannelID) -> Result<(), Ctap2StatusCode> + 'static) {
pub fn set(&mut self, check: impl Fn(Channel) -> Result<(), Ctap2StatusCode> + 'static) {
self.check = Box::new(check);
}
}
impl UserPresence for TestUserPresence {
fn check(&mut self, cid: ChannelID) -> Result<(), Ctap2StatusCode> {
(self.check)(cid)
fn check(&mut self, channel: Channel) -> Result<(), Ctap2StatusCode> {
(self.check)(channel)
}
}

8
src/env/tock/mod.rs vendored
View File

@@ -2,6 +2,7 @@ pub use self::storage::{TockStorage, TockUpgradeStorage};
use crate::api::firmware_protection::FirmwareProtection;
use crate::ctap::hid::{ChannelID, CtapHid, CtapHidCommand, KeepaliveStatus, ProcessedPacket};
use crate::ctap::status_code::Ctap2StatusCode;
use crate::ctap::Channel;
use crate::env::{Env, UserPresence};
use core::cell::Cell;
use core::sync::atomic::{AtomicBool, Ordering};
@@ -54,8 +55,11 @@ pub fn take_storage() -> StorageResult<TockStorage> {
}
impl UserPresence for TockEnv {
fn check(&mut self, cid: ChannelID) -> Result<(), Ctap2StatusCode> {
check_user_presence(self, cid)
fn check(&mut self, channel: Channel) -> Result<(), Ctap2StatusCode> {
match channel {
Channel::MainHid(cid) => check_user_presence(self, cid),
Channel::VendorHid(cid) => check_user_presence(self, cid),
}
}
}