Move three dependent customizations into new file
* default_min_pin_length(_rp_ids) and max_rp_ids_length * Did some backing store tricks to make the list configurable in TestCustomization.
This commit is contained in:
82
src/env/test/customization.rs
vendored
Normal file
82
src/env/test/customization.rs
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
use std::slice::from_raw_parts;
|
||||
|
||||
use crate::api::customization::{Customization, CustomizationImpl};
|
||||
use crate::ctap::data_formats::CredentialProtectionPolicy;
|
||||
|
||||
pub struct TestCustomization {
|
||||
pub default_min_pin_length: u8,
|
||||
default_min_pin_length_rp_ids_backing_store: Vec<String>,
|
||||
default_min_pin_length_rp_ids: Vec<*const str>,
|
||||
pub default_cred_protect: Option<CredentialProtectionPolicy>,
|
||||
pub max_msg_size: usize,
|
||||
pub max_rp_ids_length: usize,
|
||||
}
|
||||
|
||||
impl TestCustomization {
|
||||
pub fn set_default_min_pin_length_rp_ids(&mut self, rp_ids: Vec<String>) {
|
||||
self.default_min_pin_length_rp_ids_backing_store = rp_ids;
|
||||
self.default_min_pin_length_rp_ids = self
|
||||
.default_min_pin_length_rp_ids_backing_store
|
||||
.iter()
|
||||
.map(|s| s.as_ref() as *const str)
|
||||
.collect::<Vec<_>>();
|
||||
}
|
||||
}
|
||||
|
||||
impl Customization for TestCustomization {
|
||||
fn default_cred_protect(&self) -> Option<CredentialProtectionPolicy> {
|
||||
self.default_cred_protect
|
||||
}
|
||||
|
||||
fn default_min_pin_length(&self) -> u8 {
|
||||
self.default_min_pin_length
|
||||
}
|
||||
|
||||
fn default_min_pin_length_rp_ids(&self) -> &[&str] {
|
||||
let length = self.default_min_pin_length_rp_ids.len();
|
||||
let rp_ids = self.default_min_pin_length_rp_ids.as_ptr() as *const &str;
|
||||
unsafe { from_raw_parts(rp_ids, length) }
|
||||
}
|
||||
|
||||
fn max_msg_size(&self) -> usize {
|
||||
self.max_msg_size
|
||||
}
|
||||
|
||||
fn max_rp_ids_length(&self) -> usize {
|
||||
self.max_rp_ids_length
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CustomizationImpl> for TestCustomization {
|
||||
fn from(c: CustomizationImpl) -> Self {
|
||||
let CustomizationImpl {
|
||||
default_min_pin_length,
|
||||
default_min_pin_length_rp_ids,
|
||||
default_cred_protect,
|
||||
max_msg_size,
|
||||
max_rp_ids_length,
|
||||
} = c;
|
||||
|
||||
let default_min_pin_length_rp_ids_backing_store = default_min_pin_length_rp_ids
|
||||
.iter()
|
||||
.map(|s| (*s).to_owned())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let mut ret = Self {
|
||||
default_min_pin_length,
|
||||
default_min_pin_length_rp_ids_backing_store,
|
||||
default_min_pin_length_rp_ids: vec![],
|
||||
default_cred_protect,
|
||||
max_msg_size,
|
||||
max_rp_ids_length,
|
||||
};
|
||||
|
||||
ret.default_min_pin_length_rp_ids = ret
|
||||
.default_min_pin_length_rp_ids_backing_store
|
||||
.iter()
|
||||
.map(|s| s.as_ref() as *const str)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
ret
|
||||
}
|
||||
}
|
||||
12
src/env/test/mod.rs
vendored
12
src/env/test/mod.rs
vendored
@@ -1,12 +1,14 @@
|
||||
use self::upgrade_storage::BufferUpgradeStorage;
|
||||
use crate::api::customization::{CustomizationImpl, DEFAULT_CUSTOMIZATION};
|
||||
use crate::api::customization::DEFAULT_CUSTOMIZATION;
|
||||
use crate::api::firmware_protection::FirmwareProtection;
|
||||
use crate::ctap::status_code::Ctap2StatusCode;
|
||||
use crate::ctap::Channel;
|
||||
use crate::env::{Env, UserPresence};
|
||||
use crypto::rng256::ThreadRng256;
|
||||
use customization::TestCustomization;
|
||||
use persistent_store::{BufferOptions, BufferStorage, Store};
|
||||
|
||||
mod customization;
|
||||
mod upgrade_storage;
|
||||
|
||||
pub struct TestEnv {
|
||||
@@ -14,7 +16,7 @@ pub struct TestEnv {
|
||||
user_presence: TestUserPresence,
|
||||
store: Store<BufferStorage>,
|
||||
upgrade_storage: Option<BufferUpgradeStorage>,
|
||||
customization: CustomizationImpl,
|
||||
customization: TestCustomization,
|
||||
}
|
||||
|
||||
pub struct TestUserPresence {
|
||||
@@ -53,7 +55,7 @@ impl TestEnv {
|
||||
let storage = new_storage();
|
||||
let store = Store::new(storage).ok().unwrap();
|
||||
let upgrade_storage = Some(BufferUpgradeStorage::new().unwrap());
|
||||
let customization = DEFAULT_CUSTOMIZATION.clone();
|
||||
let customization = DEFAULT_CUSTOMIZATION.into();
|
||||
TestEnv {
|
||||
rng,
|
||||
user_presence,
|
||||
@@ -67,7 +69,7 @@ impl TestEnv {
|
||||
self.upgrade_storage = None;
|
||||
}
|
||||
|
||||
pub fn customization_mut(&mut self) -> &mut CustomizationImpl {
|
||||
pub fn customization_mut(&mut self) -> &mut TestCustomization {
|
||||
&mut self.customization
|
||||
}
|
||||
}
|
||||
@@ -97,7 +99,7 @@ impl Env for TestEnv {
|
||||
type UpgradeStorage = BufferUpgradeStorage;
|
||||
type FirmwareProtection = Self;
|
||||
type Write = TestWrite;
|
||||
type Customization = CustomizationImpl;
|
||||
type Customization = TestCustomization;
|
||||
|
||||
fn rng(&mut self) -> &mut Self::Rng {
|
||||
&mut self.rng
|
||||
|
||||
Reference in New Issue
Block a user