pub fn decrypt_message(&mut self, message: &NoiseEncryptedMessage) -> Result<Vec<u8>, Error> {
        // TODO: could be in NoiseEncryptedMessage's constructor?
        if message.0.len() > NOISE_MESSAGE_MAX_SIZE {
            return Err(Error::Noise("Message is too large to decrypt".to_string()));
        }
        if message.0.len() < NOISE_MESSAGE_HEADER_SIZE {
            return Err(Error::Noise("Message is too small to decrypt".to_string()));
        }
        let mut output = vec![0u8; message.0.len()];

        self.transport_state
            .read_message(&message.0, &mut output)
            .map_err(|e| Error::Noise(format!("Failed to decrypt message: {:?}", e)))?;

        // We read the length prefix and the MAC, but we don't care about any of both (we use a
        // vec, and the MAC is checked by Snow).
        // TODO: bench this against truncating and reverse-then-pop-then-reverse
        Ok(output
            .drain(LENGTH_PREFIX_SIZE..output.len() - MAC_SIZE)
            .collect())
    }
/// Get plaintext bytes from a valid Noise-encrypted message
Get plaintext bytes from a valid Noise-encrypted message
Get plaintext bytes from a valid Noise - encrypted message
pub fn decrypt_message(&mut self, message: &NoiseEncryptedMessage) -> Result<Vec<u8>, Error> {
        // TODO: could be in NoiseEncryptedMessage's constructor?
        if message.0.len() > NOISE_MESSAGE_MAX_SIZE {
            return Err(Error::Noise("Message is too large to decrypt".to_string()));
        }
        if message.0.len() < NOISE_MESSAGE_HEADER_SIZE {
            return Err(Error::Noise("Message is too small to decrypt".to_string()));
        }
        let mut output = vec![0u8; message.0.len()];
        self.transport_state
            .read_message(&message.0, &mut output)
            .map_err(|e| Error::Noise(format!("Failed to decrypt message: {:?}", e)))?;
        // We read the length prefix and the MAC, but we don't care about any of both (we use a
        // vec, and the MAC is checked by Snow).
        // TODO: bench this against truncating and reverse-then-pop-then-reverse
        Ok(output
            .drain(LENGTH_PREFIX_SIZE..output.len() - MAC_SIZE)
            .collect())
    }
pub fn decrypt_message ( & mut self , message : & NoiseEncryptedMessage ) -> Result < Vec < u8 > , Error > { // TODO: could be in NoiseEncryptedMessage's constructor? if message . 0 . len ( ) > NOISE_MESSAGE_MAX_SIZE { return Err ( Error :: Noise ( " " . to_string ( ) ) ) ; } if message . 0 . len ( ) < NOISE_MESSAGE_HEADER_SIZE { return Err ( Error :: Noise ( " " . to_string ( ) ) ) ; } let mut output = vec ! [ 0u8 message 0 len ( ) ] ; self . transport_state . read_message ( & message . 0 , & mut output ) . map_err ( | e | Error :: Noise ( format ! ( " " e ) ) ) ? ; // We read the length prefix and the MAC, but we don't care about any of both (we use a // vec, and the MAC is checked by Snow). // TODO: bench this against truncating and reverse-then-pop-then-reverse Ok ( output . drain ( LENGTH_PREFIX_SIZE .. output . len ( ) - MAC_SIZE ) . collect ( ) ) }
Get plaintext bytes from a valid Noise-encrypted message
Get plaintext bytes from a valid Noise - encrypted message
&mut self
message
&NoiseEncryptedMessage
&mut self
message
&NoiseEncryptedMessage