Skip to content

Commit

Permalink
fix examples and clippy warning
Browse files Browse the repository at this point in the history
  • Loading branch information
tbrezot committed May 3, 2024
1 parent 026df6f commit a901c33
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 67 deletions.
14 changes: 7 additions & 7 deletions examples/decrypt.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use cosmian_cover_crypt::api::EncryptionHeaderAes256;
use cosmian_cover_crypt::api::EncryptedHeaderAes256;

const USK: &str = "sUBriVEsM8HowAKOsIs9Y5p+Xa8JwJf84rlBHXzfkg+BJ6PzK79cT37Wsku5pMVKrfi/eIWhufC2pjYNMBOUAgMAH+waKc6AuwtAaYXXUAJA0K/uc5A22nXEShVXykjZ8QIBuNMsBrpSQaW0hAZ0AFvJTlwSM2BgI8m5k4wj3kQQ9NaP4cK6VvwyFlx7ZwwMZkJoCSgfiPvN4XqeWmiw/hehgjU2HkgYDQJf9QABaUoa74qM42SBnNubVVVnPvO5zrZ++NgoIHt4VPJfsMu157i6bakhOEWJy/CduXYGqedOGsNpj+gq0VsanjqeJ9gZ6sKjCknGoTxbEipIrPUO5jqJLzmJilS0ycAhR1mYlGU9yApPithxeIMaQFAAegOUTVFDFausKPbDZ1IYEWyftONyaaelMyJF4eCQIWILEihLuoscwGkVlYmRttcNVrLDW3yHN/cFQgiBSNVOi/RTLSpdsaMtattwDcaEiRUvCxe2gfaCYQV9zPIsdfAG2TIf2MPLcqUu0EBnIohX/TKyOTavt7HB76d/pCWT7sceu/YldifCYUoWABA8GbnF6DurlVwhfYUKhThnchbP3mgsEUsy+vQlWIwvrwxgpgqaabNSwJIUCXttY6kYNjJbL5pkahaAnxYLRMcvvKfGtzwlX7ewINAFrMSUBua8abWzgIa2NWlt2/ON7tKrVIaqRMYs8KFJSSsQ4bGEhZfBjWEYacAho8bFMuqamQgxaJhyj/J+tZrA24A5ckmPSPeGOIKealWkQmy8f0oAPVsOGaQFcBwLMPe4qRl49tpM6kRgpsyOkeQYOdpQ7Rue0xMK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hcoW7PgxGk7Pt1CUAJ+gI15rAmRo/s7dFdI+TLGGHhnQFXiQO+1fsWydjjR/AV1grEj56NZNKwkH6FbThRI95D2y1V33+Tdg3nu6jbZB6MN1SMnBCURJoPRN5YB5Ed263j7v+XcsLKoXf14QNYuTCPqyigEoWEsd+yyjt2yWTjZtyte+FRdgauG+12GBrXzR6UnuaXWtl7Dl0GPmtFUALnIbUnLwQx5fBwpKluOMTpcrDHUJGupnZCdXuKJD8aF0fqzZjKkkpGMRm7yG32PeqFOzx9gKPnHUT7EOEKXMPK/NIFSXpez9GbDRkzeCXrweMiShzFBb2kGC/CIbFRJJ5wA=";

