pub struct CommonState {
Show 20 fields pub(crate) negotiated_version: Option<ProtocolVersion>, pub(crate) side: Side, pub(crate) record_layer: RecordLayer, pub(crate) suite: Option<SupportedCipherSuite>, pub(crate) alpn_protocol: Option<Vec<u8>>, pub(crate) aligned_handshake: bool, pub(crate) may_send_application_data: bool, pub(crate) may_receive_application_data: bool, pub(crate) early_traffic: bool, sent_fatal_alert: bool, pub(crate) has_received_close_notify: bool, pub(crate) has_seen_eof: bool, pub(crate) received_middlebox_ccs: u8, pub(crate) peer_certificates: Option<Vec<Certificate>>, message_fragmenter: MessageFragmenter, pub(crate) received_plaintext: ChunkVecBuffer, sendable_plaintext: ChunkVecBuffer, pub(crate) sendable_tls: ChunkVecBuffer, queued_key_update_message: Option<Vec<u8>>, pub(crate) protocol: Protocol,
}
Expand description

Connection state common to both client and server connections.

Fields§

§negotiated_version: Option<ProtocolVersion>§side: Side§record_layer: RecordLayer§suite: Option<SupportedCipherSuite>§alpn_protocol: Option<Vec<u8>>§aligned_handshake: bool§may_send_application_data: bool§may_receive_application_data: bool§early_traffic: bool§sent_fatal_alert: bool§has_received_close_notify: bool

If the peer has signaled end of stream.

§has_seen_eof: bool§received_middlebox_ccs: u8§peer_certificates: Option<Vec<Certificate>>§message_fragmenter: MessageFragmenter§received_plaintext: ChunkVecBuffer§sendable_plaintext: ChunkVecBuffer§sendable_tls: ChunkVecBuffer§queued_key_update_message: Option<Vec<u8>>§protocol: Protocol

Protocol whose key schedule should be used. Unused for TLS < 1.3.

Implementations§

source§

impl CommonState

source

pub(crate) fn new(side: Side) -> Self

source

pub fn wants_write(&self) -> bool

Returns true if the caller should call Connection::write_tls as soon as possible.

source

pub fn is_handshaking(&self) -> bool

Returns true if the connection is currently performing the TLS handshake.

During this time plaintext written to the connection is buffered in memory. After Connection::process_new_packets() has been called, this might start to return false while the final handshake packets still need to be extracted from the connection’s buffers.

source

pub fn peer_certificates(&self) -> Option<&[Certificate]>

Retrieves the certificate chain used by the peer to authenticate.

The order of the certificate chain is as it appears in the TLS protocol: the first certificate relates to the peer, the second certifies the first, the third certifies the second, and so on.

This is made available for both full and resumed handshakes.

For clients, this is the certificate chain of the server.

For servers, this is the certificate chain of the client, if client authentication was completed.

The return value is None until this value is available.

source

pub fn alpn_protocol(&self) -> Option<&[u8]>

Retrieves the protocol agreed with the peer via ALPN.

A return value of None after handshake completion means no protocol was agreed (because no protocols were offered or accepted by the peer).

source

pub fn negotiated_cipher_suite(&self) -> Option<SupportedCipherSuite>

Retrieves the ciphersuite agreed with the peer.

This returns None until the ciphersuite is agreed.

source

pub fn protocol_version(&self) -> Option<ProtocolVersion>

Retrieves the protocol version agreed with the peer.

This returns None until the version is agreed.

source

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

source

pub(crate) fn process_main_protocol<Data>( &mut self, msg: Message, state: Box<dyn State<Data>>, data: &mut Data ) -> Result<Box<dyn State<Data>>, Error>

source

pub(crate) fn send_some_plaintext(&mut self, data: &[u8]) -> usize

Send plaintext application data, fragmenting and encrypting it as it goes out.

If internal buffers are too small, this function will not accept all the data.

source

pub(crate) fn send_early_plaintext(&mut self, data: &[u8]) -> usize

source

