Botan  2.15.0
Crypto and TLS for C++11
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
Botan::TLS::Stream< StreamLayer, ChannelT > Class Template Reference

boost::asio compatible SSL/TLS stream More...

#include <asio_stream.h>

Classes

class  StreamCore
 Helper class that implements Botan::TLS::Callbacks. More...
 

Public Member Functions

bool shutdown_received () const
 Indicates whether a close_notify alert has been received from the peer. More...
 
construction
template<typename... Args>
 Stream (Context &context, Args &&... args)
 Construct a new Stream. More...
 
template<typename Arg >
 Stream (Arg &&arg, Context &context)
 Construct a new Stream. More...
 
virtual ~Stream ()=default
 
 Stream (Stream &&other)=default
 
Streamoperator= (Stream &&other)=default
 
 Stream (const Stream &other)=delete
 
Streamoperator= (const Stream &other)=delete
 
configuration and callback setters
void set_verify_callback (Context::Verify_Callback callback)
 Override the tls_verify_cert_chain callback. More...
 
void set_verify_callback (Context::Verify_Callback callback, boost::system::error_code &ec)
 Compatibility overload of set_verify_callback. More...
 
void set_verify_depth (int depth)
 
void set_verify_depth (int depth, boost::system::error_code &ec)
 
template<typename verify_mode >
void set_verify_mode (verify_mode v)
 
template<typename verify_mode >
void set_verify_mode (verify_mode v, boost::system::error_code &ec)
 
shutdown methods
void shutdown (boost::system::error_code &ec)
 Shut down SSL on the stream. More...
 
void shutdown ()
 Shut down SSL on the stream. More...
 
template<typename ShutdownHandler >
void async_shutdown (ShutdownHandler &&handler)
 Asynchronously shut down SSL on the stream. More...
 
I/O methods
template<typename MutableBufferSequence >
std::size_t read_some (const MutableBufferSequence &buffers, boost::system::error_code &ec)
 Read some data from the stream. More...
 
template<typename MutableBufferSequence >
std::size_t read_some (const MutableBufferSequence &buffers)
 Read some data from the stream. More...
 
template<typename ConstBufferSequence >
std::size_t write_some (const ConstBufferSequence &buffers, boost::system::error_code &ec)
 Write some data to the stream. More...
 
template<typename ConstBufferSequence >
std::size_t write_some (const ConstBufferSequence &buffers)
 Write some data to the stream. More...
 
template<typename ConstBufferSequence , typename WriteHandler >
auto async_write_some (const ConstBufferSequence &buffers, WriteHandler &&handler) -> BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler, void(boost::system::error_code, std::size_t))
 Start an asynchronous write. The function call always returns immediately. More...
 
template<typename MutableBufferSequence , typename ReadHandler >
auto async_read_some (const MutableBufferSequence &buffers, ReadHandler &&handler) -> BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler, void(boost::system::error_code, std::size_t))
 Start an asynchronous read. The function call always returns immediately. More...
 

Protected Member Functions

void consume_send_buffer (std::size_t bytesConsumed)
 Mark bytes in the send buffer as consumed, removing them from the buffer. More...
 
template<typename MutableBufferSequence >
std::size_t copy_received_data (MutableBufferSequence buffers)
 Copy decrypted data into the user-provided buffer. More...
 
bool has_data_to_send () const
 Check if encrypted data is available in the send buffer. More...
 
bool has_received_data () const
 Check if decrypted data is available in the receive buffer. More...
 
const boost::asio::mutable_buffer & input_buffer ()
 
void process_encrypted_data (const boost::asio::const_buffer &read_buffer, boost::system::error_code &ec)
 Pass encrypted data to the native handle for processing. More...
 
boost::asio::const_buffer send_buffer () const
 
size_t send_pending_encrypted_data (boost::system::error_code &ec)
 Synchronously write encrypted data from the send buffer to the next layer. More...
 
void set_shutdown_received ()
 
template<class T = ChannelT>
std::enable_if<!std::is_same< Channel, T >::value >::type setup_native_handle (Connection_Side, boost::system::error_code &)
 
template<class T = ChannelT>
std::enable_if< std::is_same< Channel, T >::value >::type setup_native_handle (Connection_Side side, boost::system::error_code &ec)
 Create the native handle. More...
 
template<typename ConstBufferSequence >
void tls_encrypt (const ConstBufferSequence &buffers, boost::system::error_code &ec)
 Pass plaintext data to the native handle for processing. More...
 
template<typename Fun >
void try_with_error_code (Fun f, boost::system::error_code &ec)
 Catch exceptions and set an error_code. More...
 

Protected Attributes

Contextm_context
 
StreamCore m_core
 
const boost::asio::mutable_buffer m_input_buffer
 
std::vector< uint8_t > m_input_buffer_space
 
std::unique_ptr< ChannelT > m_native_handle
 
StreamLayer m_nextLayer
 
boost::beast::flat_buffer m_receive_buffer
 
boost::beast::flat_buffer m_send_buffer
 
bool m_shutdown_received
 

Friends

template<class H , class S , class A >
class detail::AsyncHandshakeOperation
 
template<class H , class S , class M , class A >
class detail::AsyncReadOperation
 
template<class H , class S , class A >
class detail::AsyncWriteOperation
 

boost::asio accessor methods

using next_layer_type = typename std::remove_reference< StreamLayer >::type
 
using lowest_layer_type = typename next_layer_type::lowest_layer_type
 
using executor_type = typename next_layer_type::executor_type
 
using native_handle_type = typename std::add_pointer< ChannelT >::type
 
const next_layer_typenext_layer () const
 
next_layer_typenext_layer ()
 
lowest_layer_typelowest_layer ()
 
const lowest_layer_typelowest_layer () const
 
executor_type get_executor () noexcept
 
native_handle_type native_handle ()
 

handshake methods

const ConstBufferSequence & buffers
 
const ConstBufferSequence BufferedHandshakeHandler && handler
 
void handshake (Connection_Side side)
 Performs SSL handshaking. More...
 
void handshake (Connection_Side side, boost::system::error_code &ec)
 Performs SSL handshaking. More...
 
template<typename HandshakeHandler >
auto async_handshake (Connection_Side side, HandshakeHandler &&handler) ->
 Starts an asynchronous SSL handshake. More...
 
