Skip to main content

MessageEncrypter

Trait MessageEncrypter 

Source
pub trait MessageEncrypter: Send + Sync {
    // Required methods
    fn encrypt<'a>(
        &mut self,
        msg: EncodedMessage<OutboundPlain<'_>>,
        seq: u64,
        out: &'a mut [u8],
    ) -> Result<EncodedMessage<&'a [u8]>, Error>;
    fn encrypted_payload_len(&self, payload_len: usize) -> usize;
}
Expand description

Objects with this trait can encrypt TLS messages.

Required Methods§

Source

fn encrypt<'a>( &mut self, msg: EncodedMessage<OutboundPlain<'_>>, seq: u64, out: &'a mut [u8], ) -> Result<EncodedMessage<&'a [u8]>, Error>

Encrypt the given TLS message msg into out, using the sequence number seq which can be used to derive a unique Nonce.

The encrypted payload including all framing the ciphersuite requires, such as any explicit nonce, padding and/or authentication tag, is written to the front of out. out must be at least Self::encrypted_payload_len() bytes long. See EncryptBuffer for a convenient wrapper.

The returned message describes the resulting record: its payload borrows the written prefix of out, and its typ and version are what the record header should carry on the wire. Encoding the record header is the caller’s responsibility and implementations of the MessageEncrypter trait must not write it to out themselves.

Source

fn encrypted_payload_len(&self, payload_len: usize) -> usize

Return the length of the ciphertext that results from encrypting plaintext of length payload_len.

For a zero payload_len this should return the minimum overhead for any message. Then, to fragment a long message into chunks of length F, Rustls will first set A := encrypted_payload_len(0) and then supply the message to Self::encrypt() in chunks of length F - A. Each encrypt() is then free to pad or otherwise transform the length at its option.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§