From bd6f4ebdd8708827d8be272d2c4f065907d63167 Mon Sep 17 00:00:00 2001 From: Hugo Rosenkranz-Costa Date: Thu, 15 Feb 2024 11:09:25 +0100 Subject: [PATCH] fix: make all Policy attributes private --- src/abe_policy/parser.rs | 18 ++++++------------ src/abe_policy/policy_versions.rs | 8 ++++---- src/abe_policy/tests.rs | 3 +-- src/core/primitives.rs | 4 ++-- 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/abe_policy/parser.rs b/src/abe_policy/parser.rs index 9825ac87..888cdc5c 100644 --- a/src/abe_policy/parser.rs +++ b/src/abe_policy/parser.rs @@ -69,9 +69,9 @@ impl TryFrom>> for Policy { /// "FIN" /// ] /// } - /// ```` + /// ``` fn try_from(value: HashMap>) -> Result { - let mut policy = Policy::new(); + let mut policy = Self::new(); for (axis, attributes) in &value { // Split the axis into axis name and hierarchy flag @@ -81,10 +81,7 @@ impl TryFrom>> for Policy { let hierarchical = match specs { "<" => true, x => { - return Err(Error::ConversionFailed(format!( - "unknown axis spec {}", - x - ))); + return Err(Error::ConversionFailed(format!("unknown axis spec {x}"))); } }; (name, hierarchical) @@ -104,8 +101,7 @@ impl TryFrom>> for Policy { "+" => EncryptionHint::Hybridized, x => { return Err(Error::ConversionFailed(format!( - "unknown attribute spec {}", - x + "unknown attribute spec {x}" ))); } }; @@ -140,8 +136,7 @@ impl TryFrom for HashMap> { type Error = Error; fn try_from(policy: Policy) -> Result { - let mut result: HashMap> = - HashMap::with_capacity(policy.dimensions.len()); + let mut result: Self = Self::with_capacity(policy.dimensions.len()); for (dim_name, dimension) in policy.dimensions { let (dim_full_name, attributes_list) = match dimension { @@ -206,8 +201,7 @@ mod tests { .get("Security Level") .unwrap() .attributes() - .collect::>() - .len(), + .count(), 3 ); assert_eq!( diff --git a/src/abe_policy/policy_versions.rs b/src/abe_policy/policy_versions.rs index 3c901cd1..bb0f30c0 100644 --- a/src/abe_policy/policy_versions.rs +++ b/src/abe_policy/policy_versions.rs @@ -24,14 +24,14 @@ pub struct PolicyV2 { #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] pub struct PolicyV1AttributeParameters { - pub values: Vec, - pub encryption_hint: EncryptionHint, + values: Vec, + encryption_hint: EncryptionHint, } #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] pub struct OldPolicyAxisParameters { - pub attribute_names: Vec, - pub is_hierarchical: bool, + attribute_names: Vec, + is_hierarchical: bool, } #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] diff --git a/src/abe_policy/tests.rs b/src/abe_policy/tests.rs index a91dd159..258d8ca4 100644 --- a/src/abe_policy/tests.rs +++ b/src/abe_policy/tests.rs @@ -206,8 +206,7 @@ fn specification_conversion_round_trip() -> Result<(), Error> { .get("Security Level") .unwrap() .attributes() - .collect::>() - .len(), + .count(), 3 ); assert_eq!( diff --git a/src/core/primitives.rs b/src/core/primitives.rs index e8b45ba5..6056c383 100644 --- a/src/core/primitives.rs +++ b/src/core/primitives.rs @@ -117,7 +117,7 @@ fn update_subkey_pair( let (sk_pq, sk_i) = msk; // update public subkey - *pk_i = h * &sk_i; + *pk_i = h * sk_i; // create or reuse Kyber keys if is_hybridized.into() { @@ -541,7 +541,7 @@ mod tests { ), ]); // user list - let users_set = vec![ + let users_set = [ HashSet::from([dev_partition.clone()]), HashSet::from([admin_partition.clone(), dev_partition.clone()]), ];