template<typename ConstBufferSequence , typename BufferedHandshakeHandler >
 BOOST_ASIO_INITFN_RESULT_TYPE (BufferedHandshakeHandler, void(boost::system::error_code, std::size_t)) async_handshake(Connection_Side side
 
 BOOST_ASIO_HANDSHAKE_HANDLER_CHECK (BufferedHandshakeHandler, handler) type_check
 
throw Not_Implemented ("buffered async handshake is not implemented")
 

Detailed Description

template<class StreamLayer, class ChannelT = Channel>
class Botan::TLS::Stream< StreamLayer, ChannelT >

boost::asio compatible SSL/TLS stream

Template Parameters
StreamLayertype of the next layer, usually a network socket
ChannelTtype of the native_handle, defaults to Botan::TLS::Channel, only needed for testing purposes

Definition at line 48 of file asio_stream.h.

Member Typedef Documentation

◆ executor_type

template<class StreamLayer , class ChannelT = Channel>
using Botan::TLS::Stream< StreamLayer, ChannelT >::executor_type = typename next_layer_type::executor_type

Definition at line 126 of file asio_stream.h.

◆ lowest_layer_type

template<class StreamLayer , class ChannelT = Channel>
using Botan::TLS::Stream< StreamLayer, ChannelT >::lowest_layer_type = typename next_layer_type::lowest_layer_type

Definition at line 120 of file asio_stream.h.

◆ native_handle_type

template<class StreamLayer , class ChannelT = Channel>
using Botan::TLS::Stream< StreamLayer, ChannelT >::native_handle_type = typename std::add_pointer<ChannelT>::type

Definition at line 129 of file asio_stream.h.

◆ next_layer_type

template<class StreamLayer , class ChannelT = Channel>
using Botan::TLS::Stream< StreamLayer, ChannelT >::next_layer_type = typename std::remove_reference<StreamLayer>::type

Definition at line 104 of file asio_stream.h.

Constructor & Destructor Documentation

◆ Stream() [1/4]

template<class StreamLayer , class ChannelT = Channel>
template<typename... Args>
Botan::TLS::Stream< StreamLayer, ChannelT >::Stream ( Context context,
Args &&...  args 
)
inlineexplicit

Construct a new Stream.

Parameters
contextThe context parameter is used to set up the underlying native handle. Using code is responsible for lifetime management of the context and must ensure that it is available for the lifetime of the stream.
argsArguments to be forwarded to the construction of the next layer.

Definition at line 63 of file asio_stream.h.

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::async_read_some().

64  : m_context(context)
65  , m_nextLayer(std::forward<Args>(args)...)
66  , m_core(*this)
67  , m_shutdown_received(false)
70  {}
const boost::asio::mutable_buffer m_input_buffer
Definition: asio_stream.h:820
StreamLayer m_nextLayer
Definition: asio_stream.h:808
StreamCore m_core
Definition: asio_stream.h:813
Context & m_context
Definition: asio_stream.h:807
std::vector< uint8_t > m_input_buffer_space
Definition: asio_stream.h:819

◆ Stream() [2/4]

template<class StreamLayer , class ChannelT = Channel>
template<typename Arg >
Botan::TLS::Stream< StreamLayer, ChannelT >::Stream ( Arg &&  arg,
Context context 
)
inlineexplicit

Construct a new Stream.

Convenience overload for boost::asio::ssl::stream compatibility.

Parameters
argThis argument is forwarded to the construction of the next layer.
contextThe context parameter is used to set up the underlying native handle. Using code is responsible for lifetime management of the context and must ensure that is available for the lifetime of the stream.

Definition at line 83 of file asio_stream.h.

84  : m_context(context)
85  , m_nextLayer(std::forward<Arg>(arg))
86  , m_core(*this)
87  , m_shutdown_received(false)
90  {}
const boost::asio::mutable_buffer m_input_buffer
Definition: asio_stream.h:820
StreamLayer m_nextLayer
Definition: asio_stream.h:808
StreamCore m_core
Definition: asio_stream.h:813
Context & m_context
Definition: asio_stream.h:807
std::vector< uint8_t > m_input_buffer_space
Definition: asio_stream.h:819

◆ ~Stream()

template<class StreamLayer , class ChannelT = Channel>
virtual Botan::TLS::Stream< StreamLayer, ChannelT >::~Stream ( )
virtualdefault

◆ Stream() [3/4]

template<class StreamLayer , class ChannelT = Channel>
Botan::TLS::Stream< StreamLayer, ChannelT >::Stream ( Stream< StreamLayer, ChannelT > &&  other)
default

◆ Stream() [4/4]

template<class StreamLayer , class ChannelT = Channel>
Botan::TLS::Stream< StreamLayer, ChannelT >::Stream ( const Stream< StreamLayer, ChannelT > &  other)
delete

Member Function Documentation

◆ async_handshake()

template<class StreamLayer , class ChannelT = Channel>
template<typename HandshakeHandler >
auto Botan::TLS::Stream< StreamLayer, ChannelT >::async_handshake ( Connection_Side  side,
HandshakeHandler &&  handler 
) ->
inline

Starts an asynchronous SSL handshake.

This function call always returns immediately.

Parameters
sideThe type of handshaking to be performed, i.e. as a client or as a server.
handlerThe handler to be called when the handshake operation completes. The equivalent function signature of the handler must be: void(boost::system::error_code)

Definition at line 264 of file asio_stream.h.

References Botan::TLS::Stream< StreamLayer, ChannelT >::BOOST_ASIO_HANDSHAKE_HANDLER_CHECK(), Botan::TLS::Stream< StreamLayer, ChannelT >::handler, init, and Botan::TLS::Stream< StreamLayer, ChannelT >::setup_native_handle().

266  {
267  BOOST_ASIO_HANDSHAKE_HANDLER_CHECK(HandshakeHandler, handler) type_check;
268 
269  boost::system::error_code ec;
270  setup_native_handle(side, ec);
271  // If ec is set by setup_native_handle, the AsyncHandshakeOperation created below will do nothing but call the
272  // handler with the error_code set appropriately - no need to early return here.
273 
274  boost::asio::async_completion<HandshakeHandler, void(boost::system::error_code)> init(handler);
275 
277  op{std::move(init.completion_handler), *this, ec};
278 
279  return init.result.get();
280  }
std::enable_if<!std::is_same< Channel, T >::value >::type setup_native_handle(Connection_Side, boost::system::error_code &)
Definition: asio_stream.h:675
BOOST_ASIO_HANDSHAKE_HANDLER_CHECK(BufferedHandshakeHandler, handler) type_check
MechanismType type
const ConstBufferSequence BufferedHandshakeHandler && handler
Definition: asio_stream.h:288
int(* init)(CTX *)
Stream(Context &context, Args &&... args)
Construct a new Stream.
Definition: asio_stream.h:63

◆ async_read_some()

template<class StreamLayer , class ChannelT = Channel>
template<typename MutableBufferSequence , typename ReadHandler >
auto Botan::TLS::Stream< StreamLayer, ChannelT >::async_read_some ( const MutableBufferSequence &  buffers,
ReadHandler &&  handler 
) -> BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler, void(boost::system::error_code, std::size_t))
inline

Start an asynchronous read. The function call always returns immediately.

