diff --git a/Cargo.lock b/Cargo.lock index c5eb5b79..ef8b8e14 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -153,7 +153,7 @@ dependencies = [ [[package]] name = "cosmian_cover_crypt" -version = "10.0.0" +version = "11.0.0" dependencies = [ "cosmian_crypto_core", "criterion", diff --git a/src/abe_policy/access_policy.rs b/src/abe_policy/access_policy.rs index ad114af8..a3cc6b0f 100644 --- a/src/abe_policy/access_policy.rs +++ b/src/abe_policy/access_policy.rs @@ -2,7 +2,6 @@ use crate::{ abe_policy::{policy::Policy, Attribute}, Error, }; -use serde::{Deserialize, Serialize}; use std::{ collections::HashMap, fmt::Debug, @@ -12,7 +11,7 @@ use std::{ /// An `AccessPolicy` is a boolean expression over attributes. /// /// Only `positive` literals are allowed (no negation). -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Debug, Clone)] pub enum AccessPolicy { Attr(Attribute), And(Box, Box), diff --git a/src/abe_policy/error.rs b/src/abe_policy/error.rs deleted file mode 100644 index 38f5bd85..00000000 --- a/src/abe_policy/error.rs +++ /dev/null @@ -1,38 +0,0 @@ -//! Define this crate error type. - -use thiserror::Error; -#[cfg(feature = "wasm_bindgen")] -use wasm_bindgen::JsValue; - -/// Crate error type. -#[derive(Error, Debug)] -pub enum Error { - #[error("attribute not found: {0}")] - AttributeNotFound(String), - #[error("{} is missing{}", - .item.clone().unwrap_or_else(|| "attribute".to_string()), - match .axis_name { - Some(axis) => format!(" in axis {axis}"), - None => String::new(), - })] - MissingAttribute { - item: Option, - axis_name: Option, - }, - #[error("No axis given")] - MissingAxis, - #[error("unsupported operator {0}")] - UnsupportedOperator(String), - #[error("attribute capacity overflow")] - CapacityOverflow, - #[error("policy {0} already exists")] - ExistingPolicy(String), - #[error("invalid boolean expression: {0}")] - InvalidBooleanExpression(String), - #[error("invalid attribute: {0}")] - InvalidAttribute(String), - #[error("invalid axis: {0}")] - InvalidAxis(String), - #[error("deserialization error: {0}")] - DeserializationError(serde_json::Error), -} diff --git a/src/abe_policy/policy.rs b/src/abe_policy/policy.rs index 54a8802f..c16b67eb 100644 --- a/src/abe_policy/policy.rs +++ b/src/abe_policy/policy.rs @@ -143,11 +143,7 @@ pub struct Policy { impl Display for Policy { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let json = serde_json::to_string(&self); - match json { - Ok(string) => write!(f, "{string}"), - Err(err) => write!(f, "{err}"), - } + write!(f, "{self:?}") } } @@ -155,7 +151,8 @@ impl Policy { /// Converts the given string into a Policy. Does not fail if the given /// string uses the legacy format. pub fn parse_and_convert(bytes: &[u8]) -> Result { - match serde_json::from_slice(bytes) { + // First try to deserialize the latest `Policy` format + match Policy::try_from(bytes) { Ok(policy) => Ok(policy), Err(e) => { if let Ok(policy) = serde_json::from_slice::(bytes) { @@ -180,9 +177,7 @@ impl Policy { .collect(), }) } else { - // Return the `Policy` deserialization error message instead of the - // `LegacyPolicy` one since this is the one that should be used. - Err(Error::DeserializationError(e)) + Err(e) } } } @@ -577,7 +572,9 @@ mod tests { // // create policy let mut policy = policy()?; + println!("{policy:?}"); policy.rotate(&Attribute::new("Department", "FIN"))?; + println!("{policy:?}"); // // create access policy diff --git a/tests/non_regression.rs b/tests/non_regression.rs index 7b4c3717..f873d3f5 100644 --- a/tests/non_regression.rs +++ b/tests/non_regression.rs @@ -205,7 +205,7 @@ impl NonRegressionTestVector { let reg_vectors = Self { public_key: base64::encode(mpk.try_to_bytes()?), master_secret_key: base64::encode(msk.try_to_bytes()?), - policy: base64::encode(serde_json::to_vec(&policy)?), + policy: base64::encode(&policy.try_into()?), // // Create user decryption keys top_secret_mkg_fin_key: UserSecretKeyTestVector::new(