fn pipe_encrypt(&mut self, input: &[u8]) -> (usize, Option<Vec<u8>>) {
        // Don't allow encrypting more than specified, when tag is obtained
        if self.has_tag() && !input.is_empty() {
            panic!("could not write to AES-GCM encrypter, exceeding specified length");
        }

        // Find input length and block size, increase current bytes counter
        let len = input.len();
        let block_size = self.cipher.block_size();
        self.cur += len;

        // Transform input data through crypter, collect output
        // TODO: do not unwrap here, but try error
        let mut out = vec![0u8; len + block_size];
        let out_len = self
            .crypter
            .update(&input, &mut out)
            .expect("failed to update AES-GCM encrypter with new data");
        out.truncate(out_len);

        // Finalize the crypter when all data is encrypted, append finalized to output
        // TODO: do not unwrap in here, but try error
        if self.cur >= self.len && !self.has_tag() {
            // Allocate tag space
            self.tag = vec![0u8; TAG_LEN];

            let mut out_final = vec![0u8; block_size];
            let final_len = self
                .crypter
                .finalize(&mut out_final)
                .expect("failed to finalize AES-GCM encrypter");
            out.extend_from_slice(&out_final[..final_len]);
            self.crypter
                .get_tag(&mut self.tag)
                .expect("failed to get AES-GCM encrypter tag for validation");

            // Append tag to output
            out.extend_from_slice(&self.tag);
        }

        (len, Some(out))
    }
/// Encrypt the given `input` data using this configured crypter.
///
/// This function returns `(read, out)` where `read` represents the number of read bytes from
/// `input`, and `out` is a vector of now encrypted bytes.
///
/// # Panics
///
/// Panics if attempted to write more bytes than the length specified while configuring the
/// crypter.
Encrypt the given `input` data using this configured crypter.
Encrypt the given ` input ` data using this configured crypter .
fn pipe_encrypt(&mut self, input: &[u8]) -> (usize, Option<Vec<u8>>) {
        // Don't allow encrypting more than specified, when tag is obtained
        if self.has_tag() && !input.is_empty() {
            panic!("could not write to AES-GCM encrypter, exceeding specified length");
        }
        // Find input length and block size, increase current bytes counter
        let len = input.len();
        let block_size = self.cipher.block_size();
        self.cur += len;
        // Transform input data through crypter, collect output
        // TODO: do not unwrap here, but try error
        let mut out = vec![0u8; len + block_size];
        let out_len = self
            .crypter
            .update(&input, &mut out)
            .expect("failed to update AES-GCM encrypter with new data");
        out.truncate(out_len);
        // Finalize the crypter when all data is encrypted, append finalized to output
        // TODO: do not unwrap in here, but try error
        if self.cur >= self.len && !self.has_tag() {
            // Allocate tag space
            self.tag = vec![0u8; TAG_LEN];
            let mut out_final = vec![0u8; block_size];
            let final_len = self
                .crypter
                .finalize(&mut out_final)
                .expect("failed to finalize AES-GCM encrypter");
            out.extend_from_slice(&out_final[..final_len]);
            self.crypter
                .get_tag(&mut self.tag)
                .expect("failed to get AES-GCM encrypter tag for validation");
            // Append tag to output
            out.extend_from_slice(&self.tag);
        }
        (len, Some(out))
    }
fn pipe_encrypt ( & mut self , input : & [ u8 ] ) -> ( usize , Option < Vec < u8 > > ) { // Don't allow encrypting more than specified, when tag is obtained if self . has_tag ( ) && ! input . is_empty ( ) { panic ! ( " " ) ; } // Find input length and block size, increase current bytes counter let len = input . len ( ) ; let block_size = self . cipher . block_size ( ) ; self . cur += len ; // Transform input data through crypter, collect output // TODO: do not unwrap here, but try error let mut out = vec ! [ 0u8 len block_size ] ; let out_len = self . crypter . update ( & input , & mut out ) . expect ( " " ) ; out . truncate ( out_len ) ; // Finalize the crypter when all data is encrypted, append finalized to output // TODO: do not unwrap in here, but try error if self . cur >= self . len && ! self . has_tag ( ) { // Allocate tag space self . tag = vec ! [ 0u8 TAG_LEN ] ; let mut out_final = vec ! [ 0u8 block_size ] ; let final_len = self . crypter . finalize ( & mut out_final ) . expect ( " " ) ; out . extend_from_slice ( & out_final [ .. final_len ] ) ; self . crypter . get_tag ( & mut self . tag ) . expect ( " " ) ; // Append tag to output out . extend_from_slice ( & self . tag ) ; } ( len , Some ( out ) ) }
Encrypt the given `input` data using this configured crypter.
Encrypt the given ` input ` data using this configured crypter .
&mut self
input
&[u8]
&mut self
input
&[u8]
panics
Panics if attempted to write more bytes than the length specified while configuring the
crypter.
Panics if attempted to write more bytes than the length specified while configuring the crypter .