Parameters
buffersThe buffers into which the data will be read. Although the buffers object may be copied as necessary, ownership of the underlying buffers is retained by the caller, which must guarantee that they remain valid until the handler is called.
handlerThe handler to be called when the read operation completes. The equivalent function signature of the handler must be: void(boost::system::error_code, std::size_t)

Definition at line 545 of file asio_stream.h.

References Botan::TLS::Stream< StreamLayer, ChannelT >::buffers, Botan::TLS::Stream< StreamLayer, ChannelT >::handler, init, and Botan::TLS::Stream< StreamLayer, ChannelT >::Stream().

548  {
549  BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
550 
551  boost::asio::async_completion<ReadHandler, void(boost::system::error_code, std::size_t)> init(handler);
552 
554  op{std::move(init.completion_handler), *this, buffers};
555  return init.result.get();
556  }
const ConstBufferSequence & buffers
Definition: asio_stream.h:286
MechanismType type
const ConstBufferSequence BufferedHandshakeHandler && handler
Definition: asio_stream.h:288
int(* init)(CTX *)
Stream(Context &context, Args &&... args)
Construct a new Stream.
Definition: asio_stream.h:63

◆ async_shutdown()

template<class StreamLayer , class ChannelT = Channel>
template<typename ShutdownHandler >
void Botan::TLS::Stream< StreamLayer, ChannelT >::async_shutdown ( ShutdownHandler &&  handler)
inline

Asynchronously shut down SSL on the stream.

This function call always returns immediately.

Note that this can be used in reaction of a received shutdown alert from the peer.

Parameters
handlerThe handler to be called when the shutdown operation completes. The equivalent function signature of the handler must be: void(boost::system::error_code)

Definition at line 373 of file asio_stream.h.

References Botan::TLS::Stream< StreamLayer, ChannelT >::handler, init, Botan::TLS::Stream< StreamLayer, ChannelT >::native_handle(), Botan::TLS::Stream< StreamLayer, ChannelT >::send_buffer(), and Botan::TLS::Stream< StreamLayer, ChannelT >::try_with_error_code().

374  {
375  boost::system::error_code ec;
377  {
378  native_handle()->close();
379  }, ec);
380  // If ec is set by native_handle->close(), the AsyncWriteOperation created below will do nothing but call the
381  // handler with the error_code set appropriately - no need to early return here.
382 
383  using ShutdownHandlerWrapper = Wrapper<ShutdownHandler>;
384 
385  ShutdownHandlerWrapper w(std::forward<ShutdownHandler>(handler));
386  BOOST_ASIO_SHUTDOWN_HANDLER_CHECK(ShutdownHandler, w) type_check;
387 
388  boost::asio::async_completion<ShutdownHandlerWrapper, void(boost::system::error_code, std::size_t)>
389  init(w);
390 
392  op{std::move(init.completion_handler), *this, boost::asio::buffer_size(send_buffer())};
393 
394  return init.result.get();
395  }
MechanismType type
boost::asio::const_buffer send_buffer() const
Definition: asio_stream.h:645
const ConstBufferSequence BufferedHandshakeHandler && handler
Definition: asio_stream.h:288
native_handle_type native_handle()
Definition: asio_stream.h:130
int(* init)(CTX *)
Stream(Context &context, Args &&... args)
Construct a new Stream.
Definition: asio_stream.h:63
void try_with_error_code(Fun f, boost::system::error_code &ec)
Catch exceptions and set an error_code.
Definition: asio_stream.h:782

◆ async_write_some()

template<class StreamLayer , class ChannelT = Channel>
template<typename ConstBufferSequence , typename WriteHandler >
auto Botan::TLS::Stream< StreamLayer, ChannelT >::async_write_some ( const ConstBufferSequence &  buffers,
WriteHandler &&  handler 
) -> BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler, void(boost::system::error_code, std::size_t))
inline

Start an asynchronous write. The function call always returns immediately.

Parameters
buffersThe data to be written.
handlerThe handler to be called when the write operation completes. Copies will be made of the handler as required. The equivalent function signature of the handler must be: void(boost::system::error_code, std::size_t)

Definition at line 508 of file asio_stream.h.

References Botan::TLS::Stream< StreamLayer, ChannelT >::buffers, Botan::TLS::Stream< StreamLayer, ChannelT >::consume_send_buffer(), Botan::TLS::Stream< StreamLayer, ChannelT >::handler, init, Botan::TLS::Stream< StreamLayer, ChannelT >::m_send_buffer, and Botan::TLS::Stream< StreamLayer, ChannelT >::tls_encrypt().

511  {
512  BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
513 
514  boost::asio::async_completion<WriteHandler, void(boost::system::error_code, std::size_t)> init(handler);
515 
516  boost::system::error_code ec;
517  tls_encrypt(buffers, ec);
518  if(ec)
519  {
520  // we cannot be sure how many bytes were committed here so clear the send_buffer and let the
521  // AsyncWriteOperation call the handler with the error_code set
524  op{std::move(init.completion_handler), *this, std::size_t(0), ec};
525  return init.result.get();
526  }
527 
529  op{std::move(init.completion_handler), *this, boost::asio::buffer_size(buffers)};
530 
531  return init.result.get();
532  }
const ConstBufferSequence & buffers
Definition: asio_stream.h:286
MechanismType type
const ConstBufferSequence BufferedHandshakeHandler && handler
Definition: asio_stream.h:288
boost::beast::flat_buffer m_send_buffer
Definition: asio_stream.h:811
void tls_encrypt(const ConstBufferSequence &buffers, boost::system::error_code &ec)
Pass plaintext data to the native handle for processing.
Definition: asio_stream.h:747
int(* init)(CTX *)
Stream(Context &context, Args &&... args)
Construct a new Stream.
Definition: asio_stream.h:63
void consume_send_buffer(std::size_t bytesConsumed)
Mark bytes in the send buffer as consumed, removing them from the buffer.
Definition: asio_stream.h:667

◆ BOOST_ASIO_HANDSHAKE_HANDLER_CHECK()

template<class StreamLayer , class ChannelT = Channel>
Botan::TLS::Stream< StreamLayer, ChannelT >::BOOST_ASIO_HANDSHAKE_HANDLER_CHECK ( BufferedHandshakeHandler  ,
handler   
)

◆ BOOST_ASIO_INITFN_RESULT_TYPE()

template<class StreamLayer , class ChannelT = Channel>
template<typename ConstBufferSequence , typename BufferedHandshakeHandler >
Botan::TLS::Stream< StreamLayer, ChannelT >::BOOST_ASIO_INITFN_RESULT_TYPE ( BufferedHandshakeHandler  ,
void(boost::system::error_code, std::size_t)   
)
Exceptions
Not_Implemented

◆ consume_send_buffer()

template<class StreamLayer , class ChannelT = Channel>
void Botan::TLS::Stream< StreamLayer, ChannelT >::consume_send_buffer ( std::size_t  bytesConsumed)
inlineprotected

◆ copy_received_data()

