Return Vec<String> for rp_ids()
This commit is contained in:
60
src/env/test/customization.rs
vendored
60
src/env/test/customization.rs
vendored
@@ -1,13 +1,12 @@
|
||||
use std::slice::from_raw_parts;
|
||||
|
||||
use crate::api::customization::{Customization, CustomizationImpl};
|
||||
use crate::ctap::data_formats::CredentialProtectionPolicy;
|
||||
use alloc::string::String;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
pub struct TestCustomization {
|
||||
pub default_cred_protect: Option<CredentialProtectionPolicy>,
|
||||
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_min_pin_length_rp_ids: Vec<String>,
|
||||
pub enforce_always_uv: bool,
|
||||
pub max_msg_size: usize,
|
||||
pub max_pin_retries: u8,
|
||||
@@ -15,17 +14,6 @@ pub struct TestCustomization {
|
||||
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
|
||||
@@ -35,10 +23,8 @@ impl Customization for TestCustomization {
|
||||
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 default_min_pin_length_rp_ids(&self) -> Vec<String> {
|
||||
self.default_min_pin_length_rp_ids.clone()
|
||||
}
|
||||
|
||||
fn enforce_always_uv(&self) -> bool {
|
||||
@@ -75,30 +61,21 @@ impl From<CustomizationImpl> for TestCustomization {
|
||||
max_rp_ids_length,
|
||||
} = c;
|
||||
|
||||
let default_min_pin_length_rp_ids_backing_store = default_min_pin_length_rp_ids
|
||||
let default_min_pin_length_rp_ids = default_min_pin_length_rp_ids
|
||||
.iter()
|
||||
.map(|s| (*s).to_owned())
|
||||
.map(|s| String::from(*s))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let mut ret = Self {
|
||||
Self {
|
||||
default_cred_protect,
|
||||
default_min_pin_length,
|
||||
default_min_pin_length_rp_ids_backing_store,
|
||||
default_min_pin_length_rp_ids: vec![],
|
||||
default_min_pin_length_rp_ids,
|
||||
enforce_always_uv,
|
||||
max_msg_size,
|
||||
max_pin_retries,
|
||||
use_signature_counter,
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,21 +89,4 @@ mod test {
|
||||
let customization = TestCustomization::from(DEFAULT_CUSTOMIZATION.clone());
|
||||
assert!(is_valid(&customization));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_vec_storage_impl() {
|
||||
let mut customization = TestCustomization::from(DEFAULT_CUSTOMIZATION.clone());
|
||||
assert!(customization.default_min_pin_length_rp_ids().is_empty());
|
||||
customization
|
||||
.set_default_min_pin_length_rp_ids(vec!["abc.com".to_owned(), "def.com".to_owned()]);
|
||||
assert_eq!(
|
||||
customization.default_min_pin_length_rp_ids(),
|
||||
["abc.com", "def.com"]
|
||||
);
|
||||
customization.set_default_min_pin_length_rp_ids(vec!["example.com".to_owned()]);
|
||||
assert_eq!(
|
||||
customization.default_min_pin_length_rp_ids(),
|
||||
["example.com"]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user