Botan  2.13.0
Crypto and TLS for C++11
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Botan::TLS::detail::AsyncHandshakeOperation< Handler, Stream, Allocator > Class Template Reference

#include <asio_async_ops.h>

Inheritance diagram for Botan::TLS::detail::AsyncHandshakeOperation< Handler, Stream, Allocator >:
Botan::TLS::detail::AsyncBase< Handler, Stream::executor_type, Allocator >

Public Types

using allocator_type = boost::asio::associated_allocator_t< Handler, Allocator >
 
using executor_type = boost::asio::associated_executor_t< Handler, Stream::executor_type >
 

Public Member Functions

template<class HandlerT >
 AsyncHandshakeOperation (HandlerT &&handler, Stream &stream, const boost::system::error_code &ec={})
 
 AsyncHandshakeOperation (AsyncHandshakeOperation &&)=default
 
allocator_type get_allocator () const noexcept
 
executor_type get_executor () const noexcept
 
void operator() (boost::system::error_code ec, std::size_t bytesTransferred, bool isContinuation=true)
 

Protected Member Functions

void complete_now (Args &&...args)
 

Protected Attributes

Handler m_handler
 
boost::asio::executor_work_guard< Stream::executor_typem_work_guard_1
 

Detailed Description

template<class Handler, class Stream, class Allocator = std::allocator<void>>
class Botan::TLS::detail::AsyncHandshakeOperation< Handler, Stream, Allocator >

Definition at line 267 of file asio_async_ops.h.

Member Typedef Documentation

using Botan::TLS::detail::AsyncBase< Handler, Stream::executor_type , Allocator >::allocator_type = boost::asio::associated_allocator_t<Handler, Allocator>
inherited

Definition at line 71 of file asio_async_ops.h.

using Botan::TLS::detail::AsyncBase< Handler, Stream::executor_type , Allocator >::executor_type = boost::asio::associated_executor_t<Handler, Stream::executor_type >
inherited

Definition at line 72 of file asio_async_ops.h.

Constructor & Destructor Documentation

template<class Handler , class Stream , class Allocator = std::allocator<void>>
template<class HandlerT >
Botan::TLS::detail::AsyncHandshakeOperation< Handler, Stream, Allocator >::AsyncHandshakeOperation ( HandlerT &&  handler,
Stream stream,
const boost::system::error_code &  ec = {} 
)
inline

Construct and invoke an AsyncHandshakeOperation.

Parameters
handlerHandler function to be called upon completion.
streamThe stream from which the data will be read
ecOptional error code; used to report an error to the handler function.

Definition at line 278 of file asio_async_ops.h.

281  {})
282  : AsyncBase<Handler, typename Stream::executor_type, Allocator>(
283  std::forward<HandlerT>(handler),
284  stream.get_executor())
285  , m_stream(stream)
286  {
287  this->operator()(ec, std::size_t(0), false);
288  }
void operator()(boost::system::error_code ec, std::size_t bytesTransferred, bool isContinuation=true)
template<class Handler , class Stream , class Allocator = std::allocator<void>>
Botan::TLS::detail::AsyncHandshakeOperation< Handler, Stream, Allocator >::AsyncHandshakeOperation ( AsyncHandshakeOperation< Handler, Stream, Allocator > &&  )
default

Member Function Documentation

void Botan::TLS::detail::AsyncBase< Handler, Stream::executor_type , Allocator >::complete_now ( Args &&...  args)
inlineprotectedinherited
allocator_type Botan::TLS::detail::AsyncBase< Handler, Stream::executor_type , Allocator >::get_allocator ( ) const
inlinenoexceptinherited

Definition at line 74 of file asio_async_ops.h.

References Botan::TLS::detail::AsyncBase< Handler, Executor1, Allocator >::m_handler.