template<class StreamLayer , class ChannelT = Channel>
template<typename MutableBufferSequence >
std::size_t Botan::TLS::Stream< StreamLayer, ChannelT >::copy_received_data ( MutableBufferSequence  buffers)
inlineprotected

Copy decrypted data into the user-provided buffer.

Definition at line 652 of file asio_stream.h.

References Botan::TLS::Stream< StreamLayer, ChannelT >::buffers, and Botan::TLS::Stream< StreamLayer, ChannelT >::m_receive_buffer.

Referenced by Botan::TLS::detail::AsyncReadOperation< Handler, Stream, MutableBufferSequence, Allocator >::operator()(), and Botan::TLS::Stream< StreamLayer, ChannelT >::read_some().

653  {
654  // Note: It would be nice to avoid this buffer copy. This could be achieved by equipping the StreamCore with
655  // the user's desired target buffer once a read is started, and reading directly into that buffer in tls_record
656  // received. However, we need to deal with the case that the receive buffer provided by the caller is smaller
657  // than the decrypted record, so this optimization might not be worth the additional complexity.
658  const auto copiedBytes = boost::asio::buffer_copy(buffers, m_receive_buffer.data());
659  m_receive_buffer.consume(copiedBytes);
660  return copiedBytes;
661  }
const ConstBufferSequence & buffers
Definition: asio_stream.h:286
boost::beast::flat_buffer m_receive_buffer
Definition: asio_stream.h:810

◆ get_executor()

template<class StreamLayer , class ChannelT = Channel>
executor_type Botan::TLS::Stream< StreamLayer, ChannelT >::get_executor ( )
inlinenoexcept

Definition at line 127 of file asio_stream.h.

References Botan::TLS::Stream< StreamLayer, ChannelT >::m_nextLayer.

127 { return m_nextLayer.get_executor(); }
StreamLayer m_nextLayer
Definition: asio_stream.h:808

◆ handshake() [1/2]

template<class StreamLayer , class ChannelT = Channel>
void Botan::TLS::Stream< StreamLayer, ChannelT >::handshake ( Connection_Side  side)
inline

Performs SSL handshaking.

The function call will block until handshaking is complete or an error occurs.

Parameters
sideThe type of handshaking to be performed, i.e. as a client or as a server.
Exceptions
boost::system::system_errorif error occured

Definition at line 217 of file asio_stream.h.

218  {
219  boost::system::error_code ec;
220  handshake(side, ec);
221  boost::asio::detail::throw_error(ec, "handshake");
222  }
void handshake(Connection_Side side)
Performs SSL handshaking.
Definition: asio_stream.h:217

◆ handshake() [2/2]

template<class StreamLayer , class ChannelT = Channel>
void Botan::TLS::Stream< StreamLayer, ChannelT >::handshake ( Connection_Side  side,
boost::system::error_code &  ec 
)
inline

Performs SSL handshaking.

The function call will block until handshaking is complete or an error occurs.

Parameters
sideThe type of handshaking to be performed, i.e. as a client or as a server.
ecSet to indicate what error occurred, if any.

Definition at line 232 of file asio_stream.h.

References Botan::TLS::CLIENT, Botan::TLS::Stream< StreamLayer, ChannelT >::input_buffer(), Botan::TLS::Stream< StreamLayer, ChannelT >::m_nextLayer, Botan::TLS::Stream< StreamLayer, ChannelT >::native_handle(), Botan::TLS::Stream< StreamLayer, ChannelT >::process_encrypted_data(), Botan::TLS::Stream< StreamLayer, ChannelT >::send_pending_encrypted_data(), and Botan::TLS::Stream< StreamLayer, ChannelT >::setup_native_handle().

233  {
234  setup_native_handle(side, ec);
235 
236  if(side == CLIENT)
237  {
238  // send client hello, which was written to the send buffer on client instantiation
240  }
241 
242  while(!native_handle()->is_active() && !ec)
243  {
244  boost::asio::const_buffer read_buffer{input_buffer().data(), m_nextLayer.read_some(input_buffer(), ec)};
245  if(ec)
246  { return; }
247 
248  process_encrypted_data(read_buffer, ec);
249 
251  }
252  }
size_t send_pending_encrypted_data(boost::system::error_code &ec)
Synchronously write encrypted data from the send buffer to the next layer.
Definition: asio_stream.h:724
std::enable_if<!std::is_same< Channel, T >::value >::type setup_native_handle(Connection_Side, boost::system::error_code &)
Definition: asio_stream.h:675
StreamLayer m_nextLayer
Definition: asio_stream.h:808
void process_encrypted_data(const boost::asio::const_buffer &read_buffer, boost::system::error_code &ec)
Pass encrypted data to the native handle for processing.
Definition: asio_stream.h:772
const boost::asio::mutable_buffer & input_buffer()
Definition: asio_stream.h:644
native_handle_type native_handle()
Definition: asio_stream.h:130

◆ has_data_to_send()

template<class StreamLayer , class ChannelT = Channel>
bool Botan::TLS::Stream< StreamLayer, ChannelT >::has_data_to_send ( ) const
inlineprotected

◆ has_received_data()

template<class StreamLayer , class ChannelT = Channel>
bool Botan::TLS::Stream< StreamLayer, ChannelT >::has_received_data ( ) const
inlineprotected

Check if decrypted data is available in the receive buffer.

Definition at line 648 of file asio_stream.h.

References Botan::TLS::Stream< StreamLayer, ChannelT >::m_receive_buffer.

Referenced by Botan::TLS::detail::AsyncReadOperation< Handler, Stream, MutableBufferSequence, Allocator >::operator()(), and Botan::TLS::Stream< StreamLayer, ChannelT >::read_some().

648 { return m_receive_buffer.size() > 0; }
boost::beast::flat_buffer m_receive_buffer
Definition: asio_stream.h:810

◆ input_buffer()

template<class StreamLayer , class ChannelT = Channel>
const boost::asio::mutable_buffer& Botan::TLS::Stream< StreamLayer, ChannelT >::input_buffer ( )
inlineprotected

◆ lowest_layer() [1/2]

template<class StreamLayer , class ChannelT = Channel>
lowest_layer_type& Botan::TLS::Stream< StreamLayer, ChannelT >::lowest_layer ( )
inline

Definition at line 122 of file asio_stream.h.

References Botan::TLS::Stream< StreamLayer, ChannelT >::m_nextLayer.

122 { return m_nextLayer.lowest_layer(); }
StreamLayer m_nextLayer
Definition: asio_stream.h:808

◆ lowest_layer() [2/2]

template<class StreamLayer , class ChannelT = Channel>
const lowest_layer_type& Botan::TLS::Stream< StreamLayer, ChannelT >::lowest_layer ( ) const
inline

Definition at line 123 of file asio_stream.h.

References Botan::TLS::Stream< StreamLayer, ChannelT >::m_nextLayer.

