/// Use the channel to encrypt a message shorter than [NOISE_MESSAGE_HEADER_SIZE].
/// Pre-fixes the message with (big-endian) length field and pads the message with
/// 0s before encryption.
/// On success, returns the ciphertext.
Use the channel to encrypt a message shorter than [NOISE_MESSAGE_HEADER_SIZE].
Pre-fixes the message with (big-endian) length field and pads the message with
0s before encryption.
On success, returns the ciphertext.
Use the channel to encrypt a message shorter than [ NOISE_MESSAGE_HEADER_SIZE ] . Pre - fixes the message with ( big - endian ) length field and pads the message with 0s before encryption . On success returns the ciphertext .
pub fn encrypt_message(&mut self, message: &[u8]) -> Result<NoiseEncryptedMessage, Error> {
        if message.len() > NOISE_PLAINTEXT_MAX_SIZE {
            return Err(Error::Noise("Message is too large to encrypt".to_string()));
        }
        let mut output = vec![0u8; NOISE_MESSAGE_HEADER_SIZE + message.len()];
        let message_len: usize = MAC_SIZE + message.len();
        let mut prefixed_message = message_len.to_be_bytes().to_vec();
        prefixed_message.extend_from_slice(message);
        self.transport_state
            .write_message(&prefixed_message, &mut output)
            .map_err(|e| Error::Noise(format!("Header encryption failed: {:?}", e)))?;
        Ok(NoiseEncryptedMessage(output))
    }
pub fn encrypt_message ( & mut self , message : & [ u8 ] ) -> Result < NoiseEncryptedMessage , Error > { if message . len ( ) > NOISE_PLAINTEXT_MAX_SIZE { return Err ( Error :: Noise ( " " . to_string ( ) ) ) ; } let mut output = vec ! [ 0u8 NOISE_MESSAGE_HEADER_SIZE message len ( ) ] ; let message_len : usize = MAC_SIZE + message . len ( ) ; let mut prefixed_message = message_len . to_be_bytes ( ) . to_vec ( ) ; prefixed_message . extend_from_slice ( message ) ; self . transport_state . write_message ( & prefixed_message , & mut output ) . map_err ( | e | Error :: Noise ( format ! ( " " e ) ) ) ? ; Ok ( NoiseEncryptedMessage ( output ) ) }
Use the channel to encrypt a message shorter than [NOISE_MESSAGE_HEADER_SIZE].
Use the channel to encrypt a message shorter than [ NOISE_MESSAGE_HEADER_SIZE ] .
&mut self
message
&[u8]