pub fn delegate(
    _pk: &CpAbePublicKey,
    _sk: &CpAbeSecretKey,
    _subset: &Vec<String>,
) -> Option<CpAbeSecretKey> {
    let _str_attr = _sk._d_j
        .iter()
        .map(|_values| _values._str.to_string())
        .collect::<Vec<_>>();

    return if !is_subset(&_subset, &_str_attr) {
        println!("Error: the given attribute set is not a subset of the given sk.");
        None
    } else {
        // if no attibutes or an empty policy
        // maybe add empty msk also here
        if _subset.is_empty() || _subset.len() == 0 {
            println!("Error: the given attribute subset is empty.");
            return None;
        }
        // random number generator
        let mut _rng = rand::thread_rng();
        // generate random r
        let _r: Fr = _rng.gen();
        // calculate derived _k_0
        let mut _d_k: Vec<CpAbeAttribute> = Vec::new();
        // calculate derived attributes
        for _attr in _subset {
            let _r_j: Fr = _rng.gen();
            let _d_j_val = _sk._d_j
                .iter()
                .find(|x| x._str == _attr.to_string())
                .map(|x| (x._g1, x._g2))
                .unwrap();
            _d_k.push(CpAbeAttribute {
                _str: _attr.clone(),
                _g1: _d_j_val.0 + (_pk._g1 * _r_j),
                _g2: _d_j_val.1 + (blake2b_hash_g2(_pk._g2, &_attr) * _r_j) + (_pk._g2 * _r),
            });
        }
        Some(CpAbeSecretKey {
            _d: _sk._d + (_pk._f * _r),
            _d_j: _d_k,
        })
    }
}
/// The delegate generation algorithm of BSW CP-ABE. Generates a new CpAbeSecretKey using a CpAbePublicKey, a CpAbeSecretKey and a subset of attributes (of the key _sk) given as Vec<String>.
///
/// # Arguments
///
///	* `_pk` - A Public Key (PK), generated by the function setup()
///	* `_sk` - A Secret User Key (SK), generated by the function keygen()
///	* `_attributes` - A Vector of String attributes assigned to this user key
///
The delegate generation algorithm of BSW CP-ABE. Generates a new CpAbeSecretKey using a CpAbePublicKey, a CpAbeSecretKey and a subset of attributes (of the key _sk) given as Vec.
The delegate generation algorithm of BSW CP - ABE . Generates a new CpAbeSecretKey using a CpAbePublicKey a CpAbeSecretKey and a subset of attributes ( of the key _sk ) given as Vec .
pub fn delegate(
    _pk: &CpAbePublicKey,
    _sk: &CpAbeSecretKey,
    _subset: &Vec<String>,
) -> Option<CpAbeSecretKey> {
    let _str_attr = _sk._d_j
        .iter()
        .map(|_values| _values._str.to_string())
        .collect::<Vec<_>>();
    return if !is_subset(&_subset, &_str_attr) {
        println!("Error: the given attribute set is not a subset of the given sk.");
        None
    } else {
        // if no attibutes or an empty policy
        // maybe add empty msk also here
        if _subset.is_empty() || _subset.len() == 0 {
            println!("Error: the given attribute subset is empty.");
            return None;
        }
        // random number generator
        let mut _rng = rand::thread_rng();
        // generate random r
        let _r: Fr = _rng.gen();
        // calculate derived _k_0
        let mut _d_k: Vec<CpAbeAttribute> = Vec::new();
        // calculate derived attributes
        for _attr in _subset {
            let _r_j: Fr = _rng.gen();
            let _d_j_val = _sk._d_j
                .iter()
                .find(|x| x._str == _attr.to_string())
                .map(|x| (x._g1, x._g2))
                .unwrap();
            _d_k.push(CpAbeAttribute {
                _str: _attr.clone(),
                _g1: _d_j_val.0 + (_pk._g1 * _r_j),
                _g2: _d_j_val.1 + (blake2b_hash_g2(_pk._g2, &_attr) * _r_j) + (_pk._g2 * _r),
            });
        }
        Some(CpAbeSecretKey {
            _d: _sk._d + (_pk._f * _r),
            _d_j: _d_k,
        })
    }
}
pub fn delegate ( _pk : & CpAbePublicKey , _sk : & CpAbeSecretKey , _subset : & Vec < String > , ) -> Option < CpAbeSecretKey > { let _str_attr = _sk . _d_j . iter ( ) . map ( | _values | _values . _str . to_string ( ) ) . collect :: < Vec < _ > > ( ) ; return if ! is_subset ( & _subset , & _str_attr ) { println ! ( " " ) ; None } else { // if no attibutes or an empty policy // maybe add empty msk also here if _subset . is_empty ( ) || _subset . len ( ) == 0 { println ! ( " " ) ; return None ; } // random number generator let mut _rng = rand :: thread_rng ( ) ; // generate random r let _r : Fr = _rng . gen ( ) ; // calculate derived _k_0 let mut _d_k : Vec < CpAbeAttribute > = Vec :: new ( ) ; // calculate derived attributes for _attr in _subset { let _r_j : Fr = _rng . gen ( ) ; let _d_j_val = _sk . _d_j . iter ( ) . find ( | x | x . _str == _attr . to_string ( ) ) . map ( | x | ( x . _g1 , x . _g2 ) ) . unwrap ( ) ; _d_k . push ( CpAbeAttribute { _str : _attr . clone ( ) , _g1 : _d_j_val . 0 + ( _pk . _g1 * _r_j ) , _g2 : _d_j_val . 1 + ( blake2b_hash_g2 ( _pk . _g2 , & _attr ) * _r_j ) + ( _pk . _g2 * _r ) , } ) ; } Some ( CpAbeSecretKey { _d : _sk . _d + ( _pk . _f * _r ) , _d_j : _d_k , } ) } }
The delegate generation algorithm of BSW CP-ABE.
The delegate generation algorithm of BSW CP - ABE .
_pk
&CpAbePublicKey
_sk
&CpAbeSecretKey
_subset
&Vec<String>
_pk
&CpAbePublicKey
_sk
&CpAbeSecretKey
_subset
&Vec<String>