123 { return m_nextLayer.lowest_layer(); }
StreamLayer m_nextLayer
Definition: asio_stream.h:808

◆ native_handle()

template<class StreamLayer , class ChannelT = Channel>
native_handle_type Botan::TLS::Stream< StreamLayer, ChannelT >::native_handle ( )
inline

◆ next_layer() [1/2]

template<class StreamLayer , class ChannelT = Channel>
const next_layer_type& Botan::TLS::Stream< StreamLayer, ChannelT >::next_layer ( ) const
inline

◆ next_layer() [2/2]

template<class StreamLayer , class ChannelT = Channel>
next_layer_type& Botan::TLS::Stream< StreamLayer, ChannelT >::next_layer ( )
inline

Definition at line 107 of file asio_stream.h.

References Botan::TLS::Stream< StreamLayer, ChannelT >::m_nextLayer.

107 { return m_nextLayer; }
StreamLayer m_nextLayer
Definition: asio_stream.h:808

◆ Not_Implemented()

template<class StreamLayer , class ChannelT = Channel>
throw Botan::TLS::Stream< StreamLayer, ChannelT >::Not_Implemented ( "buffered async handshake is not implemented"  )

◆ operator=() [1/2]

template<class StreamLayer , class ChannelT = Channel>
Stream& Botan::TLS::Stream< StreamLayer, ChannelT >::operator= ( Stream< StreamLayer, ChannelT > &&  other)
default

◆ operator=() [2/2]

template<class StreamLayer , class ChannelT = Channel>
Stream& Botan::TLS::Stream< StreamLayer, ChannelT >::operator= ( const Stream< StreamLayer, ChannelT > &  other)
delete

◆ process_encrypted_data()

template<class StreamLayer , class ChannelT = Channel>
void Botan::TLS::Stream< StreamLayer, ChannelT >::process_encrypted_data ( const boost::asio::const_buffer &  read_buffer,
boost::system::error_code &  ec 
)
inlineprotected

Pass encrypted data to the native handle for processing.

If an exception occurs while processing the data, an error code will be set.

Parameters
read_bufferInput buffer containing the encrypted data.
ecSet to indicate what error occurred, if any.

Definition at line 772 of file asio_stream.h.

References Botan::TLS::Stream< StreamLayer, ChannelT >::native_handle(), and Botan::TLS::Stream< StreamLayer, ChannelT >::try_with_error_code().

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::handshake(), Botan::TLS::detail::AsyncReadOperation< Handler, Stream, MutableBufferSequence, Allocator >::operator()(), Botan::TLS::detail::AsyncHandshakeOperation< Handler, Stream, Allocator >::operator()(), and Botan::TLS::Stream< StreamLayer, ChannelT >::read_some().

773  {
775  {
776  native_handle()->received_data(static_cast<const uint8_t*>(read_buffer.data()), read_buffer.size());
777  }, ec);
778  }
native_handle_type native_handle()
Definition: asio_stream.h:130
void try_with_error_code(Fun f, boost::system::error_code &ec)
Catch exceptions and set an error_code.
Definition: asio_stream.h:782

◆ read_some() [1/2]

template<class StreamLayer , class ChannelT = Channel>
template<typename MutableBufferSequence >
std::size_t Botan::TLS::Stream< StreamLayer, ChannelT >::read_some ( const MutableBufferSequence &  buffers,
boost::system::error_code &  ec 
)
inline

Read some data from the stream.

The function call will block until one or more bytes of data has been read successfully, or until an error occurs.

Parameters
buffersThe buffers into which the data will be read.
ecSet to indicate what error occurred, if any. Specifically, StreamTruncated will be set if the peer has closed the connection but did not properly shut down the SSL connection.
Returns
The number of bytes read. Returns 0 if an error occurred.

Definition at line 413 of file asio_stream.h.

References Botan::TLS::Stream< StreamLayer, ChannelT >::buffers, Botan::TLS::Stream< StreamLayer, ChannelT >::copy_received_data(), Botan::TLS::Stream< StreamLayer, ChannelT >::has_received_data(), Botan::TLS::Stream< StreamLayer, ChannelT >::input_buffer(), Botan::TLS::Stream< StreamLayer, ChannelT >::m_nextLayer, Botan::TLS::Stream< StreamLayer, ChannelT >::process_encrypted_data(), Botan::TLS::Stream< StreamLayer, ChannelT >::shutdown_received(), and Botan::TLS::StreamTruncated.

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::read_some().

415  {
416  if(has_received_data())
417  { return copy_received_data(buffers); }
418 
419  boost::asio::const_buffer read_buffer{input_buffer().data(), m_nextLayer.read_some(input_buffer(), ec)};
420  if(ec)
421  { return 0; }
422 
423  process_encrypted_data(read_buffer, ec);
424 
425  if(ec) // something went wrong in process_encrypted_data()
426  { return 0; }
427 
428  if(shutdown_received())
429  {
430  // we just received a 'close_notify' from the peer and don't expect any more data
431  ec = boost::asio::error::eof;
432  }
433  else if(ec == boost::asio::error::eof)
434  {
435  // we did not expect this disconnection from the peer
437  }
438 
439  return !ec ? copy_received_data(buffers) : 0;
440  }
const ConstBufferSequence & buffers
Definition: asio_stream.h:286
bool shutdown_received() const
Indicates whether a close_notify alert has been received from the peer.
Definition: asio_stream.h:561
StreamLayer m_nextLayer
Definition: asio_stream.h:808
void process_encrypted_data(const boost::asio::const_buffer &read_buffer, boost::system::error_code &ec)
Pass encrypted data to the native handle for processing.
Definition: asio_stream.h:772
const boost::asio::mutable_buffer & input_buffer()
Definition: asio_stream.h:644
std::size_t copy_received_data(MutableBufferSequence buffers)
Copy decrypted data into the user-provided buffer.
Definition: asio_stream.h:652
bool has_received_data() const
Check if decrypted data is available in the receive buffer.
Definition: asio_stream.h:648

◆ read_some() [2/2]

template<class StreamLayer , class ChannelT = Channel>
template<typename MutableBufferSequence >
std::size_t Botan::TLS::Stream< StreamLayer, ChannelT >::read_some ( const MutableBufferSequence &  buffers)
inline

Read some data from the stream.

The function call will block until one or more bytes of data has been read successfully, or until an error occurs.

Parameters
buffersThe buffers into which the data will be read.
Returns
The number of bytes read. Returns 0 if an error occurred.
Exceptions
boost::system::system_errorif error occured

Definition at line 453 of file asio_stream.h.

References Botan::TLS::Stream< StreamLayer, ChannelT >::buffers, and Botan::TLS::Stream< StreamLayer, ChannelT >::read_some().

