pub fn encrypt(
    _pk: &CpAbePublicKey,
    _policy: &String,
    _plaintext: &Vec<u8>,
) -> Option<CpAbeCiphertext> {
    if _plaintext.is_empty() || _policy.is_empty() {
        return None;
    }
    let mut _rng = rand::thread_rng();
    // the shared root secret
    let _s:Fr = _rng.gen();
    let _msg: Gt = _rng.gen();
    let _shares: Vec<(String, Fr)> = gen_shares_str(_s, _policy).unwrap();
    let _c = _pk._h * _s;
    let _c_p = _pk._e_gg_alpha.pow(_s) * _msg;
    let mut _c_y: Vec<CpAbeAttribute> = Vec::new();
    for (_j, _j_val) in _shares {
        _c_y.push(CpAbeAttribute {
            _str: _j.clone(),
            _g1: _pk._g1 * _j_val,
            _g2: blake2b_hash_g2(_pk._g2, &_j) * _j_val,
        });
    }
    let _policy = _policy.to_string();
    let _ct = encrypt_symmetric(&_msg, &_plaintext).unwrap();
    //Encrypt plaintext using derived key from secret
    return Some(CpAbeCiphertext {_policy, _c, _c_p, _c_y, _ct});
}
/// The encrypt algorithm of BSW CP-ABE. Generates a new CpAbeCiphertext using an Ac17PublicKey, an access policy given as String and some plaintext data given as [u8].
///
/// # Arguments
///
///	* `_pk` - A Public Key (PK), generated by the function setup()
///	* `_policy` - An access policy given as JSON String
///	* `_plaintext` - plaintext data given as a Vector of u8
///
The encrypt algorithm of BSW CP-ABE. Generates a new CpAbeCiphertext using an Ac17PublicKey, an access policy given as String and some plaintext data given as [u8].
The encrypt algorithm of BSW CP - ABE . Generates a new CpAbeCiphertext using an Ac17PublicKey an access policy given as String and some plaintext data given as [ u8 ] .
pub fn encrypt(
    _pk: &CpAbePublicKey,
    _policy: &String,
    _plaintext: &Vec<u8>,
) -> Option<CpAbeCiphertext> {
    if _plaintext.is_empty() || _policy.is_empty() {
        return None;
    }
    let mut _rng = rand::thread_rng();
    // the shared root secret
    let _s:Fr = _rng.gen();
    let _msg: Gt = _rng.gen();
    let _shares: Vec<(String, Fr)> = gen_shares_str(_s, _policy).unwrap();
    let _c = _pk._h * _s;
    let _c_p = _pk._e_gg_alpha.pow(_s) * _msg;
    let mut _c_y: Vec<CpAbeAttribute> = Vec::new();
    for (_j, _j_val) in _shares {
        _c_y.push(CpAbeAttribute {
            _str: _j.clone(),
            _g1: _pk._g1 * _j_val,
            _g2: blake2b_hash_g2(_pk._g2, &_j) * _j_val,
        });
    }
    let _policy = _policy.to_string();
    let _ct = encrypt_symmetric(&_msg, &_plaintext).unwrap();
    //Encrypt plaintext using derived key from secret
    return Some(CpAbeCiphertext {_policy, _c, _c_p, _c_y, _ct});
}
pub fn encrypt ( _pk : & CpAbePublicKey , _policy : & String , _plaintext : & Vec < u8 > , ) -> Option < CpAbeCiphertext > { if _plaintext . is_empty ( ) || _policy . is_empty ( ) { return None ; } let mut _rng = rand :: thread_rng ( ) ; // the shared root secret let _s : Fr = _rng . gen ( ) ; let _msg : Gt = _rng . gen ( ) ; let _shares : Vec < ( String , Fr ) > = gen_shares_str ( _s , _policy ) . unwrap ( ) ; let _c = _pk . _h * _s ; let _c_p = _pk . _e_gg_alpha . pow ( _s ) * _msg ; let mut _c_y : Vec < CpAbeAttribute > = Vec :: new ( ) ; for ( _j , _j_val ) in _shares { _c_y . push ( CpAbeAttribute { _str : _j . clone ( ) , _g1 : _pk . _g1 * _j_val , _g2 : blake2b_hash_g2 ( _pk . _g2 , & _j ) * _j_val , } ) ; } let _policy = _policy . to_string ( ) ; let _ct = encrypt_symmetric ( & _msg , & _plaintext ) . unwrap ( ) ; //Encrypt plaintext using derived key from secret return Some ( CpAbeCiphertext { _policy , _c , _c_p , _c_y , _ct } ) ; }
The encrypt algorithm of BSW CP-ABE.
The encrypt algorithm of BSW CP - ABE .
_pk
&CpAbePublicKey
_policy
&String
_plaintext
&Vec<u8>
_pk
&CpAbePublicKey
_policy
&String
_plaintext
&Vec<u8>