Skip to content

Commit

Permalink
fix: make all Policy attributes private
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Rosenkranz-Costa committed Feb 15, 2024
1 parent 51b487e commit bd6f4eb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
18 changes: 6 additions & 12 deletions src/abe_policy/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ impl TryFrom<HashMap<String, Vec<String>>> for Policy {
/// "FIN"
/// ]
/// }
/// ````
/// ```
fn try_from(value: HashMap<String, Vec<String>>) -> Result<Self, Self::Error> {
let mut policy = Policy::new();
let mut policy = Self::new();

for (axis, attributes) in &value {
// Split the axis into axis name and hierarchy flag
Expand All @@ -81,10 +81,7 @@ impl TryFrom<HashMap<String, Vec<String>>> 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)
Expand All @@ -104,8 +101,7 @@ impl TryFrom<HashMap<String, Vec<String>>> for Policy {
"+" => EncryptionHint::Hybridized,
x => {
return Err(Error::ConversionFailed(format!(
"unknown attribute spec {}",
x
"unknown attribute spec {x}"
)));
}
};
Expand Down Expand Up @@ -140,8 +136,7 @@ impl TryFrom<Policy> for HashMap<String, Vec<String>> {
type Error = Error;

fn try_from(policy: Policy) -> Result<Self, Self::Error> {
let mut result: HashMap<String, Vec<String>> =
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 {
Expand Down Expand Up @@ -206,8 +201,7 @@ mod tests {
.get("Security Level")
.unwrap()
.attributes()
.collect::<Vec<_>>()
.len(),
.count(),
3
);
assert_eq!(
Expand Down
8 changes: 4 additions & 4 deletions src/abe_policy/policy_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ pub struct PolicyV2 {

#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
pub struct PolicyV1AttributeParameters {
pub values: Vec<u32>,
pub encryption_hint: EncryptionHint,
values: Vec<u32>,
encryption_hint: EncryptionHint,
}

#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
pub struct OldPolicyAxisParameters {
pub attribute_names: Vec<String>,
pub is_hierarchical: bool,
attribute_names: Vec<String>,
is_hierarchical: bool,
}

#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
Expand Down
3 changes: 1 addition & 2 deletions src/abe_policy/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@ fn specification_conversion_round_trip() -> Result<(), Error> {
.get("Security Level")
.unwrap()
.attributes()
.collect::<Vec<_>>()
.len(),
.count(),
3
);
assert_eq!(
Expand Down
4 changes: 2 additions & 2 deletions src/core/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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()]),
];
Expand Down

0 comments on commit bd6f4eb

Please sign in to comment.