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

        // How many data and tag bytes we need to read, read chunks from input
        let data_len = self.len - self.cur;
        let tag_len = TAG_LEN - self.tag.len();
        let consumed = min(data_len + tag_len, input.len());
        let (data_buf, tag_buf) = input.split_at(min(data_len, input.len()));
        self.cur += min(consumed, self.len);

        let mut plaintext = Vec::new();

        // Read from the data buffer
        if !data_buf.is_empty() {
            // Create a decrypted buffer, with the proper size
            let block_size = self.cipher.block_size();
            let mut decrypted = vec![0u8; data_len + block_size];

            // Decrypt bytes
            // TODO: do not unwrap, but try error
            let len = self
                .crypter
                .update(data_buf, &mut decrypted)
                .expect("failed to update AES-GCM decrypter with new data");

            // Add decrypted bytes to output
            plaintext.extend_from_slice(&decrypted[..len]);
        }

        // Read from the tag part to fill the tag buffer
        if !tag_buf.is_empty() {
            self.tag.extend_from_slice(&tag_buf[..tag_len]);
        }

        // Verify the tag once available
        if self.has_tag() {
            // Set the tag
            // TODO: do not unwrap, but try error
            self.crypter
                .set_tag(&self.tag)
                .expect("failed to set AES-GCM decrypter tag for validation");

            // Create a buffer for any remaining data
            let block_size = self.cipher.block_size();
            let mut extra = vec![0u8; block_size];

            // Finalize, write all remaining data
            // TODO: do not unwrap, but try error
            let len = self
                .crypter
                .finalize(&mut extra)
                .expect("failed to finalize AES-GCM decrypter");
            plaintext.extend_from_slice(&extra[..len]);
        }

        let plaintext = if !plaintext.is_empty() {
            Some(plaintext)
        } else {
            None
        };
        (consumed, plaintext)
    }
/// Decrypt the given `input` payload using this configured crypter.
///
/// This function returns `(read, plaintext)` where `read` represents the number of read bytes from
/// `input`, and `plaintext` is a vector of the produced plaintext.
///
/// # Panics
///
/// Panics if attempted to write more bytes than the length specified while configuring the
/// crypter.
Decrypt the given `input` payload using this configured crypter.
Decrypt the given ` input ` payload using this configured crypter .
fn pipe_decrypt(&mut self, input: &[u8]) -> (usize, Option<Vec<u8>>) {
        // Don't allow decrypting more than specified, when tag is obtained
        if self.has_tag() && !input.is_empty() {
            panic!("could not write to AES-GCM decrypter, exceeding specified lenght");
        }
        // How many data and tag bytes we need to read, read chunks from input
        let data_len = self.len - self.cur;
        let tag_len = TAG_LEN - self.tag.len();
        let consumed = min(data_len + tag_len, input.len());
        let (data_buf, tag_buf) = input.split_at(min(data_len, input.len()));
        self.cur += min(consumed, self.len);
        let mut plaintext = Vec::new();
        // Read from the data buffer
        if !data_buf.is_empty() {
            // Create a decrypted buffer, with the proper size
            let block_size = self.cipher.block_size();
            let mut decrypted = vec![0u8; data_len + block_size];
            // Decrypt bytes
            // TODO: do not unwrap, but try error
            let len = self
                .crypter
                .update(data_buf, &mut decrypted)
                .expect("failed to update AES-GCM decrypter with new data");
            // Add decrypted bytes to output
            plaintext.extend_from_slice(&decrypted[..len]);
        }
        // Read from the tag part to fill the tag buffer
        if !tag_buf.is_empty() {
            self.tag.extend_from_slice(&tag_buf[..tag_len]);
        }
        // Verify the tag once available
        if self.has_tag() {
            // Set the tag
            // TODO: do not unwrap, but try error
            self.crypter
                .set_tag(&self.tag)
                .expect("failed to set AES-GCM decrypter tag for validation");
            // Create a buffer for any remaining data
            let block_size = self.cipher.block_size();
            let mut extra = vec![0u8; block_size];
            // Finalize, write all remaining data
            // TODO: do not unwrap, but try error
            let len = self
                .crypter
                .finalize(&mut extra)
                .expect("failed to finalize AES-GCM decrypter");
            plaintext.extend_from_slice(&extra[..len]);
        }
        let plaintext = if !plaintext.is_empty() {
            Some(plaintext)
        } else {
            None
        };
        (consumed, plaintext)
    }
fn pipe_decrypt ( & mut self , input : & [ u8 ] ) -> ( usize , Option < Vec < u8 > > ) { // Don't allow decrypting more than specified, when tag is obtained if self . has_tag ( ) && ! input . is_empty ( ) { panic ! ( " " ) ; } // How many data and tag bytes we need to read, read chunks from input let data_len = self . len - self . cur ; let tag_len = TAG_LEN - self . tag . len ( ) ; let consumed = min ( data_len + tag_len , input . len ( ) ) ; let ( data_buf , tag_buf ) = input . split_at ( min ( data_len , input . len ( ) ) ) ; self . cur += min ( consumed , self . len ) ; let mut plaintext = Vec :: new ( ) ; // Read from the data buffer if ! data_buf . is_empty ( ) { // Create a decrypted buffer, with the proper size let block_size = self . cipher . block_size ( ) ; let mut decrypted = vec ! [ 0u8 data_len block_size ] ; // Decrypt bytes // TODO: do not unwrap, but try error let len = self . crypter . update ( data_buf , & mut decrypted ) . expect ( " " ) ; // Add decrypted bytes to output plaintext . extend_from_slice ( & decrypted [ .. len ] ) ; } // Read from the tag part to fill the tag buffer if ! tag_buf . is_empty ( ) { self . tag . extend_from_slice ( & tag_buf [ .. tag_len ] ) ; } // Verify the tag once available if self . has_tag ( ) { // Set the tag // TODO: do not unwrap, but try error self . crypter . set_tag ( & self . tag ) . expect ( " " ) ; // Create a buffer for any remaining data let block_size = self . cipher . block_size ( ) ; let mut extra = vec ! [ 0u8 block_size ] ; // Finalize, write all remaining data // TODO: do not unwrap, but try error let len = self . crypter . finalize ( & mut extra ) . expect ( " " ) ; plaintext . extend_from_slice ( & extra [ .. len ] ) ; } let plaintext = if ! plaintext . is_empty ( ) { Some ( plaintext ) } else { None } ; ( consumed , plaintext ) }
Decrypt the given `input` payload using this configured crypter.
Decrypt the given ` input ` payload 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 .