454  {
455  boost::system::error_code ec;
456  auto const n = read_some(buffers, ec);
457  boost::asio::detail::throw_error(ec, "read_some");
458  return n;
459  }
const ConstBufferSequence & buffers
Definition: asio_stream.h:286
std::size_t read_some(const MutableBufferSequence &buffers, boost::system::error_code &ec)
Read some data from the stream.
Definition: asio_stream.h:413

◆ send_buffer()

template<class StreamLayer , class ChannelT = Channel>
boost::asio::const_buffer Botan::TLS::Stream< StreamLayer, ChannelT >::send_buffer ( ) const
inlineprotected

◆ send_pending_encrypted_data()

template<class StreamLayer , class ChannelT = Channel>
size_t Botan::TLS::Stream< StreamLayer, ChannelT >::send_pending_encrypted_data ( boost::system::error_code &  ec)
inlineprotected

Synchronously write encrypted data from the send buffer to the next layer.

If this function is called with an error code other than 'Success', it will do nothing and return 0.

Parameters
ecSet to indicate what error occurred, if any. Specifically, StreamTruncated will be set if the peer has closed the connection but did not properly shut down the SSL connection.
Returns
The number of bytes written.

Definition at line 724 of file asio_stream.h.

References Botan::TLS::Stream< StreamLayer, ChannelT >::consume_send_buffer(), Botan::TLS::Stream< StreamLayer, ChannelT >::m_nextLayer, Botan::TLS::Stream< StreamLayer, ChannelT >::send_buffer(), Botan::TLS::Stream< StreamLayer, ChannelT >::shutdown_received(), and Botan::TLS::StreamTruncated.

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::handshake(), Botan::TLS::Stream< StreamLayer, ChannelT >::shutdown(), and Botan::TLS::Stream< StreamLayer, ChannelT >::write_some().

725  {
726  if(ec)
727  { return 0; }
728 
729  auto writtenBytes = boost::asio::write(m_nextLayer, send_buffer(), ec);
730  consume_send_buffer(writtenBytes);
731 
732  if(ec == boost::asio::error::eof && !shutdown_received())
733  {
734  // transport layer was closed by peer without receiving 'close_notify'
736  }
737 
738  return writtenBytes;
739  }
bool shutdown_received() const
Indicates whether a close_notify alert has been received from the peer.
Definition: asio_stream.h:561
StreamLayer m_nextLayer
Definition: asio_stream.h:808
boost::asio::const_buffer send_buffer() const
Definition: asio_stream.h:645
void consume_send_buffer(std::size_t bytesConsumed)
Mark bytes in the send buffer as consumed, removing them from the buffer.
Definition: asio_stream.h:667

◆ set_shutdown_received()

template<class StreamLayer , class ChannelT = Channel>
void Botan::TLS::Stream< StreamLayer, ChannelT >::set_shutdown_received ( )
inlineprotected

◆ set_verify_callback() [1/2]

template<class StreamLayer , class ChannelT = Channel>
void Botan::TLS::Stream< StreamLayer, ChannelT >::set_verify_callback ( Context::Verify_Callback  callback)
inline

Override the tls_verify_cert_chain callback.

This changes the verify_callback in the stream's TLS::Context, and hence the tls_verify_cert_chain callback used in the handshake. Using this function is equivalent to setting the callback via

See also
Botan::TLS::Context::set_verify_callback
Note
This function should only be called before initiating the TLS handshake

Definition at line 150 of file asio_stream.h.

References Botan::TLS::Stream< StreamLayer, ChannelT >::m_context, and Botan::TLS::Context::set_verify_callback().

151  {
152  m_context.set_verify_callback(std::move(callback));
153  }
void set_verify_callback(Verify_Callback callback)
Override the tls_verify_cert_chain callback.
Definition: asio_context.h:84
Context & m_context
Definition: asio_stream.h:807

◆ set_verify_callback() [2/2]

template<class StreamLayer , class ChannelT = Channel>
void Botan::TLS::Stream< StreamLayer, ChannelT >::set_verify_callback ( Context::Verify_Callback  callback,
boost::system::error_code &  ec 
)
inline

Compatibility overload of set_verify_callback.

Parameters
callbackthe callback implementation
ecThis parameter is unused.

Definition at line 161 of file asio_stream.h.

References BOTAN_UNUSED, Botan::TLS::Stream< StreamLayer, ChannelT >::m_context, and Botan::TLS::Context::set_verify_callback().

162  {
163  BOTAN_UNUSED(ec);
164  m_context.set_verify_callback(std::move(callback));
165  }
void set_verify_callback(Verify_Callback callback)
Override the tls_verify_cert_chain callback.
Definition: asio_context.h:84
Context & m_context
Definition: asio_stream.h:807
#define BOTAN_UNUSED(...)
Definition: assert.h:142

◆ set_verify_depth() [1/2]

template<class StreamLayer , class ChannelT = Channel>
void Botan::TLS::Stream< StreamLayer, ChannelT >::set_verify_depth ( int  depth)
inline
Exceptions
Not_Implemented

Definition at line 168 of file asio_stream.h.

References BOTAN_UNUSED, and Botan::TLS::Stream< StreamLayer, ChannelT >::Not_Implemented().

169  {
170  BOTAN_UNUSED(depth);
171  throw Not_Implemented("set_verify_depth is not implemented");
172  }
throw Not_Implemented("buffered async handshake is not implemented")
#define BOTAN_UNUSED(...)
Definition: assert.h:142

◆ set_verify_depth() [2/2]

template<class StreamLayer , class ChannelT = Channel>
void Botan::TLS::Stream< StreamLayer, ChannelT >::set_verify_depth ( int  depth,
boost::system::error_code &  ec 
)
inline

Not Implemented.

Parameters
depththe desired verification depth
ecWill be set to Botan::ErrorType::NotImplemented

Definition at line 179 of file asio_stream.h.

References BOTAN_UNUSED, and Botan::NotImplemented.

180  {
181  BOTAN_UNUSED(depth);
183  }
#define BOTAN_UNUSED(...)
Definition: assert.h:142

◆ set_verify_mode() [1/2]

template<class StreamLayer , class ChannelT = Channel>
template<typename verify_mode >
void Botan::TLS::Stream< StreamLayer, ChannelT >::set_verify_mode ( verify_mode  v)
inline
Exceptions
Not_Implemented

Definition at line 187 of file asio_stream.h.

References BOTAN_UNUSED, and Botan::TLS::Stream< StreamLayer, ChannelT >::Not_Implemented().

188  {
189  BOTAN_UNUSED(v);
190  throw Not_Implemented("set_verify_mode is not implemented");
191  }
throw Not_Implemented("buffered async handshake is not implemented")
#define BOTAN_UNUSED(...)
Definition: assert.h:142

◆ set_verify_mode() [2/2]

template<class StreamLayer , class ChannelT = Channel>
template<typename verify_mode >
void Botan::TLS::Stream< StreamLayer, ChannelT >::set_verify_mode ( verify_mode  v,
boost::system::error_code &  ec 
)
inline

