pub fn encrypt(
    _pk: &Mke08PublicKey,
    _attr_pks: &Vec<Mke08PublicAttributeKey>,
    _policy: &String,
    _plaintext: &[u8],
) -> Option<Mke08Ciphertext> {
    // if policy is in DNF
    return if DnfPolicy::is_in_dnf(&_policy) {
        // random number generator
        let mut _rng = rand::thread_rng();
        // an DNF policy from the given String
        let dnf: DnfPolicy = DnfPolicy::from_string(&_policy, _attr_pks).unwrap();
        // random Gt msgs
        let _msg1 = pairing(_rng.gen(), _rng.gen());
        let _msg2 = _msg1.pow(_rng.gen());
        let _msg = _msg1 * _msg2;
        // CT result vectors
        let mut _e: Vec<Mke08CTConjunction> = Vec::new();
        // now add randomness using _r_j
        for _term in dnf._terms.into_iter() {
            let _r_j: Fr = _rng.gen();
            _e.push(Mke08CTConjunction {
                _str: _term.0,
                _j1: _term.1.pow(_r_j) * _msg1,
                _j2: _term.2.pow(_r_j) * _msg2,
                _j3: _pk._p1 * _r_j,
                _j4: _pk._p2 * _r_j,
                _j5: _term.3 * _r_j,
                _j6: _term.4 * _r_j,
            });
        }
        //Encrypt plaintext using derived key from secret
        let _policy = _policy.to_string();
        let _ct = encrypt_symmetric(&_msg, &_plaintext.to_vec()).unwrap();
        Some(Mke08Ciphertext { _policy, _e, _ct})
    } else {
        None
    }
}
/// The encrypt algorithm of MKE08. Generates an Mke08Ciphertext using an Mke08PublicKey,
/// a Vector of Mke08PublicAttributeKeys, 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 Mke08PublicAttributeKey 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 MKE08. Generates an Mke08Ciphertext using an Mke08PublicKey,
a Vector of Mke08PublicAttributeKeys, an access policy given as String as well as some plaintext data given as [u8].
The encrypt algorithm of MKE08 . Generates an Mke08Ciphertext using an Mke08PublicKey a Vector of Mke08PublicAttributeKeys an access policy given as String as well as some plaintext data given as [ u8 ] .
pub fn encrypt(
    _pk: &Mke08PublicKey,
    _attr_pks: &Vec<Mke08PublicAttributeKey>,
    _policy: &String,
    _plaintext: &[u8],
) -> Option<Mke08Ciphertext> {
    // if policy is in DNF
    return if DnfPolicy::is_in_dnf(&_policy) {
        // random number generator
        let mut _rng = rand::thread_rng();
        // an DNF policy from the given String
        let dnf: DnfPolicy = DnfPolicy::from_string(&_policy, _attr_pks).unwrap();
        // random Gt msgs
        let _msg1 = pairing(_rng.gen(), _rng.gen());
        let _msg2 = _msg1.pow(_rng.gen());
        let _msg = _msg1 * _msg2;
        // CT result vectors
        let mut _e: Vec<Mke08CTConjunction> = Vec::new();
        // now add randomness using _r_j
        for _term in dnf._terms.into_iter() {
            let _r_j: Fr = _rng.gen();
            _e.push(Mke08CTConjunction {
                _str: _term.0,
                _j1: _term.1.pow(_r_j) * _msg1,
                _j2: _term.2.pow(_r_j) * _msg2,
                _j3: _pk._p1 * _r_j,
                _j4: _pk._p2 * _r_j,
                _j5: _term.3 * _r_j,
                _j6: _term.4 * _r_j,
            });
        }
        //Encrypt plaintext using derived key from secret
        let _policy = _policy.to_string();
        let _ct = encrypt_symmetric(&_msg, &_plaintext.to_vec()).unwrap();
        Some(Mke08Ciphertext { _policy, _e, _ct})
    } else {
        None
    }
}
pub fn encrypt ( _pk : & Mke08PublicKey , _attr_pks : & Vec < Mke08PublicAttributeKey > , _policy : & String , _plaintext : & [ u8 ] , ) -> Option < Mke08Ciphertext > { // if policy is in DNF return if DnfPolicy :: is_in_dnf ( & _policy ) { // random number generator let mut _rng = rand :: thread_rng ( ) ; // an DNF policy from the given String let dnf : DnfPolicy = DnfPolicy :: from_string ( & _policy , _attr_pks ) . unwrap ( ) ; // random Gt msgs let _msg1 = pairing ( _rng . gen ( ) , _rng . gen ( ) ) ; let _msg2 = _msg1 . pow ( _rng . gen ( ) ) ; let _msg = _msg1 * _msg2 ; // CT result vectors let mut _e : Vec < Mke08CTConjunction > = Vec :: new ( ) ; // now add randomness using _r_j for _term in dnf . _terms . into_iter ( ) { let _r_j : Fr = _rng . gen ( ) ; _e . push ( Mke08CTConjunction { _str : _term . 0 , _j1 : _term . 1 . pow ( _r_j ) * _msg1 , _j2 : _term . 2 . pow ( _r_j ) * _msg2 , _j3 : _pk . _p1 * _r_j , _j4 : _pk . _p2 * _r_j , _j5 : _term . 3 * _r_j , _j6 : _term . 4 * _r_j , } ) ; } //Encrypt plaintext using derived key from secret let _policy = _policy . to_string ( ) ; let _ct = encrypt_symmetric ( & _msg , & _plaintext . to_vec ( ) ) . unwrap ( ) ; Some ( Mke08Ciphertext { _policy , _e , _ct } ) } else { None } }
The encrypt algorithm of MKE08.
The encrypt algorithm of MKE08 .
_pk
&Mke08PublicKey
_attr_pks
&Vec<Mke08PublicAttributeKey>
_policy
&String
_plaintext
&[u8]
_pk
&Mke08PublicKey
_attr_pks
&Vec<Mke08PublicAttributeKey>
_policy
&String
_plaintext
&[u8]