Botan 2.19.5 Crypto and TLS for C&

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 >:

## Public Types
using | allocator_type = boost::asio::associated_allocator_t< Handler, std::allocator< void > >
using | executor_type = boost::asio::associated_executor_t< Handler, Stream::executor_type >

## Public Member Functions
| AsyncHandshakeOperation (AsyncHandshakeOperation &&)=default
template<class HandlerT >
| AsyncHandshakeOperation (HandlerT &&handler, Stream &stream, const boost::system::error_code &ec={})
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_type > | m_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

## ◆ allocator_type

using Botan::TLS::detail::AsyncBase< Handler, Stream::executor_type , std::allocator< void > >::allocator_type = boost::asio::associated_allocator_t<Handler, std::allocator< void > >
| inherited

Definition at line 71 of file asio_async_ops.h.

## ◆ executor_type

using Botan::TLS::detail::AsyncBase< Handler, Stream::executor_type , std::allocator< void > >::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

## ◆ AsyncHandshakeOperation() [1/2]

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

  handler | Handler function to be called upon completion.
  stream | The stream from which the data will be read
  ec | Optional 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 }
Botan::TLS::detail::AsyncHandshakeOperation::operator()
void operator()(boost::system::error_code ec, std::size_t bytesTransferred, bool isContinuation=true)
Definition: asio_async_ops.h:292

## ◆ AsyncHandshakeOperation() [2/2]

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

## ◆ complete_now()

void Botan::TLS::detail::AsyncBase< Handler, Stream::executor_type , std::allocator< void > >::complete_now | ( | Args &&... | args | ) |
| inline protected inherited

Call the completion handler.

This function should only be called after an intermediate initiating function has been called.

Parameters

  args | Arguments forwarded to the completion handler function.

Definition at line 100 of file asio_async_ops.h.

101 {
102 m_work_guard_1.reset();
103 m_handler(std::forward<Args>(args)...);
104 }
Botan::TLS::detail::AsyncBase< Handler, Stream::executor_type, std::allocator< void > >::m_handler
Handler m_handler
Definition: asio_async_ops.h:106
Botan::TLS::detail::AsyncBase< Handler, Stream::executor_type, std::allocator< void > >::m_work_guard_1
boost::asio::executor_work_guard< Stream::executor_type > m_work_guard_1
Definition: asio_async_ops.h:107

## ◆ get_allocator()

allocator_type Botan::TLS::detail::AsyncBase< Handler, Stream::executor_type , std::allocator< void > >::get_allocator | ( |  | ) | const
| inline noexcept inherited

Definition at line 74 of file asio_async_ops.h.

75 {
76 return boost::asio::get_associated_allocator(m_handler);
77 }

## ◆ get_executor()

executor_type Botan::TLS::detail::AsyncBase< Handler, Stream::executor_type , std::allocator< void > >::get_executor | ( |  | ) | const
| inline noexcept inherited

Definition at line 79 of file asio_async_ops.h.

80 {
81 return boost::asio::get_associated_executor(m_handler, m_work_guard_1.get_executor());
82 }

## ◆ operator()()

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.

293 {
294 reenter(this)
295 {
296 if(ec == boost::asio::error::eof)
297 {
298 ec = StreamError::StreamTruncated;
299 }
300
301 if(bytesTransferred > 0 && !ec)
302 {
303 // Provide encrypted TLS data received from the network to TLS::Channel for decryption
304 boost::asio::const_buffer read_buffer {m_stream.input_buffer().data(), bytesTransferred};
305 m_stream.process_encrypted_data(read_buffer, ec);
306 }
307
308 if(m_stream.has_data_to_send() && !ec)
309 {
310 // Write encrypted TLS data provided by the TLS::Channel on the wire
311
312 // Note: we construct `AsyncWriteOperation` with 0 as its last parameter (`plainBytesTransferred`). This
313 // operation will eventually call `*this` as its own handler, passing the 0 back to this call operator.
314 // This is necessary because the check of `bytesTransferred > 0` assumes that `bytesTransferred` bytes
315 // were just read and are available in input_buffer for further processing.
316 AsyncWriteOperation<AsyncHandshakeOperation<typename std::decay<Handler>::type, Stream, Allocator>,
317 Stream,
318 Allocator>
319 op{std::move(*this), m_stream, 0};
320 return;
321 }
322
323 if(!m_stream.native_handle()->is_active() && !ec)
324 {
325 // Read more encrypted TLS data from the network
326 m_stream.next_layer().async_read_some(m_stream.input_buffer(), std::move(*this));
327 return;
328 }
329
330 if(!isContinuation)
331 {
332 // Make sure the handler is not called without an intermediate initiating function.
333 // "Reading" into a zero-byte buffer will complete immediately.
334 m_ec = ec;
335 yield m_stream.next_layer().async_read_some(boost::asio::mutable_buffer(), std::move(*this));
336 ec = m_ec;
337 }
338
339 this->complete_now(ec);
340 }
341 }
Botan::TLS::Stream::native_handle
native_handle_type native_handle()
Definition: asio_stream.h:130
Botan::TLS::Stream::next_layer
const next_layer_type & next_layer() const
Definition: asio_stream.h:106
Botan::TLS::Stream::input_buffer
const boost::asio::mutable_buffer & input_buffer()
Definition: asio_stream.h:652
Botan::TLS::Stream::process_encrypted_data
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:780
Botan::TLS::Stream::has_data_to_send
bool has_data_to_send() const
Check if encrypted data is available in the send buffer.
Definition: asio_stream.h:672
Botan::TLS::detail::AsyncBase< Handler, Stream::executor_type, std::allocator< void > >::complete_now
void complete_now(Args &&... args)
Definition: asio_async_ops.h:100
Botan::TLS::StreamTruncated
@ StreamTruncated
Definition: asio_error.h:35
type
MechanismType type
Definition: p11_mechanism.cpp:44

References Botan::TLS::detail::AsyncBase< Handler, Stream::executor_type, std::allocator< void > >::complete_now(), 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::Stream< StreamLayer, ChannelT >::process_encrypted_data(), and Botan::TLS::StreamTruncated.

## Member Data Documentation

## ◆ m_handler

Handler Botan::TLS::detail::AsyncBase< Handler, Stream::executor_type , std::allocator< void > >::m_handler
| protected inherited

Definition at line 106 of file asio_async_ops.h.

## ◆ m_work_guard_1

boost::asio::executor_work_guard<Stream::executor_type > Botan::TLS::detail::AsyncBase< Handler, Stream::executor_type , std::allocator< void > >::m_work_guard_1
| protected inherited

Definition at line 107 of file asio_async_ops.h.

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

- src/lib/tls/asio/asio_async_ops.h