Skip to content

Commit

Permalink
Merge pull request #123 from Cosmian/fix/access_policy
Browse files Browse the repository at this point in the history
fix: access policy parsing
  • Loading branch information
tbrezot authored Jan 19, 2024
2 parents a476bc5 + aa153dd commit f37d53f
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 394 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
/*.sh
/.vscode
Cargo.lock
**/.#*
**/#*#
38 changes: 16 additions & 22 deletions benches/benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn policy() -> Result<Policy, Error> {
DimensionBuilder::new(
"Department",
vec![
("R&D", EncryptionHint::Classic),
("RD", EncryptionHint::Classic),
("HR", EncryptionHint::Classic),
("MKG", EncryptionHint::Classic),
("FIN", EncryptionHint::Classic),
Expand All @@ -46,7 +46,7 @@ fn policy() -> Result<Policy, Error> {
DimensionBuilder::new(
"Department",
vec![
("R&D", EncryptionHint::Hybridized),
("RD", EncryptionHint::Hybridized),
("HR", EncryptionHint::Hybridized),
("MKG", EncryptionHint::Hybridized),
("FIN", EncryptionHint::Hybridized),
Expand Down Expand Up @@ -118,16 +118,13 @@ fn get_access_policies() -> (Vec<AccessPolicy>, Vec<AccessPolicy>) {
// Access policy with 1 partition
#[allow(unused_mut)]
let mut access_policies =
vec![
AccessPolicy::from_boolean_expression("Department::FIN && Security Level::Protected")
.unwrap(),
];
vec![AccessPolicy::parse("Department::FIN && Security Level::Protected").unwrap()];

#[cfg(feature = "full_bench")]
{
// Access policy with 2 partition
access_policies.push(
AccessPolicy::from_boolean_expression(
AccessPolicy::parse(
"(Department::FIN && Security Level::Protected) || (Department::HR && Security \
Level::Confidential)",
)
Expand All @@ -136,7 +133,7 @@ fn get_access_policies() -> (Vec<AccessPolicy>, Vec<AccessPolicy>) {

// Access policy with 3 partition
access_policies.push(
AccessPolicy::from_boolean_expression(
AccessPolicy::parse(
"(Department::FIN && Security Level::Protected) || ((Department::HR || \
Department::MKG) && Security Level::Confidential)",
)
Expand All @@ -145,18 +142,18 @@ fn get_access_policies() -> (Vec<AccessPolicy>, Vec<AccessPolicy>) {

// Access policy with 4 partition
access_policies.push(
AccessPolicy::from_boolean_expression(
AccessPolicy::parse(
"(Department::FIN && Security Level::Protected) || ((Department::HR || \
Department::MKG || Department::R&D) && Security Level::Confidential)",
Department::MKG || Department::RD) && Security Level::Confidential)",
)
.unwrap(),
);

// Access policy with 5 partition
access_policies.push(
AccessPolicy::from_boolean_expression(
AccessPolicy::parse(
"(Department::FIN && Security Level::Protected) || ((Department::HR || \
Department::MKG || Department::R&D) && Security Level::Confidential) || \
Department::MKG || Department::RD) && Security Level::Confidential) || \
(Department::HR && Security Level::Top Secret)",
)
.unwrap(),
Expand All @@ -167,36 +164,33 @@ fn get_access_policies() -> (Vec<AccessPolicy>, Vec<AccessPolicy>) {
// policies is always "Department::FIN && Security Level::Protected" only.
#[allow(unused_mut)]
let mut user_access_policies =
vec![
AccessPolicy::from_boolean_expression("Department::FIN && Security Level::Protected")
.unwrap(),
];
vec![AccessPolicy::parse("Department::FIN && Security Level::Protected").unwrap()];

#[cfg(feature = "full_bench")]
{
user_access_policies.push(
AccessPolicy::from_boolean_expression(
AccessPolicy::parse(
"(Department::FIN && Department::MKG) && Security Level::Protected",
)
.unwrap(),
);
user_access_policies.push(
AccessPolicy::from_boolean_expression(
AccessPolicy::parse(
"(Department::FIN && Department::MKG && Department::HR) && Security \
Level::Protected",
)
.unwrap(),
);
user_access_policies.push(
AccessPolicy::from_boolean_expression(
"(Department::R&D && Department::FIN && Department::MKG && Department::HR) && \
AccessPolicy::parse(
"(Department::RD && Department::FIN && Department::MKG && Department::HR) && \
Security Level::Protected",
)
.unwrap(),
);
user_access_policies.push(
AccessPolicy::from_boolean_expression(
"(Department::R&D && Department::FIN && Department::MKG && Department::HR && \
AccessPolicy::parse(
"(Department::RD && Department::FIN && Department::MKG && Department::HR && \
Department::CYBER) && Security Level::Protected",
)
.unwrap(),
Expand Down
3 changes: 1 addition & 2 deletions examples/runme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ fn main() {
// The user has a security clearance `Security Level::Top Secret`,
// and belongs to the finance department (`Department::FIN`).
let access_policy =
AccessPolicy::from_boolean_expression("Security Level::Top Secret && Department::FIN")
.unwrap();
AccessPolicy::parse("Security Level::Top Secret && Department::FIN").unwrap();
let mut usk = cover_crypt
.generate_user_secret_key(&msk, &access_policy, &policy)
.unwrap();
Expand Down
Loading

0 comments on commit f37d53f

Please sign in to comment.