pub fn crypt<S: AsRef<[u8]>>(key: AesKey, nonce: [u8; 12], sections: &[S]) -> Vec<Vec<u8>> {
    // FIXME(perf): Optimize storage of return type (`Vec<&[u8]>` with shared backing store)

    let iv = build_iv(nonce);

    let cipher = Cipher::aes_128_ctr();
    let block_size = cipher.block_size();
    debug!(
        "key size: {}, iv size: {:?}, block size: {}",
        cipher.key_len(),
        cipher.iv_len(),
        block_size
    );

    let mut crypter = Crypter::new(cipher, symm::Mode::Decrypt, key.as_raw(), Some(&iv)).unwrap();

    sections
        .into_iter()
        .map(|section| {
            let section = section.as_ref();
            let mut data = vec![0; section.len() + block_size];
            let size = crypter.update(&section, &mut data).unwrap();
            let data = &data[..size];
            assert_eq!(
                section.len(),
                size,
                "input {} bytes, got {} bytes out",
                section.len(),
                size
            );

            data.to_vec()
        })
        .collect()
}
/// Encrypts or decrypts a list of sections, returning each
/// section as raw bytes.
///
/// # Parameters
///
/// * `key`: The 128-bit AES key.
/// * `nonce`: The 12-byte nonce stored in the encryption header of the GBL
///   file.
/// * `sections`: Iterator over the sections of the GBL.
///   Will be encrypted or decrypted in series.
Encrypts or decrypts a list of sections, returning each
section as raw bytes.
Encrypts or decrypts a list of sections returning each section as raw bytes .
pub fn crypt<S: AsRef<[u8]>>(key: AesKey, nonce: [u8; 12], sections: &[S]) -> Vec<Vec<u8>> {
    // FIXME(perf): Optimize storage of return type (`Vec<&[u8]>` with shared backing store)
    let iv = build_iv(nonce);
    let cipher = Cipher::aes_128_ctr();
    let block_size = cipher.block_size();
    debug!(
        "key size: {}, iv size: {:?}, block size: {}",
        cipher.key_len(),
        cipher.iv_len(),
        block_size
    );
    let mut crypter = Crypter::new(cipher, symm::Mode::Decrypt, key.as_raw(), Some(&iv)).unwrap();
    sections
        .into_iter()
        .map(|section| {
            let section = section.as_ref();
            let mut data = vec![0; section.len() + block_size];
            let size = crypter.update(&section, &mut data).unwrap();
            let data = &data[..size];
            assert_eq!(
                section.len(),
                size,
                "input {} bytes, got {} bytes out",
                section.len(),
                size
            );
            data.to_vec()
        })
        .collect()
}
pub fn crypt < S : AsRef < [ u8 ] > > ( key : AesKey , nonce : [ u8 ; 12 ] , sections : & [ S ] ) -> Vec < Vec < u8 > > { // FIXME(perf): Optimize storage of return type (`Vec<&[u8]>` with shared backing store) let iv = build_iv ( nonce ) ; let cipher = Cipher :: aes_128_ctr ( ) ; let block_size = cipher . block_size ( ) ; debug ! ( " " cipher key_len ( ) cipher iv_len ( ) block_size ) ; let mut crypter = Crypter :: new ( cipher , symm :: Mode :: Decrypt , key . as_raw ( ) , Some ( & iv ) ) . unwrap ( ) ; sections . into_iter ( ) . map ( | section | { let section = section . as_ref ( ) ; let mut data = vec ! [ 0 section len ( ) block_size ] ; let size = crypter . update ( & section , & mut data ) . unwrap ( ) ; let data = & data [ .. size ] ; assert_eq ! ( section len ( ) size " " section len ( ) size ) ; data . to_vec ( ) } ) . collect ( ) }
Encrypts or decrypts a list of sections, returning each
section as raw bytes.
Encrypts or decrypts a list of sections returning each section as raw bytes .
key
AesKey
nonce
[u8; 12]
sections
&[S]