Skip to main content

Session

Trait Session 

pub trait Session:
    Send
    + Sync
    + 'static {
Show 14 methods // Required methods fn initial_keys( &self, version: Version, dst_cid: &ConnectionId, side: Side, ) -> Result<Keys, Error>; fn switch_version( &mut self, version: Version, ) -> Result<(), UnsupportedVersion>; fn handshake_summary(&self) -> Option<NegotiatedTlsParameters>; fn negotiated_alpn(&self) -> Option<&[u8]>; fn peer_certificates(&self) -> Option<Vec<CertificateDer<'static>>>; fn early_crypto(&self) -> Option<(Box<dyn HeaderKey>, Box<dyn PacketKey>)>; fn early_data_accepted(&self) -> Option<bool>; fn is_handshaking(&self) -> bool; fn read_handshake( &mut self, level: SpaceId, buf: &[u8], ) -> Result<bool, Error>; fn transport_parameters(&self) -> Result<Option<TransportParameters>, Error>; fn poll_handshake(&mut self) -> Result<Option<HandshakeEvent>, Error>; fn next_1rtt_keys( &mut self, ) -> Result<Option<KeyPair<Box<dyn PacketKey>>>, Error>; fn is_valid_retry( &self, orig_dst_cid: &ConnectionId, header: &[u8], payload: &[u8], ) -> bool; fn export_keying_material( &self, output: &mut [u8], label: &[u8], context: &[u8], ) -> Result<(), ExportKeyingMaterialError>;
}
Available on crate features quic and std only.
Expand description

A cryptographic session (commonly TLS)

Required Methods§

fn initial_keys( &self, version: Version, dst_cid: &ConnectionId, side: Side, ) -> Result<Keys, Error>

Create the initial set of keys for version given the client’s initial destination ConnectionId.

version is the version of the connection, or the version compatible version negotiation (RFC 9368) is moving it to; the salt and labels follow it (RFC 9369 §3.3).

fn switch_version(&mut self, version: Version) -> Result<(), UnsupportedVersion>

Move the session to a compatible version before any Handshake or 1-RTT key is derived (RFC 9368 §2.3, RFC 9369 §4.1).

Called at most once, before the handshake keys are drained, and only for sessions of a ClientConfig that supports switching. A provider that derives its own packet keys from TLS secrets can re-label them for a compatible version; one that receives finished keys returns UnsupportedVersion.

fn handshake_summary(&self) -> Option<NegotiatedTlsParameters>

What the handshake has settled, when the session has it. None until the connection emits HandshakeDataReady.

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

Borrow negotiated ALPN bytes for diagnostics without allocating a handshake summary.

fn peer_certificates(&self) -> Option<Vec<CertificateDer<'static>>>

The certificate chain the peer presented, if it presented one.

fn early_crypto(&self) -> Option<(Box<dyn HeaderKey>, Box<dyn PacketKey>)>

Get the 0-RTT keys if available (clients only)

On the client side, this method can be used to see if 0-RTT key material is available to start sending data before the protocol handshake has completed.

Returns None if the key material is not available. This might happen if you have not connected to this server before.

fn early_data_accepted(&self) -> Option<bool>

If the 0-RTT-encrypted data has been accepted by the peer

fn is_handshaking(&self) -> bool

Returns true until the connection is fully established.

fn read_handshake(&mut self, level: SpaceId, buf: &[u8]) -> Result<bool, Error>

Read bytes of handshake data

This should be called with the contents of CRYPTO frames. If it returns Ok, the caller should call poll_handshake() to check if the crypto protocol has anything to send to the peer. This method will only return true the first time that handshake data is available. Future calls will always return false.

On success, returns true when handshake_summary() first becomes available.

fn transport_parameters(&self) -> Result<Option<TransportParameters>, Error>

The peer’s QUIC transport parameters

These are only available after the first flight from the peer has been received.

fn poll_handshake(&mut self) -> Result<Option<HandshakeEvent>, Error>

Drain ordered handshake output and directional key changes.

fn next_1rtt_keys( &mut self, ) -> Result<Option<KeyPair<Box<dyn PacketKey>>>, Error>

Compute keys for the next key update

fn is_valid_retry( &self, orig_dst_cid: &ConnectionId, header: &[u8], payload: &[u8], ) -> bool

Verify the integrity of a retry packet

fn export_keying_material( &self, output: &mut [u8], label: &[u8], context: &[u8], ) -> Result<(), ExportKeyingMaterialError>

Fill output with output.len() bytes of keying material derived from the Session’s secrets, using label and context for domain separation.

This function will fail, returning ExportKeyingMaterialError, if the requested output length is too large.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§