pub struct SslStream<S> { /* private fields */ }
Expand description

A TLS session over a stream.

Implementations

Creates a new SslStream.

This function performs no IO; the stream will not have performed any part of the handshake with the peer. If the Ssl was configured with SslRef::set_connect_state or SslRef::set_accept_state, the handshake can be performed automatically during the first call to read or write. Otherwise the connect and accept methods can be used to explicitly perform the handshake.

This corresponds to SSL_set_bio.

👎Deprecated since 0.10.32: use Ssl::from_ptr and SslStream::new instead

Constructs an SslStream from a pointer to the underlying OpenSSL SSL struct.

This is useful if the handshake has already been completed elsewhere.

Safety

The caller must ensure the pointer is valid.

Read application data transmitted by a client before handshake completion.

Useful for reducing latency, but vulnerable to replay attacks. Call SslRef::set_accept_state first.

Returns Ok(0) if all early data has been read.

Requires OpenSSL 1.1.1 or LibreSSL 3.4.0 or newer.

This corresponds to SSL_read_early_data.

Send data to the server without blocking on handshake completion.

Useful for reducing latency, but vulnerable to replay attacks. Call SslRef::set_connect_state first.

Requires OpenSSL 1.1.1 or LibreSSL 3.4.0 or newer.

This corresponds to SSL_write_early_data.

Initiates a client-side TLS handshake.

Warning

OpenSSL’s default configuration is insecure. It is highly recommended to use SslConnector rather than Ssl directly, as it manages that configuration.

This corresponds to SSL_connect.

Initiates a server-side TLS handshake.

Warning

OpenSSL’s default configuration is insecure. It is highly recommended to use SslAcceptor rather than Ssl directly, as it manages that configuration.

This corresponds to SSL_accept.

Initiates the handshake.

This will fail if set_accept_state or set_connect_state was not called first.

This corresponds to SSL_do_handshake.

Perform a stateless server-side handshake.

Requires that cookie generation and verification callbacks were set on the SSL context.

Returns Ok(true) if a complete ClientHello containing a valid cookie was read, in which case the handshake should be continued via accept. If a HelloRetryRequest containing a fresh cookie was transmitted, Ok(false) is returned instead. If the handshake cannot proceed at all, Err is returned.

This corresponds to SSL_stateless.

Like read, but returns an ssl::Error rather than an io::Error.

It is particularly useful with a non-blocking socket, where the error value will identify if OpenSSL is waiting on read or write readiness.

This corresponds to SSL_read.

Like write, but returns an ssl::Error rather than an io::Error.

It is particularly useful with a non-blocking socket, where the error value will identify if OpenSSL is waiting on read or write readiness.

This corresponds to SSL_write.

Reads data from the stream, without removing it from the queue.

This corresponds to SSL_peek.

Shuts down the session.

The shutdown process consists of two steps. The first step sends a close notify message to the peer, after which ShutdownResult::Sent is returned. The second step awaits the receipt of a close notify message from the peer, after which ShutdownResult::Received is returned.

While the connection may be closed after the first step, it is recommended to fully shut the session down. In particular, it must be fully shut down if the connection is to be used for further communication in the future.

This corresponds to SSL_shutdown.

Returns the session’s shutdown state.

This corresponds to SSL_get_shutdown.

Sets the session’s shutdown state.

This can be used to tell OpenSSL that the session should be cached even if a full two-way shutdown was not completed.

This corresponds to SSL_set_shutdown.

Returns a shared reference to the underlying stream.

Returns a mutable reference to the underlying stream.

Warning

It is inadvisable to read from or write to the underlying stream as it will most likely corrupt the SSL session.

Returns a shared reference to the Ssl object associated with this stream.

Trait Implementations

Formats the value using the given formatter. Read more
Executes the destructor for this type. Read more
Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
Like read, except that it reads into a slice of buffers. Read more
🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
Read all bytes until EOF in this source, placing them into buf. Read more
Read all bytes until EOF in this source, appending them to buf. Read more
Read the exact number of bytes required to fill buf. Read more
🔬This is a nightly-only experimental API. (read_buf)
Pull some bytes from this source into the specified buffer. Read more
🔬This is a nightly-only experimental API. (read_buf)
Read the exact number of bytes required to fill cursor. Read more
Creates a “by reference” adaptor for this instance of Read. Read more
Transforms this Read instance to an Iterator over its bytes. Read more
Creates an adapter which will chain this stream with another. Read more
Creates an adapter which will read at most limit bytes from it. Read more
Write a buffer into this writer, returning how many bytes were written. Read more
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
Like write, except that it writes from a slice of buffers. Read more
🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
Attempts to write an entire buffer into this writer. Read more
🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
Writes a formatted string into this writer, returning any error encountered. Read more
Creates a “by reference” adapter for this instance of Write. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.