Struct RecordLayer

Source
pub(crate) struct RecordLayer {
    message_encrypter: Box<dyn MessageEncrypter>,
    message_decrypter: Box<dyn MessageDecrypter>,
    write_seq_max: u64,
    write_seq: u64,
    read_seq: u64,
    has_decrypted: bool,
    encrypt_state: DirectionState,
    decrypt_state: DirectionState,
    trial_decryption_len: Option<usize>,
}
Expand description

Record layer that tracks decryption and encryption keys.

Fields§

§message_encrypter: Box<dyn MessageEncrypter>§message_decrypter: Box<dyn MessageDecrypter>§write_seq_max: u64§write_seq: u64§read_seq: u64§has_decrypted: bool§encrypt_state: DirectionState§decrypt_state: DirectionState§trial_decryption_len: Option<usize>

Implementations§

Source§

impl RecordLayer

Source

pub(crate) fn new() -> Self

Create new record layer with no keys.

Source

pub(crate) fn decrypt_incoming<'a>( &mut self, encr: InboundOpaqueMessage<'a>, ) -> Result<Option<Decrypted<'a>>, Error>

Decrypt a TLS message.

encr is a decoded message allegedly received from the peer. If it can be decrypted, its decryption is returned. Otherwise, an error is returned.

Source

pub(crate) fn encrypt_outgoing( &mut self, plain: OutboundPlainMessage<'_>, ) -> OutboundOpaqueMessage

Encrypt a TLS message.

plain is a TLS message we’d like to send. This function panics if the requisite keying material hasn’t been established yet.

Source

pub(crate) fn prepare_message_encrypter( &mut self, cipher: Box<dyn MessageEncrypter>, max_messages: u64, )

Prepare to use the given MessageEncrypter for future message encryption. It is not used until you call start_encrypting.

Source

pub(crate) fn prepare_message_decrypter( &mut self, cipher: Box<dyn MessageDecrypter>, )

Prepare to use the given MessageDecrypter for future message decryption. It is not used until you call start_decrypting.

Source

pub(crate) fn start_encrypting(&mut self)

Start using the MessageEncrypter previously provided to the previous call to prepare_message_encrypter.

Source

pub(crate) fn start_decrypting(&mut self)

Start using the MessageDecrypter previously provided to the previous call to prepare_message_decrypter.

Source

pub(crate) fn set_message_encrypter( &mut self, cipher: Box<dyn MessageEncrypter>, max_messages: u64, )

Set and start using the given MessageEncrypter for future outgoing message encryption.

Source

pub(crate) fn set_message_decrypter( &mut self, cipher: Box<dyn MessageDecrypter>, )

Set and start using the given MessageDecrypter for future incoming message decryption.

Source

pub(crate) fn set_message_decrypter_with_trial_decryption( &mut self, cipher: Box<dyn MessageDecrypter>, max_length: usize, )

Set and start using the given MessageDecrypter for future incoming message decryption, and enable “trial decryption” mode for when TLS1.3 0-RTT is attempted but rejected by the server.

Source

pub(crate) fn finish_trial_decryption(&mut self)

Source

pub(crate) fn next_pre_encrypt_action(&self) -> PreEncryptAction

Source

pub(crate) fn pre_encrypt_action(&self, add: u64) -> PreEncryptAction

Return a remedial action when we are near to encrypting too many messages.

add is added to the current sequence number. add as 0 means “the next message processed by encrypt_outgoing

Source

pub(crate) fn is_encrypting(&self) -> bool

Source

pub(crate) fn has_decrypted(&self) -> bool

Return true if we have ever decrypted a message. This is used in place of checking the read_seq since that will be reset on key updates.

Source

pub(crate) fn write_seq(&self) -> u64

Source

pub(crate) fn read_seq(&self) -> u64

Source

pub(crate) fn encrypted_len(&self, payload_len: usize) -> usize

Source

fn doing_trial_decryption(&mut self, requested: usize) -> bool

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.