Return Vec<String> for rp_ids()
This commit is contained in:
@@ -18,6 +18,8 @@
|
|||||||
//! Our deploy script enforces the invariants.
|
//! Our deploy script enforces the invariants.
|
||||||
|
|
||||||
use crate::ctap::data_formats::CredentialProtectionPolicy;
|
use crate::ctap::data_formats::CredentialProtectionPolicy;
|
||||||
|
use alloc::string::String;
|
||||||
|
use alloc::vec::Vec;
|
||||||
|
|
||||||
pub trait Customization {
|
pub trait Customization {
|
||||||
// ###########################################################################
|
// ###########################################################################
|
||||||
@@ -66,7 +68,7 @@ pub trait Customization {
|
|||||||
///
|
///
|
||||||
/// Only the RP IDs listed in default_min_pin_length_rp_ids are allowed to read
|
/// Only the RP IDs listed in default_min_pin_length_rp_ids are allowed to read
|
||||||
/// the minimum PIN length with the minPinLength extension.
|
/// the minimum PIN length with the minPinLength extension.
|
||||||
fn default_min_pin_length_rp_ids(&self) -> &[&str];
|
fn default_min_pin_length_rp_ids(&self) -> Vec<String>;
|
||||||
|
|
||||||
/// Enforces the alwaysUv option.
|
/// Enforces the alwaysUv option.
|
||||||
///
|
///
|
||||||
@@ -164,8 +166,11 @@ impl Customization for CustomizationImpl {
|
|||||||
self.default_min_pin_length
|
self.default_min_pin_length
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_min_pin_length_rp_ids(&self) -> &[&str] {
|
fn default_min_pin_length_rp_ids(&self) -> Vec<String> {
|
||||||
self.default_min_pin_length_rp_ids
|
self.default_min_pin_length_rp_ids
|
||||||
|
.iter()
|
||||||
|
.map(|s| String::from(*s))
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enforce_always_uv(&self) -> bool {
|
fn enforce_always_uv(&self) -> bool {
|
||||||
@@ -221,7 +226,6 @@ mod test {
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[allow(clippy::assertions_on_constants)]
|
|
||||||
fn test_invariants() {
|
fn test_invariants() {
|
||||||
assert!(is_valid(&DEFAULT_CUSTOMIZATION));
|
assert!(is_valid(&DEFAULT_CUSTOMIZATION));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -397,15 +397,7 @@ pub fn set_min_pin_length(env: &mut impl Env, min_pin_length: u8) -> Result<(),
|
|||||||
/// allowed.
|
/// allowed.
|
||||||
pub fn min_pin_length_rp_ids(env: &mut impl Env) -> Result<Vec<String>, Ctap2StatusCode> {
|
pub fn min_pin_length_rp_ids(env: &mut impl Env) -> Result<Vec<String>, Ctap2StatusCode> {
|
||||||
let rp_ids = env.store().find(key::MIN_PIN_LENGTH_RP_IDS)?.map_or_else(
|
let rp_ids = env.store().find(key::MIN_PIN_LENGTH_RP_IDS)?.map_or_else(
|
||||||
|| {
|
|| Some(env.customization().default_min_pin_length_rp_ids()),
|
||||||
Some(
|
|
||||||
env.customization()
|
|
||||||
.default_min_pin_length_rp_ids()
|
|
||||||
.iter()
|
|
||||||
.map(|&s| String::from(s))
|
|
||||||
.collect(),
|
|
||||||
)
|
|
||||||
},
|
|
||||||
|value| deserialize_min_pin_length_rp_ids(&value),
|
|value| deserialize_min_pin_length_rp_ids(&value),
|
||||||
);
|
);
|
||||||
debug_assert!(rp_ids.is_some());
|
debug_assert!(rp_ids.is_some());
|
||||||
@@ -418,8 +410,7 @@ pub fn set_min_pin_length_rp_ids(
|
|||||||
min_pin_length_rp_ids: Vec<String>,
|
min_pin_length_rp_ids: Vec<String>,
|
||||||
) -> Result<(), Ctap2StatusCode> {
|
) -> Result<(), Ctap2StatusCode> {
|
||||||
let mut min_pin_length_rp_ids = min_pin_length_rp_ids;
|
let mut min_pin_length_rp_ids = min_pin_length_rp_ids;
|
||||||
for &rp_id in env.customization().default_min_pin_length_rp_ids().iter() {
|
for rp_id in env.customization().default_min_pin_length_rp_ids() {
|
||||||
let rp_id = String::from(rp_id);
|
|
||||||
if !min_pin_length_rp_ids.contains(&rp_id) {
|
if !min_pin_length_rp_ids.contains(&rp_id) {
|
||||||
min_pin_length_rp_ids.push(rp_id);
|
min_pin_length_rp_ids.push(rp_id);
|
||||||
}
|
}
|
||||||
@@ -1140,8 +1131,7 @@ mod test {
|
|||||||
// Changes by the setter are reflected by the getter.
|
// Changes by the setter are reflected by the getter.
|
||||||
let mut rp_ids = vec![String::from("example.com")];
|
let mut rp_ids = vec![String::from("example.com")];
|
||||||
assert_eq!(set_min_pin_length_rp_ids(&mut env, rp_ids.clone()), Ok(()));
|
assert_eq!(set_min_pin_length_rp_ids(&mut env, rp_ids.clone()), Ok(()));
|
||||||
for &rp_id in env.customization().default_min_pin_length_rp_ids().iter() {
|
for rp_id in env.customization().default_min_pin_length_rp_ids() {
|
||||||
let rp_id = String::from(rp_id);
|
|
||||||
if !rp_ids.contains(&rp_id) {
|
if !rp_ids.contains(&rp_id) {
|
||||||
rp_ids.push(rp_id);
|
rp_ids.push(rp_id);
|
||||||
}
|
}
|
||||||
|
|||||||
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::api::customization::{Customization, CustomizationImpl};
|
||||||
use crate::ctap::data_formats::CredentialProtectionPolicy;
|
use crate::ctap::data_formats::CredentialProtectionPolicy;
|
||||||
|
use alloc::string::String;
|
||||||
|
use alloc::vec::Vec;
|
||||||
|
|
||||||
pub struct TestCustomization {
|
pub struct TestCustomization {
|
||||||
pub default_cred_protect: Option<CredentialProtectionPolicy>,
|
pub default_cred_protect: Option<CredentialProtectionPolicy>,
|
||||||
pub default_min_pin_length: u8,
|
pub default_min_pin_length: u8,
|
||||||
default_min_pin_length_rp_ids_backing_store: Vec<String>,
|
pub default_min_pin_length_rp_ids: Vec<String>,
|
||||||
default_min_pin_length_rp_ids: Vec<*const str>,
|
|
||||||
pub enforce_always_uv: bool,
|
pub enforce_always_uv: bool,
|
||||||
pub max_msg_size: usize,
|
pub max_msg_size: usize,
|
||||||
pub max_pin_retries: u8,
|
pub max_pin_retries: u8,
|
||||||
@@ -15,17 +14,6 @@ pub struct TestCustomization {
|
|||||||
pub max_rp_ids_length: 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 {
|
impl Customization for TestCustomization {
|
||||||
fn default_cred_protect(&self) -> Option<CredentialProtectionPolicy> {
|
fn default_cred_protect(&self) -> Option<CredentialProtectionPolicy> {
|
||||||
self.default_cred_protect
|
self.default_cred_protect
|
||||||
@@ -35,10 +23,8 @@ impl Customization for TestCustomization {
|
|||||||
self.default_min_pin_length
|
self.default_min_pin_length
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_min_pin_length_rp_ids(&self) -> &[&str] {
|
fn default_min_pin_length_rp_ids(&self) -> Vec<String> {
|
||||||
let length = self.default_min_pin_length_rp_ids.len();
|
self.default_min_pin_length_rp_ids.clone()
|
||||||
let rp_ids = self.default_min_pin_length_rp_ids.as_ptr() as *const &str;
|
|
||||||
unsafe { from_raw_parts(rp_ids, length) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enforce_always_uv(&self) -> bool {
|
fn enforce_always_uv(&self) -> bool {
|
||||||
@@ -75,30 +61,21 @@ impl From<CustomizationImpl> for TestCustomization {
|
|||||||
max_rp_ids_length,
|
max_rp_ids_length,
|
||||||
} = c;
|
} = 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()
|
.iter()
|
||||||
.map(|s| (*s).to_owned())
|
.map(|s| String::from(*s))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let mut ret = Self {
|
Self {
|
||||||
default_cred_protect,
|
default_cred_protect,
|
||||||
default_min_pin_length,
|
default_min_pin_length,
|
||||||
default_min_pin_length_rp_ids_backing_store,
|
default_min_pin_length_rp_ids,
|
||||||
default_min_pin_length_rp_ids: vec![],
|
|
||||||
enforce_always_uv,
|
enforce_always_uv,
|
||||||
max_msg_size,
|
max_msg_size,
|
||||||
max_pin_retries,
|
max_pin_retries,
|
||||||
use_signature_counter,
|
use_signature_counter,
|
||||||
max_rp_ids_length,
|
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());
|
let customization = TestCustomization::from(DEFAULT_CUSTOMIZATION.clone());
|
||||||
assert!(is_valid(&customization));
|
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