Skip to main content

RecordEncrypter

Trait RecordEncrypter 

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

Objects with this trait can encrypt TLS records.

Required Methods§

Source

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

Encrypt the given TLS record 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 return value 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 RecordEncrypter 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 payload. Then, to fragment a long payload into chunks of length F, Rustls will first set A := encrypted_payload_len(0) and then supply the payload 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§