boost::corosio::openssl_stream

A TLS stream using OpenSSL.

Synopsis

class openssl_stream final
    : public tls_stream

Description

This class wraps an underlying stream satisfying capy::Stream and provides TLS encryption using the OpenSSL library.

Derives from tls_stream to provide a runtime‐polymorphic interface. The TLS operations are implemented as coroutines that orchestrate reads and writes on the underlying stream.

Construction Modes

Two construction modes are supported:

Owning: Pass stream by value. The openssl_stream takes ownership and the stream is moved into internal storage.

Reference: Pass stream by pointer. The openssl_stream does not own the stream; the caller must ensure the stream outlives this object.

Thread Safety

Distinct objects: Safe. Shared objects: Unsafe.

Example

tls_context ctx;
ctx.set_hostname("example.com");
ctx.set_verify_mode(tls_verify_mode::peer);

corosio::tcp_socket sock(ioc);
co_await sock.connect(endpoint);

// Reference mode - sock must outlive tls
corosio::openssl_stream tls(&sock, ctx);
auto [ec] = co_await tls.handshake(openssl_stream::client);

// Or owning mode - tls owns the socket
corosio::openssl_stream tls2(std::move(sock), ctx);

Base Classes

Name Description

tls_stream

Abstract base class for TLS streams.

Enums

Name

Description

handshake_type

Different handshake types.

Member Functions

Name

Description

openssl_stream [constructor]

Constructors

~openssl_stream [destructor] [virtual]

Destructor.

operator= [deleted]

Assignment operators

handshake [virtual]

name [virtual]

next_layer [virtual]

read_some

Initiate an asynchronous read operation.

shutdown [virtual]

write_some

Initiate an asynchronous write operation.

Protected Member Functions

Name

do_read_some [virtual]

do_write_some [virtual]

See Also

tls_stream, wolfssl_stream

Created with MrDocs