pub(crate) fn check_aligned_handshake(&mut self) -> Result<(), Error>

source

pub(crate) fn send_msg_encrypt(&mut self, m: PlainMessage)

Fragment m, encrypt the fragments, and then queue the encrypted fragments for sending.

source

fn send_appdata_encrypt(&mut self, payload: &[u8], limit: Limit) -> usize

Like send_msg_encrypt, but operate on an appdata directly.

source

fn send_single_fragment(&mut self, m: BorrowedPlainMessage<'_>)

source

fn send_plain(&mut self, data: &[u8], limit: Limit) -> usize

Encrypt and send some plaintext data. limit controls whether the per-connection buffer limits apply.

Returns the number of bytes written from data: this might be less than data.len() if buffer limits were exceeded.

source

pub(crate) fn start_outgoing_traffic(&mut self)

source

pub(crate) fn start_traffic(&mut self)

source

pub fn set_buffer_limit(&mut self, limit: Option<usize>)

Sets a limit on the internal buffers used to buffer unsent plaintext (prior to completing the TLS handshake) and unsent TLS records. This limit acts only on application data written through Connection::writer.

By default the limit is 64KB. The limit can be set at any time, even if the current buffer use is higher.

None means no limit applies, and will mean that written data is buffered without bound – it is up to the application to appropriately schedule its plaintext and TLS writes to bound memory usage.

For illustration: Some(1) means a limit of one byte applies: Connection::writer will accept only one byte, encrypt it and add a TLS header. Once this is sent via Connection::write_tls, another byte may be sent.

Internal write-direction buffering

rustls has two buffers whose size are bounded by this setting:

Buffering of unsent plaintext data prior to handshake completion

Calls to Connection::writer before or during the handshake are buffered (up to the limit specified here). Once the handshake completes this data is encrypted and the resulting TLS records are added to the outgoing buffer.

Buffering of outgoing TLS records

This buffer is used to store TLS records that rustls needs to send to the peer. It is used in these two circumstances:

This buffer is emptied by Connection::write_tls.

source

fn flush_plaintext(&mut self)

Send any buffered plaintext. Plaintext is buffered if written during handshake.

source

fn queue_tls_message(&mut self, m: OpaqueMessage)

source

pub(crate) fn send_msg(&mut self, m: Message, must_encrypt: bool)

Send a raw TLS message, fragmenting it if needed.

source

pub(crate) fn take_received_plaintext(&mut self, bytes: Payload)

source

pub(crate) fn start_encryption_tls12( &mut self, secrets: &ConnectionSecrets, side: Side )

source

fn send_warning_alert(&mut self, desc: AlertDescription)

source

pub(crate) fn process_alert( &mut self, alert: &AlertMessagePayload ) -> Result<(), Error>

source

pub(crate) fn send_cert_verify_error_alert(&mut self, err: Error) -> Error

source

pub(crate) fn send_fatal_alert( &mut self, desc: AlertDescription, err: impl Into<Error> ) -> Error

source

pub fn send_close_notify(&mut self)

Queues a close_notify warning alert to be sent in the next Connection::write_tls call. This informs the peer that the connection is being closed.

source

fn send_warning_alert_no_log(&mut self, desc: AlertDescription)

source

pub(crate) fn set_max_fragment_size( &mut self, new: Option<usize> ) -> Result<(), Error>

source

pub(crate) fn get_alpn_protocol(&self) -> Option<&[u8]>

source

pub fn wants_read(&self) -> bool

Returns true if the caller should call Connection::read_tls as soon as possible.

If there is pending plaintext data to read with Connection::reader, this returns false. If your application respects this mechanism, only one full TLS message will be buffered by rustls.

source

pub(crate) fn current_io_state(&self) -> IoState

source

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

source

pub(crate) fn should_update_key( &mut self, key_update_request: &KeyUpdateRequest ) -> Result<bool, Error>

source

pub(crate) fn enqueue_key_update_notification(&mut self)

source

pub(crate) fn perhaps_write_key_update(&mut self)

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.