Not Implemented.

Parameters
vthe desired verify mode
ecWill be set to Botan::ErrorType::NotImplemented

Definition at line 199 of file asio_stream.h.

References BOTAN_UNUSED, and Botan::NotImplemented.

200  {
201  BOTAN_UNUSED(v);
203  }
#define BOTAN_UNUSED(...)
Definition: assert.h:142

◆ setup_native_handle() [1/2]

template<class StreamLayer , class ChannelT = Channel>
template<class T = ChannelT>
std::enable_if<!std::is_same<Channel, T>::value>::type Botan::TLS::Stream< StreamLayer, ChannelT >::setup_native_handle ( Connection_Side  ,
boost::system::error_code &   
)
inlineprotected

◆ setup_native_handle() [2/2]

template<class StreamLayer , class ChannelT = Channel>
template<class T = ChannelT>
std::enable_if<std::is_same<Channel, T>::value>::type Botan::TLS::Stream< StreamLayer, ChannelT >::setup_native_handle ( Connection_Side  side,
boost::system::error_code &  ec 
)
inlineprotected

Create the native handle.

Depending on the desired connection side, this function will create a Botan::TLS::Client or a Botan::TLS::Server.

Parameters
sideThe desired connection side (client or server)
ecSet to indicate what error occurred, if any.

Definition at line 688 of file asio_stream.h.

References Botan::TLS::CLIENT, Botan::TLS::Protocol_Version::latest_tls_version(), Botan::TLS::Stream< StreamLayer, ChannelT >::m_context, Botan::TLS::Stream< StreamLayer, ChannelT >::m_core, Botan::TLS::Context::m_credentials_manager, Botan::TLS::Stream< StreamLayer, ChannelT >::m_native_handle, Botan::TLS::Context::m_policy, Botan::TLS::Context::m_rng, Botan::TLS::Context::m_server_info, Botan::TLS::Context::m_session_manager, and Botan::TLS::Stream< StreamLayer, ChannelT >::try_with_error_code().

689  {
691  {
692  if(side == CLIENT)
693  {
694  m_native_handle = std::unique_ptr<Client>(
695  new Client(m_core,
702  }
703  else
704  {
705  m_native_handle = std::unique_ptr<Server>(
706  new Server(m_core,
711  false /* no DTLS */));
712  }
713  }, ec);
714  }
RandomNumberGenerator & m_rng
Definition: asio_context.h:108
static Protocol_Version latest_tls_version()
Definition: tls_version.h:36
Credentials_Manager & m_credentials_manager
Definition: asio_context.h:107
StreamCore m_core
Definition: asio_stream.h:813
Context & m_context
Definition: asio_stream.h:807
Server_Information m_server_info
Definition: asio_context.h:112
Session_Manager & m_session_manager
Definition: asio_context.h:109
void try_with_error_code(Fun f, boost::system::error_code &ec)
Catch exceptions and set an error_code.
Definition: asio_stream.h:782
std::unique_ptr< ChannelT > m_native_handle
Definition: asio_stream.h:814

◆ shutdown() [1/2]

template<class StreamLayer , class ChannelT = Channel>
void Botan::TLS::Stream< StreamLayer, ChannelT >::shutdown ( boost::system::error_code &  ec)
inline

Shut down SSL on the stream.

This function is used to shut down SSL on the stream. The function call will block until SSL has been shut down or an error occurs. Note that this will not close the lowest layer.

Note that this can be used in reaction of a received shutdown alert from the peer.

Parameters
ecSet to indicate what error occured, if any.

Definition at line 308 of file asio_stream.h.

References Botan::TLS::Stream< StreamLayer, ChannelT >::native_handle(), Botan::TLS::Stream< StreamLayer, ChannelT >::send_pending_encrypted_data(), and Botan::TLS::Stream< StreamLayer, ChannelT >::try_with_error_code().

309  {
311  {
312  native_handle()->close();
313  }, ec);
314 
316  }
size_t send_pending_encrypted_data(boost::system::error_code &ec)
Synchronously write encrypted data from the send buffer to the next layer.
Definition: asio_stream.h:724
native_handle_type native_handle()
Definition: asio_stream.h:130
void try_with_error_code(Fun f, boost::system::error_code &ec)
Catch exceptions and set an error_code.
Definition: asio_stream.h:782

◆ shutdown() [2/2]

template<class StreamLayer , class ChannelT = Channel>
void Botan::TLS::Stream< StreamLayer, ChannelT >::shutdown ( )
inline

Shut down SSL on the stream.

This function is used to shut down SSL on the stream. The function call will block until SSL has been shut down or an error occurs. Note that this will not close the lowest layer.

Note that this can be used in reaction of a received shutdown alert from the peer.

Exceptions
boost::system::system_errorif error occured

Definition at line 328 of file asio_stream.h.

329  {
330  boost::system::error_code ec;
331  shutdown(ec);
332  boost::asio::detail::throw_error(ec, "shutdown");
333  }
void shutdown()
Shut down SSL on the stream.
Definition: asio_stream.h:328

◆ shutdown_received()

template<class StreamLayer , class ChannelT = Channel>
bool Botan::TLS::Stream< StreamLayer, ChannelT >::shutdown_received ( ) const
inline

◆ tls_encrypt()

template<class StreamLayer , class ChannelT = Channel>
template<typename ConstBufferSequence >
void Botan::TLS::Stream< StreamLayer, ChannelT >::tls_encrypt ( const ConstBufferSequence &  buffers,
boost::system::error_code &  ec 
)
inlineprotected

Pass plaintext data to the native handle for processing.

The native handle will then create TLS records and hand them back to the Stream via the tls_emit_data callback.

Definition at line 747 of file asio_stream.h.

References Botan::TLS::Stream< StreamLayer, ChannelT >::buffers, Botan::TLS::Stream< StreamLayer, ChannelT >::native_handle(), and Botan::TLS::Stream< StreamLayer, ChannelT >::try_with_error_code().

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::async_write_some(), and Botan::TLS::Stream< StreamLayer, ChannelT >::write_some().

748  {
749  // NOTE: This is not asynchronous: it encrypts the data synchronously.
750  // The data encrypted by native_handle()->send() is synchronously stored in the send_buffer of m_core,
751  // but is not actually written to the wire, yet.
752  for(auto it = boost::asio::buffer_sequence_begin(buffers);
753  !ec && it != boost::asio::buffer_sequence_end(buffers);
754  it++)
755  {
756  const boost::asio::const_buffer buffer = *it;
758  {
759  native_handle()->send(static_cast<const uint8_t*>(buffer.data()), buffer.size());
760  }, ec);
761  }
762  }
const ConstBufferSequence & buffers
Definition: asio_stream.h:286
native_handle_type native_handle()
Definition: asio_stream.h:130
void try_with_error_code(Fun f, boost::system::error_code &ec)
Catch exceptions and set an error_code.
Definition: asio_stream.h:782