fn main() {
use base64::{
Expand All @@ -20,10 +20,10 @@ fn main() {
let cc = Covercrypt::default();
let usk = UserSecretKey::deserialize(&transcoder.decode(USK.as_bytes()).unwrap()).unwrap();
let encrypted_header =
EncryptionHeaderAes256::deserialize(&transcoder.decode(HEADER.as_bytes()).unwrap())
.unwrap();
for _ in 0..1000 {
EncryptionHeaderAes256::decrypt(&encrypted_header, &cc, &usk, None)
EncryptedHeaderAes256::deserialize(&transcoder.decode(HEADER.as_bytes()).unwrap()).unwrap();
for _ in 0..100 {
encrypted_header
.decrypt(&cc, &usk, None)
.expect("cannot decrypt hybrid header");
}
}
11 changes: 5 additions & 6 deletions examples/encrypt.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cosmian_cover_crypt::{
abe_policy::{AccessPolicy, Policy},
api::{Covercrypt, EncryptionHeaderAes256},
api::{Covercrypt, EncryptedHeaderAes256},
test_utils::policy,
MasterPublicKey, MasterSecretKey,
};
Expand All @@ -15,9 +15,8 @@ fn generate_new(
let access_policy =
AccessPolicy::parse("Department::FIN && Security Level::Top Secret").unwrap();

let (_, _header) =
EncryptionHeaderAes256::generate(cc, policy, mpk, access_policy.clone(), None, None)
.expect("cannot encrypt header");
let (_, _header) = EncryptedHeaderAes256::generate(cc, policy, mpk, &access_policy, None, None)
.expect("cannot encrypt header");

#[cfg(feature = "serialization")]
{
Expand Down Expand Up @@ -59,8 +58,8 @@ fn main() {
generate_new(&cc, &policy, &mut msk, &mpk);

// Encrypt header, use loop to increase its wight in the flame graph.
for _ in 0..1000 {
EncryptionHeaderAes256::generate(&cc, &policy, &mpk, ap.clone(), None, None)
for _ in 0..100 {
EncryptedHeaderAes256::generate(&cc, &policy, &mpk, &ap, None, None)
.expect("cannot encrypt header");
}
}
53 changes: 30 additions & 23 deletions examples/runme.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! This is the demo given in `README.md` and `lib.rs`

use cosmian_cover_crypt::{
abe_policy::{AccessPolicy, Attribute, DimensionBuilder, EncryptionHint, Policy},
api::{Covercrypt, EncryptionHeaderAes256},
abe_policy::{AccessPolicy, DimensionBuilder, EncryptionHint, Policy},
api::{Covercrypt, EncryptedHeaderAes256},
};

fn main() {
Expand Down Expand Up @@ -54,45 +54,52 @@ fn main() {
.unwrap();

// Encrypt
let (_, encrypted_header) =
EncryptionHeaderAes256::generate(&cover_crypt, &policy, &mpk, access_policy, None, None)
.unwrap();
let (_, encrypted_header) = EncryptedHeaderAes256::generate(
&cover_crypt,
&policy,
&mpk,
&access_policy.clone(),
None,
None,
)
.unwrap();

// The user is able to decrypt the encrypted header.
assert!(EncryptionHeaderAes256::decrypt(&encrypted_header, &cover_crypt, &usk, None).is_ok());
assert!(encrypted_header
.decrypt(&cover_crypt, &usk, None)
.unwrap()
.is_some());

//
// Rekey all keys using the `Security Level::Top Secret` attribute
let rekey_access_policy = AccessPolicy::Attr(Attribute::from(("Security Level", "Top Secret")));
// Rekey the user access policy.
let mpk = cover_crypt
.rekey(&rekey_access_policy, &policy, &mut msk)
.rekey(&access_policy, &policy, &mut msk)
.unwrap();

let enc_policy = AccessPolicy::parse("Security Level::Top Secret").unwrap();
// Encrypt with rotated attribute
let (_, new_encrypted_header) =
EncryptionHeaderAes256::generate(&cover_crypt, &policy, &mpk, enc_policy, None, None)
EncryptedHeaderAes256::generate(&cover_crypt, &policy, &mpk, &enc_policy, None, None)
.unwrap();

// user cannot decrypt the newly encrypted header
assert!(
EncryptionHeaderAes256::decrypt(&new_encrypted_header, &cover_crypt, &usk, None)
.expect("must not fail")
.is_none()
);
assert!(new_encrypted_header
.decrypt(&cover_crypt, &usk, None)
.unwrap()
.is_none());

// refresh user secret key, do not grant old encryption access
cover_crypt.refresh_usk(&mut usk, &mut msk, false).unwrap();

// The user with refreshed key is able to decrypt the newly encrypted header.
assert!(
EncryptionHeaderAes256::decrypt(&new_encrypted_header, &cover_crypt, &usk, None).is_ok()
);
assert!(new_encrypted_header
.decrypt(&cover_crypt, &usk, None)
.unwrap()
.is_some());

// But it cannot decrypt old ciphertexts
assert!(
EncryptionHeaderAes256::decrypt(&encrypted_header, &cover_crypt, &usk, None)
.expect("must not fail")
.is_none()
);
assert!(encrypted_header
.decrypt(&cover_crypt, &usk, None)
.unwrap()
.is_none());
}
10 changes: 5 additions & 5 deletions src/abe_policy/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl Policy {
/// Returns an error if the access policy is invalid.
pub fn generate_semantic_space_coordinates(
&self,
ap: AccessPolicy,
ap: &AccessPolicy,
) -> Result<HashSet<Coordinate>, Error> {
let dnf = ap.to_dnf();
let mut coordinates = HashSet::new();
Expand Down Expand Up @@ -216,7 +216,7 @@ impl Policy {
/// Returns an error if the access policy is invalid.
pub fn generate_point_coordinates(
&self,
ap: AccessPolicy,
ap: &AccessPolicy,
) -> Result<HashSet<Coordinate>, Error> {
let dnf = ap.to_dnf();
let mut coordinates = HashSet::with_capacity(dnf.len());
Expand Down Expand Up @@ -318,7 +318,7 @@ mod tests {
let ap = "(Department::HR || Department::FIN) && Security Level::Low Secret";

let semantic_space_coordinates =
policy.generate_semantic_space_coordinates(AccessPolicy::parse(ap)?)?;
policy.generate_semantic_space_coordinates(&AccessPolicy::parse(ap)?)?;

// Check the number of coordinates is correct.
assert_eq!(semantic_space_coordinates.len(), (2 + 1) * (2 + 1));
Expand Down Expand Up @@ -415,7 +415,7 @@ mod tests {

assert_eq!(
policy
.generate_semantic_space_coordinates(AccessPolicy::parse(ap)?)?
.generate_semantic_space_coordinates(&AccessPolicy::parse(ap)?)?
.len(),
// remove (2 + 1) not to count "Security Level::Protected" -> "Security Level::Low Secret" twice
2 * (1 + 1) * (2 + 1) - (2 + 1)
Expand All @@ -425,7 +425,7 @@ mod tests {
|| (Department::MKG && Security Level::Medium Secret)";
assert_eq!(
policy
.generate_semantic_space_coordinates(AccessPolicy::parse(ap)?)?
.generate_semantic_space_coordinates(&AccessPolicy::parse(ap)?)?
.len(),
// remove (2 + 1) not to count "Security Level::Protected" -> "Security Level::Low Secret" twice
(1 + 1) * (2 + 1) + (1 + 1) * (3 + 1) - (2 + 1)
Expand Down
20 changes: 10 additions & 10 deletions src/core/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl Covercrypt {
rekey(
&mut *self.rng.lock().expect("Mutex lock failed!"),
msk,
policy.generate_semantic_space_coordinates(ap.clone())?,
policy.generate_semantic_space_coordinates(ap)?,
)?;
mpk_keygen(msk)
}
Expand All @@ -126,7 +126,7 @@ impl Covercrypt {
) -> Result<MasterPublicKey, Error> {
prune(
msk,
&policy.generate_semantic_space_coordinates(access_policy.clone())?,
&policy.generate_semantic_space_coordinates(access_policy)?,
);
mpk_keygen(msk)
}
Expand All @@ -145,7 +145,7 @@ impl Covercrypt {
usk_keygen(
&mut *self.rng.lock().expect("Mutex lock failed!"),
msk,
policy.generate_semantic_space_coordinates(access_policy.clone())?,
policy.generate_semantic_space_coordinates(access_policy)?,
)
}

Expand Down Expand Up @@ -187,7 +187,7 @@ impl Covercrypt {
usk_keygen(
&mut *self.rng.lock().expect("Mutex lock failed!"),
msk,
policy.generate_semantic_space_coordinates(ap)?,
policy.generate_semantic_space_coordinates(&ap)?,
)
}
}
Expand Down Expand Up @@ -286,7 +286,7 @@ impl<
cover_crypt: &Covercrypt,
policy: &Policy,
public_key: &MasterPublicKey,
encryption_policy: AccessPolicy,
encryption_policy: &AccessPolicy,
metadata: Option<&[u8]>,
authentication_data: Option<&[u8]>,
) -> Result<(Secret<SEED_LENGTH>, Self), Error> {
Expand Down Expand Up @@ -372,7 +372,7 @@ pub trait CovercryptKEM {
&self,
mpk: &MasterPublicKey,
policy: &Policy,
ap: AccessPolicy,
ap: &AccessPolicy,
) -> Result<(Secret<SEED_LENGTH>, Encapsulation), Error>;

/// Attempts opening the given encapsulation using the given
Expand All @@ -392,7 +392,7 @@ impl CovercryptKEM for Covercrypt {
&self,
mpk: &MasterPublicKey,
policy: &Policy,
ap: AccessPolicy,
ap: &AccessPolicy,
) -> Result<(Secret<SEED_LENGTH>, Encapsulation), Error> {
encaps(
&mut *self.rng.lock().expect("Mutex lock failed!"),
Expand Down Expand Up @@ -429,7 +429,7 @@ pub trait CovercryptPKE<
&self,
mpk: &MasterPublicKey,
policy: &Policy,
ap: AccessPolicy,
ap: &AccessPolicy,
ad: Option<&[u8]>,
plaintext: &[u8],
) -> Result<(Encapsulation, Vec<u8>), Error>;
Expand Down Expand Up @@ -463,7 +463,7 @@ impl<
&self,
mpk: &MasterPublicKey,
policy: &Policy,
ap: AccessPolicy,
ap: &AccessPolicy,
ad: Option<&[u8]>,
plaintext: &[u8],
) -> Result<(Encapsulation, Vec<u8>), Error> {
Expand Down Expand Up @@ -504,7 +504,7 @@ impl<
}
}

pub type EncryptionHeaderAes256 = EncryptedHeader<
pub type EncryptedHeaderAes256 = EncryptedHeader<
Aes256Gcm,
{ Aes256Gcm::KEY_LENGTH },
{ Aes256Gcm::NONCE_LENGTH },
Expand Down
1 change: 1 addition & 0 deletions src/data_struct/revision_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ where

#[cfg(test)]
mod tests {
#![allow(clippy::unnecessary_to_owned)]
use std::collections::HashSet;

use super::*;
Expand Down
Loading

0 comments on commit a901c33

Please sign in to comment.