pub fn encrypt(cipher_key: &CipherKey, plain_text: &[u8]) -> Vec<u8> {
    let mut nonce = [0u8; size_of::<Nonce>()];
    OsRng.fill_bytes(&mut nonce);

    let nonce_ga = Nonce::from_slice(&nonce);
    let mut cipher = ChaCha20::new(&cipher_key.0, nonce_ga);

    // Cloning the plain text to avoid a caller thinking we have encrypted in place and losing the integral nonce added
    // below
    let mut plain_text_clone = plain_text.to_vec();

    cipher.apply_keystream(plain_text_clone.as_mut_slice());

    let mut ciphertext_integral_nonce = Vec::with_capacity(nonce.len() + plain_text_clone.len());
    ciphertext_integral_nonce.extend(&nonce);
    ciphertext_integral_nonce.append(&mut plain_text_clone);
    ciphertext_integral_nonce
}
/// Encrypt the plain text using the ChaCha20 stream cipher
Encrypt the plain text using the ChaCha20 stream cipher
Encrypt the plain text using the ChaCha20 stream cipher
pub fn encrypt(cipher_key: &CipherKey, plain_text: &[u8]) -> Vec<u8> {
    let mut nonce = [0u8; size_of::<Nonce>()];
    OsRng.fill_bytes(&mut nonce);
    let nonce_ga = Nonce::from_slice(&nonce);
    let mut cipher = ChaCha20::new(&cipher_key.0, nonce_ga);
    // Cloning the plain text to avoid a caller thinking we have encrypted in place and losing the integral nonce added
    // below
    let mut plain_text_clone = plain_text.to_vec();
    cipher.apply_keystream(plain_text_clone.as_mut_slice());
    let mut ciphertext_integral_nonce = Vec::with_capacity(nonce.len() + plain_text_clone.len());
    ciphertext_integral_nonce.extend(&nonce);
    ciphertext_integral_nonce.append(&mut plain_text_clone);
    ciphertext_integral_nonce
}
pub fn encrypt ( cipher_key : & CipherKey , plain_text : & [ u8 ] ) -> Vec < u8 > { let mut nonce = [ 0u8 ; size_of :: < Nonce > ( ) ] ; OsRng . fill_bytes ( & mut nonce ) ; let nonce_ga = Nonce :: from_slice ( & nonce ) ; let mut cipher = ChaCha20 :: new ( & cipher_key . 0 , nonce_ga ) ; // Cloning the plain text to avoid a caller thinking we have encrypted in place and losing the integral nonce added // below let mut plain_text_clone = plain_text . to_vec ( ) ; cipher . apply_keystream ( plain_text_clone . as_mut_slice ( ) ) ; let mut ciphertext_integral_nonce = Vec :: with_capacity ( nonce . len ( ) + plain_text_clone . len ( ) ) ; ciphertext_integral_nonce . extend ( & nonce ) ; ciphertext_integral_nonce . append ( & mut plain_text_clone ) ; ciphertext_integral_nonce }
Encrypt the plain text using the ChaCha20 stream cipher
Encrypt the plain text using the ChaCha20 stream cipher
cipher_key
&CipherKey
plain_text
&[u8]
cipher_key
&CipherKey
plain_text
&[u8]