pub fn encrypt(plaintext: &[u8], public_keys: &[&[u8]]) -> Option<Vec<u8>> {
    let mut ciphertext = Vec::<u8>::new();
    let nonce = gen_nonce();
    ciphertext.extend_from_slice(nonce.as_ref());
    let (ephemeral_public_key, ephemeral_private_key) = gen_keypair();
    ciphertext.extend_from_slice(ephemeral_public_key.as_ref());
    let key = gen_key();
    let key_with_recipient_count = {
        let mut blob = Vec::<u8>::new();
        blob.extend_from_slice(key.as_ref());
        blob.push(match public_keys.len().try_into() {
            Ok(length) => length,
            Err(_) => return None,
        });
        blob
    };
    for public_key in public_keys {
        let shared_key = match scalarmult(
            &Scalar::from_slice(ephemeral_private_key.as_ref()).unwrap(),
            &GroupElement::from_slice(public_key).unwrap(),
        ) {
            Ok(it) => Key::from_slice(it.as_ref()).unwrap(),
            Err(()) => return None,
        };
        ciphertext.extend_from_slice(&seal(&key_with_recipient_count, &nonce, &shared_key));
    }
    ciphertext.extend_from_slice(&seal(&plaintext, &nonce, &key));
    Some(ciphertext)
}
/// Returns None if one of the public keys is unacceptable, i.e. is equal to
/// 0 or public key count exceeds 255.
Returns None if one of the public keys is unacceptable, i.e. is equal to
0 or public key count exceeds 255.
Returns None if one of the public keys is unacceptable i . e . is equal to 0 or public key count exceeds 255 .
pub fn encrypt(plaintext: &[u8], public_keys: &[&[u8]]) -> Option<Vec<u8>> {
    let mut ciphertext = Vec::<u8>::new();
    let nonce = gen_nonce();
    ciphertext.extend_from_slice(nonce.as_ref());
    let (ephemeral_public_key, ephemeral_private_key) = gen_keypair();
    ciphertext.extend_from_slice(ephemeral_public_key.as_ref());
    let key = gen_key();
    let key_with_recipient_count = {
        let mut blob = Vec::<u8>::new();
        blob.extend_from_slice(key.as_ref());
        blob.push(match public_keys.len().try_into() {
            Ok(length) => length,
            Err(_) => return None,
        });
        blob
    };
    for public_key in public_keys {
        let shared_key = match scalarmult(
            &Scalar::from_slice(ephemeral_private_key.as_ref()).unwrap(),
            &GroupElement::from_slice(public_key).unwrap(),
        ) {
            Ok(it) => Key::from_slice(it.as_ref()).unwrap(),
            Err(()) => return None,
        };
        ciphertext.extend_from_slice(&seal(&key_with_recipient_count, &nonce, &shared_key));
    }
    ciphertext.extend_from_slice(&seal(&plaintext, &nonce, &key));
    Some(ciphertext)
}
pub fn encrypt ( plaintext : & [ u8 ] , public_keys : & [ & [ u8 ] ] ) -> Option < Vec < u8 > > { let mut ciphertext = Vec :: < u8 > :: new ( ) ; let nonce = gen_nonce ( ) ; ciphertext . extend_from_slice ( nonce . as_ref ( ) ) ; let ( ephemeral_public_key , ephemeral_private_key ) = gen_keypair ( ) ; ciphertext . extend_from_slice ( ephemeral_public_key . as_ref ( ) ) ; let key = gen_key ( ) ; let key_with_recipient_count = { let mut blob = Vec :: < u8 > :: new ( ) ; blob . extend_from_slice ( key . as_ref ( ) ) ; blob . push ( match public_keys . len ( ) . try_into ( ) { Ok ( length ) => length , Err ( _ ) => return None , } ) ; blob } ; for public_key in public_keys { let shared_key = match scalarmult ( & Scalar :: from_slice ( ephemeral_private_key . as_ref ( ) ) . unwrap ( ) , & GroupElement :: from_slice ( public_key ) . unwrap ( ) , ) { Ok ( it ) => Key :: from_slice ( it . as_ref ( ) ) . unwrap ( ) , Err ( ( ) ) => return None , } ; ciphertext . extend_from_slice ( & seal ( & key_with_recipient_count , & nonce , & shared_key ) ) ; } ciphertext . extend_from_slice ( & seal ( & plaintext , & nonce , & key ) ) ; Some ( ciphertext ) }
Returns None if one of the public keys is unacceptable, i.e.
Returns None if one of the public keys is unacceptable i . e .
plaintext
&[u8]
public_keys
&[&[u8]]