75  {
76  return boost::asio::get_associated_allocator(m_handler);
77  }
executor_type Botan::TLS::detail::AsyncBase< Handler, Stream::executor_type , Allocator >::get_executor ( ) const
inlinenoexceptinherited
template<class Handler , class Stream , class Allocator = std::allocator<void>>
void Botan::TLS::detail::AsyncHandshakeOperation< Handler, Stream, Allocator >::operator() ( boost::system::error_code  ec,
std::size_t  bytesTransferred,
bool  isContinuation = true 
)
inline

Definition at line 292 of file asio_async_ops.h.

References Botan::TLS::detail::AsyncBase< Handler, Stream::executor_type, Allocator >::complete_now(), Botan::Exception::error_type(), Botan::TLS::Stream< StreamLayer, ChannelT >::has_data_to_send(), Botan::TLS::Stream< StreamLayer, ChannelT >::input_buffer(), Botan::TLS::Stream< StreamLayer, ChannelT >::native_handle(), Botan::TLS::Stream< StreamLayer, ChannelT >::next_layer(), Botan::TLS::TLS_Exception::type(), and Botan::Unknown.

293  {
294  reenter(this)
295  {
296  if(bytesTransferred > 0 && !ec)
297  {
298  // Provide encrypted TLS data received from the network to TLS::Channel for decryption
299  boost::asio::const_buffer read_buffer {m_stream.input_buffer().data(), bytesTransferred};
300  try
301  {
302  m_stream.native_handle()->received_data(
303  static_cast<const uint8_t*>(read_buffer.data()), read_buffer.size()
304  );
305  }
306  catch(const TLS_Exception& e)
307  {
308  ec = e.type();
309  }
310  catch(const Botan::Exception& e)
311  {
312  ec = e.error_type();
313  }
314  catch(...)
315  {
317  }
318  }
319 
320  if(m_stream.has_data_to_send() && !ec)
321  {
322  // Write encrypted TLS data provided by the TLS::Channel on the wire
323 
324  // Note: we construct `AsyncWriteOperation` with 0 as its last parameter (`plainBytesTransferred`). This
325  // operation will eventually call `*this` as its own handler, passing the 0 back to this call operator.
326  // This is necessary because the check of `bytesTransferred > 0` assumes that `bytesTransferred` bytes
327  // were just read and are available in input_buffer for further processing.
328  AsyncWriteOperation<
330  Stream,
331  Allocator>
332  op{std::move(*this), m_stream, 0};
333  return;
334  }
335 
336  if(!m_stream.native_handle()->is_active() && !ec)
337  {
338  // Read more encrypted TLS data from the network
339  m_stream.next_layer().async_read_some(m_stream.input_buffer(), std::move(*this));
340  return;
341  }
342 
343  if(!isContinuation)
344  {
345  // Make sure the handler is not called without an intermediate initiating function.
346  // "Reading" into a zero-byte buffer will complete immediately.
347  m_ec = ec;
348  yield m_stream.next_layer().async_read_some(boost::asio::mutable_buffer(), std::move(*this));
349  ec = m_ec;
350  }
351 
352  this->complete_now(ec);
353  }
354  }
const next_layer_type & next_layer() const
Definition: asio_stream.h:110
virtual ErrorType error_type() const noexcept
Definition: exceptn.h:101
MechanismType type
const boost::asio::mutable_buffer & input_buffer()
Definition: asio_stream.h:594
native_handle_type native_handle()
Definition: asio_stream.h:116
bool has_data_to_send() const
Check if encrypted data is available in the send buffer.
Definition: asio_stream.h:614

Member Data Documentation

Handler Botan::TLS::detail::AsyncBase< Handler, Stream::executor_type , Allocator >::m_handler
protectedinherited

Definition at line 106 of file asio_async_ops.h.

boost::asio::executor_work_guard<Stream::executor_type > Botan::TLS::detail::AsyncBase< Handler, Stream::executor_type , Allocator >::m_work_guard_1
protectedinherited

Definition at line 107 of file asio_async_ops.h.


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