pub fn encrypt(
    _pk: &BdabePublicKey,
    _attr_pks: &Vec<BdabePublicAttributeKey>,
    _policy: &String,
    _plaintext: &[u8],
) -> Option<BdabeCiphertext> {
    // if policy is in DNF
    if dnf::DnfPolicy::is_in_dnf(&_policy) {
        // random number generator
        let mut _rng = rand::thread_rng();
        let _policy = _policy.to_string();
        // an DNF policy from the given String
        let dnf: dnf::DnfPolicy = dnf::DnfPolicy::from_string(&_policy, _attr_pks).unwrap();
        // random Gt msg
        let _msg = pairing(_rng.gen(), _rng.gen());
        // CT result vector
        let _ct = encrypt_symmetric(&_msg, &_plaintext.to_vec()).unwrap();
        let mut _j: Vec<BdabeCiphertextTuple> = Vec::new();
        // now add randomness using _r_j
        for _term in dnf._terms {
            let _r_j: Fr = _rng.gen();
            _j.push(BdabeCiphertextTuple {
                _str: _term.0,
                _e1: _term.1.pow(_r_j) * _msg,
                _e2: _pk._p1 * _r_j,
                _e3: _pk._p2 * _r_j,
                _e4: _term.3 * _r_j,
                _e5: _term.4 * _r_j,
            });
        }
        //Encrypt plaintext using derived key from secret
        Some(BdabeCiphertext {_policy, _j, _ct })
    } else {
        None
    }
}
/// The encrypt algorithm of BDABE. Generates an BdabeCiphertext using an BdabePublicKey,
/// a Vector of BdabePublicAttributeKeys, an access policy given as String as well as some plaintext data given as [u8].
///
/// # Arguments
///
///	* `_pk` - A Public Key (PK), generated by the function setup()
///	* `_attr_pks` - A Vector of all BdabePublicAttributeKeys that are involded in the policy
///	* `_policy` - An access policy given as JSON String
///	* `_plaintext` - plaintext data given as a Vector of u8
///
The encrypt algorithm of BDABE. Generates an BdabeCiphertext using an BdabePublicKey,
a Vector of BdabePublicAttributeKeys, an access policy given as String as well as some plaintext data given as [u8].
The encrypt algorithm of BDABE . Generates an BdabeCiphertext using an BdabePublicKey a Vector of BdabePublicAttributeKeys an access policy given as String as well as some plaintext data given as [ u8 ] .
pub fn encrypt(
    _pk: &BdabePublicKey,
    _attr_pks: &Vec<BdabePublicAttributeKey>,
    _policy: &String,
    _plaintext: &[u8],
) -> Option<BdabeCiphertext> {
    // if policy is in DNF
    if dnf::DnfPolicy::is_in_dnf(&_policy) {
        // random number generator
        let mut _rng = rand::thread_rng();
        let _policy = _policy.to_string();
        // an DNF policy from the given String
        let dnf: dnf::DnfPolicy = dnf::DnfPolicy::from_string(&_policy, _attr_pks).unwrap();
        // random Gt msg
        let _msg = pairing(_rng.gen(), _rng.gen());
        // CT result vector
        let _ct = encrypt_symmetric(&_msg, &_plaintext.to_vec()).unwrap();
        let mut _j: Vec<BdabeCiphertextTuple> = Vec::new();
        // now add randomness using _r_j
        for _term in dnf._terms {
            let _r_j: Fr = _rng.gen();
            _j.push(BdabeCiphertextTuple {
                _str: _term.0,
                _e1: _term.1.pow(_r_j) * _msg,
                _e2: _pk._p1 * _r_j,
                _e3: _pk._p2 * _r_j,
                _e4: _term.3 * _r_j,
                _e5: _term.4 * _r_j,
            });
        }
        //Encrypt plaintext using derived key from secret
        Some(BdabeCiphertext {_policy, _j, _ct })
    } else {
        None
    }
}
pub fn encrypt ( _pk : & BdabePublicKey , _attr_pks : & Vec < BdabePublicAttributeKey > , _policy : & String , _plaintext : & [ u8 ] , ) -> Option < BdabeCiphertext > { // if policy is in DNF if dnf :: DnfPolicy :: is_in_dnf ( & _policy ) { // random number generator let mut _rng = rand :: thread_rng ( ) ; let _policy = _policy . to_string ( ) ; // an DNF policy from the given String let dnf : dnf :: DnfPolicy = dnf :: DnfPolicy :: from_string ( & _policy , _attr_pks ) . unwrap ( ) ; // random Gt msg let _msg = pairing ( _rng . gen ( ) , _rng . gen ( ) ) ; // CT result vector let _ct = encrypt_symmetric ( & _msg , & _plaintext . to_vec ( ) ) . unwrap ( ) ; let mut _j : Vec < BdabeCiphertextTuple > = Vec :: new ( ) ; // now add randomness using _r_j for _term in dnf . _terms { let _r_j : Fr = _rng . gen ( ) ; _j . push ( BdabeCiphertextTuple { _str : _term . 0 , _e1 : _term . 1 . pow ( _r_j ) * _msg , _e2 : _pk . _p1 * _r_j , _e3 : _pk . _p2 * _r_j , _e4 : _term . 3 * _r_j , _e5 : _term . 4 * _r_j , } ) ; } //Encrypt plaintext using derived key from secret Some ( BdabeCiphertext { _policy , _j , _ct } ) } else { None } }
The encrypt algorithm of BDABE.
The encrypt algorithm of BDABE .
_pk
&BdabePublicKey
_attr_pks
&Vec<BdabePublicAttributeKey>
_policy
&String
_plaintext
&[u8]
_pk
&BdabePublicKey
_attr_pks
&Vec<BdabePublicAttributeKey>
_policy
&String
_plaintext
&[u8]