Skip to content

Commit

Permalink
adopted examples to use human policy
Browse files Browse the repository at this point in the history
  • Loading branch information
Bramm, Georg committed Jul 31, 2020
1 parent 9321090 commit 6da4222
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 17 deletions.
18 changes: 12 additions & 6 deletions src/schemes/ac17/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
//! use rabe::utils::policy::pest::PolicyLanguage;
//! let (pk, msk) = setup();
//! let plaintext = String::from("our plaintext!").into_bytes();
//! let policy = String::from(r#"{"name": "and", "children": [{"name": "A"}, {"name": "B"}]}"#);
//! let ct: Ac17KpCiphertext = kp_encrypt(&pk, &vec!["A".to_string(), "B".to_string()], &plaintext).unwrap();
//! let sk: Ac17KpSecretKey = kp_keygen(&msk, &policy, PolicyLanguage::JsonPolicy).unwrap();
//! let policy = String::from(r#""A" and "B""#);
//! let ct: Ac17KpCiphertext = kp_encrypt(&pk, &vec![
//! "A".to_string(),
//! "B".to_string()
//! ], &plaintext).unwrap();
//! let sk: Ac17KpSecretKey = kp_keygen(&msk, &policy, PolicyLanguage::HumanPolicy).unwrap();
//! assert_eq!(kp_decrypt(&sk, &ct).unwrap(), plaintext);
//! ```
//!
Expand All @@ -30,9 +33,12 @@
//! use rabe::utils::policy::pest::PolicyLanguage;
//! let (pk, msk) = setup();
//! let plaintext = String::from("our plaintext!").into_bytes();
//! let policy = String::from(r#"{"name": "and", "children": [{"name": "A"}, {"name": "B"}]}"#);
//! let ct: Ac17CpCiphertext = cp_encrypt(&pk, &policy, &plaintext, PolicyLanguage::JsonPolicy).unwrap();
//! let sk: Ac17CpSecretKey = cp_keygen(&msk, &vec!["A".to_string(), "B".to_string()]).unwrap();
//! let policy = String::from(r#""A" and "B""#);
//! let ct: Ac17CpCiphertext = cp_encrypt(&pk, &policy, &plaintext, PolicyLanguage::HumanPolicy).unwrap();
//! let sk: Ac17CpSecretKey = cp_keygen(&msk, &vec![
//! "A".to_string(),
//! "B".to_string()
//! ]).unwrap();
//! assert_eq!(cp_decrypt(&sk, &ct).unwrap(), plaintext);
//! ```
use std::{
Expand Down
4 changes: 2 additions & 2 deletions src/schemes/aw11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
//!let gk = setup();
//!let (pk, msk) = authgen(&gk, &vec!["A".to_string(), "B".to_string()]).unwrap();
//!let plaintext = String::from("our plaintext!").into_bytes();
//!let policy = String::from(r#"{"name": "or", "children": [{"name": "A"}, {"name": "B"}]}"#);
//!let policy = String::from(r#""A" or "B""#);
//!let bob = keygen(&gk, &msk, &String::from("bob"), &vec!["A".to_string()]).unwrap();
//!let ct: Aw11Ciphertext = encrypt(&gk, &vec![pk], &policy, PolicyLanguage::JsonPolicy, &plaintext).unwrap();
//!let ct: Aw11Ciphertext = encrypt(&gk, &vec![pk], &policy, PolicyLanguage::HumanPolicy, &plaintext).unwrap();
//!let matching = decrypt(&gk, &bob, &ct).unwrap();
//!assert_eq!(matching, plaintext);
//! ```
Expand Down
4 changes: 2 additions & 2 deletions src/schemes/bdabe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
//!let _att1_pk = request_attribute_pk(&_pk, &_a1_key, &_att1).unwrap();
//!_u_key._ska.push(request_attribute_sk(&_u_key._pk, &_a1_key, &_att1).unwrap());
//!let _plaintext = String::from("our plaintext!").into_bytes();
//!let _policy = String::from(r#"{"name": "aa1::A"}"#);
//!let _ct: BdabeCiphertext = encrypt(&_pk, &vec![_att1_pk], &_policy, &_plaintext, PolicyLanguage::JsonPolicy).unwrap();
//!let _policy = String::from(r#""aa1::A" or "aa1::B""#);
//!let _ct: BdabeCiphertext = encrypt(&_pk, &vec![_att1_pk], &_policy, &_plaintext, PolicyLanguage::HumanPolicy).unwrap();
//!let _match = decrypt(&_pk, &_u_key, &_ct);
//!assert_eq!(_match.is_ok(), true);
//!assert_eq!(_match.unwrap(), _plaintext);
Expand Down
4 changes: 2 additions & 2 deletions src/schemes/bsw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
//! use rabe::utils::policy::pest::PolicyLanguage;
//!let (pk, msk) = setup();
//!let plaintext = String::from("dance like no one's watching, encrypt like everyone is!").into_bytes();
//!let policy = String::from(r#"{"name": "and", "children": [{"name": "A"}, {"name": "B"}]}"#);
//!let ct_cp: CpAbeCiphertext = encrypt(&pk, &policy, &plaintext, PolicyLanguage::JsonPolicy).unwrap();
//!let policy = String::from(r#""A" and "B""#);
//!let ct_cp: CpAbeCiphertext = encrypt(&pk, &policy, &plaintext, PolicyLanguage::HumanPolicy).unwrap();
//!let sk: CpAbeSecretKey = keygen(&pk, &msk, &vec!["A".to_string(), "B".to_string()]).unwrap();
//!assert_eq!(decrypt(&sk, &ct_cp).unwrap(), plaintext);
//! ```
Expand Down
4 changes: 2 additions & 2 deletions src/schemes/lsw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
//! use rabe::utils::policy::pest::PolicyLanguage;
//!let (pk, msk) = setup();
//!let plaintext = String::from("our plaintext!").into_bytes();
//!let policy = String::from(r#"{"name": "or", "children": [{"name": "X"}, {"name": "B"}]}"#);
//!let policy = String::from(r#""X" or "B""#);
//!let ct_kp: KpAbeCiphertext = encrypt(&pk, &vec!["A".to_string(), "B".to_string()], &plaintext).unwrap();
//!let sk: KpAbeSecretKey = keygen(&pk, &msk, &policy, PolicyLanguage::JsonPolicy).unwrap();
//!let sk: KpAbeSecretKey = keygen(&pk, &msk, &policy, PolicyLanguage::HumanPolicy).unwrap();
//!assert_eq!(decrypt(&sk, &ct_kp).unwrap(), plaintext);
//! ```
use bn::{Group, Fr, G1, G2, Gt, pairing};
Expand Down
4 changes: 2 additions & 2 deletions src/schemes/mke08/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
//!_u_key._sk_a.push(request_authority_sk(&_att1, &_a1_key, &_u_key._pk_u).unwrap());
//!_u_key._sk_a.push(request_authority_sk(&_att2, &_a2_key, &_u_key._pk_u).unwrap());
//!let _plaintext = String::from("our plaintext!").into_bytes();
//!let _policy = String::from(r#"{"name": "and", "children": [{"name": "aa1::A"}, {"name": "aa2::B"}]}"#);
//!let _ct: Mke08Ciphertext = encrypt(&_pk, &vec![_att1_pk, _att2_pk], &_policy, PolicyLanguage::JsonPolicy, &_plaintext).unwrap();
//!let _policy = String::from(r#""aa1::A" and "aa2::B""#);
//!let _ct: Mke08Ciphertext = encrypt(&_pk, &vec![_att1_pk, _att2_pk], &_policy, PolicyLanguage::HumanPolicy, &_plaintext).unwrap();
//!assert_eq!(decrypt(&_pk, &_u_key, &_ct).unwrap(), _plaintext);
//! ```
use bn::{Group, Fr, G1, G2, Gt, pairing};
Expand Down
1 change: 0 additions & 1 deletion src/utils/policy/pest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ pub fn serialize_policy(val: &PolicyValue, language: PolicyLanguage, parent: Opt
Some(PolicyType::Or) => format!("({})", contents.join(" or ")),
_ => panic!("children without parent")
}

}
String(s) => format!("{}", s),
}
Expand Down

0 comments on commit 6da4222

Please sign in to comment.