◆ try_with_error_code()

template<class StreamLayer , class ChannelT = Channel>
template<typename Fun >
void Botan::TLS::Stream< StreamLayer, ChannelT >::try_with_error_code ( Fun  f,
boost::system::error_code &  ec 
)
inlineprotected

Catch exceptions and set an error_code.

Definition at line 782 of file asio_stream.h.

References Botan::Exception::error_type(), Botan::TLS::TLS_Exception::type(), and Botan::Unknown.

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::async_shutdown(), Botan::TLS::Stream< StreamLayer, ChannelT >::process_encrypted_data(), Botan::TLS::Stream< StreamLayer, ChannelT >::setup_native_handle(), Botan::TLS::Stream< StreamLayer, ChannelT >::shutdown(), and Botan::TLS::Stream< StreamLayer, ChannelT >::tls_encrypt().

783  {
784  try
785  {
786  f();
787  }
788  catch(const TLS_Exception& e)
789  {
790  ec = e.type();
791  }
792  catch(const Botan::Exception& e)
793  {
794  ec = e.error_type();
795  }
796  catch(const std::exception&)
797  {
799  }
800  }
virtual ErrorType error_type() const noexcept
Definition: exceptn.h:101

◆ write_some() [1/2]

template<class StreamLayer , class ChannelT = Channel>
template<typename ConstBufferSequence >
std::size_t Botan::TLS::Stream< StreamLayer, ChannelT >::write_some ( const ConstBufferSequence &  buffers,
boost::system::error_code &  ec 
)
inline

Write some data to the stream.

The function call will block until one or more bytes of data has been written successfully, or until an error occurs.

Parameters
buffersThe data to be written.
ecSet to indicate what error occurred, if any.
Returns
The number of bytes processed from the input buffers.

Definition at line 472 of file asio_stream.h.

References Botan::TLS::Stream< StreamLayer, ChannelT >::buffers, Botan::TLS::Stream< StreamLayer, ChannelT >::send_pending_encrypted_data(), and Botan::TLS::Stream< StreamLayer, ChannelT >::tls_encrypt().

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::write_some().

474  {
475  tls_encrypt(buffers, ec);
477  return !ec ? boost::asio::buffer_size(buffers) : 0;
478  }
size_t send_pending_encrypted_data(boost::system::error_code &ec)
Synchronously write encrypted data from the send buffer to the next layer.
Definition: asio_stream.h:724
const ConstBufferSequence & buffers
Definition: asio_stream.h:286
void tls_encrypt(const ConstBufferSequence &buffers, boost::system::error_code &ec)
Pass plaintext data to the native handle for processing.
Definition: asio_stream.h:747

◆ write_some() [2/2]

template<class StreamLayer , class ChannelT = Channel>
template<typename ConstBufferSequence >
std::size_t Botan::TLS::Stream< StreamLayer, ChannelT >::write_some ( const ConstBufferSequence &  buffers)
inline

Write some data to the stream.

The function call will block until one or more bytes of data has been written successfully, or until an error occurs.

Parameters
buffersThe data to be written.
Returns
The number of bytes written.
Exceptions
boost::system::system_errorif error occured

Definition at line 491 of file asio_stream.h.

References Botan::TLS::Stream< StreamLayer, ChannelT >::buffers, and Botan::TLS::Stream< StreamLayer, ChannelT >::write_some().

492  {
493  boost::system::error_code ec;
494  auto const n = write_some(buffers, ec);
495  boost::asio::detail::throw_error(ec, "write_some");
496  return n;
497  }
const ConstBufferSequence & buffers
Definition: asio_stream.h:286
std::size_t write_some(const ConstBufferSequence &buffers, boost::system::error_code &ec)
Write some data to the stream.
Definition: asio_stream.h:472

Friends And Related Function Documentation

◆ detail::AsyncHandshakeOperation

template<class StreamLayer , class ChannelT = Channel>
template<class H , class S , class A >
friend class detail::AsyncHandshakeOperation
friend

Definition at line 569 of file asio_stream.h.

◆ detail::AsyncReadOperation

template<class StreamLayer , class ChannelT = Channel>
template<class H , class S , class M , class A >
friend class detail::AsyncReadOperation
friend

Definition at line 567 of file asio_stream.h.

◆ detail::AsyncWriteOperation

template<class StreamLayer , class ChannelT = Channel>
template<class H , class S , class A >
friend class detail::AsyncWriteOperation
friend

Definition at line 568 of file asio_stream.h.

Member Data Documentation

◆ buffers

template<class StreamLayer , class ChannelT = Channel>
const ConstBufferSequence& Botan::TLS::Stream< StreamLayer, ChannelT >::buffers

◆ handler

template<class StreamLayer , class ChannelT = Channel>
const ConstBufferSequence BufferedHandshakeHandler&& Botan::TLS::Stream< StreamLayer, ChannelT >::handler

◆ m_context

template<class StreamLayer , class ChannelT = Channel>
Context& Botan::TLS::Stream< StreamLayer, ChannelT >::m_context
protected

◆ m_core

template<class StreamLayer , class ChannelT = Channel>
StreamCore Botan::TLS::Stream< StreamLayer, ChannelT >::m_core
protected

◆ m_input_buffer

template<class StreamLayer , class ChannelT = Channel>
const boost::asio::mutable_buffer Botan::TLS::Stream< StreamLayer, ChannelT >::m_input_buffer
protected

◆ m_input_buffer_space

template<class StreamLayer , class ChannelT = Channel>
std::vector<uint8_t> Botan::TLS::Stream< StreamLayer, ChannelT >::m_input_buffer_space
protected

Definition at line 819 of file asio_stream.h.

◆ m_native_handle

template<class StreamLayer , class ChannelT = Channel>
std::unique_ptr<ChannelT> Botan::TLS::Stream< StreamLayer, ChannelT >::m_native_handle
protected

◆ m_nextLayer

template<class StreamLayer , class ChannelT = Channel>
StreamLayer Botan::TLS::Stream< StreamLayer, ChannelT >::m_nextLayer
protected

◆ m_receive_buffer

template<class StreamLayer , class ChannelT = Channel>
boost::beast::flat_buffer Botan::TLS::Stream< StreamLayer, ChannelT >::m_receive_buffer
protected

◆ m_send_buffer

template<class StreamLayer , class ChannelT = Channel>
boost::beast::flat_buffer Botan::TLS::Stream< StreamLayer, ChannelT >::m_send_buffer
protected

◆ m_shutdown_received

template<class StreamLayer , class ChannelT = Channel>
bool Botan::TLS::Stream< StreamLayer, ChannelT >::m_shutdown_received
protected

The documentation for this class was generated from the following file: