From f2ab1c976fd1e2ccdd2f4a013a92bca338fff6dc Mon Sep 17 00:00:00 2001 From: Rene Meusel Date: Wed, 18 Oct 2023 08:50:56 +0200 Subject: [PATCH] Refactor: replace macro checks by concepts Co-Authored-By: Fabian Albert --- src/lib/tls/asio/asio_stream.h | 36 +++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/lib/tls/asio/asio_stream.h b/src/lib/tls/asio/asio_stream.h index e2de674a124..11c2c50bde8 100644 --- a/src/lib/tls/asio/asio_stream.h +++ b/src/lib/tls/asio/asio_stream.h @@ -127,6 +127,16 @@ class StreamCallbacks : public Callbacks { std::weak_ptr m_context; }; +namespace detail { + +template +concept basic_completion_token = boost::asio::completion_token_for; + +template +concept byte_size_completion_token = boost::asio::completion_token_for; + +} // namespace detail + /** * @brief boost::asio compatible SSL/TLS stream * @@ -346,15 +356,13 @@ class Stream { * @param completion_token The completion handler to be called when the handshake operation completes. * The completion signature of the handler must be: void(boost::system::error_code). */ - template + template auto async_handshake(Botan::TLS::Connection_Side side, CompletionToken&& completion_token = default_completion_token{}) { return boost::asio::async_initiate( [this](auto&& completion_handler, TLS::Connection_Side connection_side) { using completion_handler_t = std::decay_t; - BOOST_ASIO_HANDSHAKE_HANDLER_CHECK(completion_handler_t, completion_handler) type_check; - boost::system::error_code ec; setup_native_handle(connection_side, ec); @@ -366,11 +374,11 @@ class Stream { } //! @throws Not_Implemented - template - BOOST_ASIO_INITFN_RESULT_TYPE(BufferedHandshakeHandler, void(boost::system::error_code, std::size_t)) - async_handshake(Connection_Side side, const ConstBufferSequence& buffers, BufferedHandshakeHandler&& handler) { + template + auto async_handshake(Connection_Side side, + const ConstBufferSequence& buffers, + BufferedHandshakeHandler&& handler) { BOTAN_UNUSED(side, buffers, handler); - BOOST_ASIO_HANDSHAKE_HANDLER_CHECK(BufferedHandshakeHandler, handler) type_check; throw Not_Implemented("buffered async handshake is not implemented"); } @@ -447,14 +455,12 @@ class Stream { * @param completion_token The completion handler to be called when the shutdown operation completes. * The completion signature of the handler must be: void(boost::system::error_code). */ - template + template auto async_shutdown(CompletionToken&& completion_token = default_completion_token{}) { return boost::asio::async_initiate( [this](auto&& completion_handler) { using completion_handler_t = std::decay_t; - BOOST_ASIO_SHUTDOWN_HANDLER_CHECK(completion_handler_t, completion_handler) type_check; - boost::system::error_code ec; try_with_error_code([&] { native_handle()->close(); }, ec); @@ -574,15 +580,14 @@ class Stream { * handler will be made as required. The completion signature of the handler must be: * void(boost::system::error_code, std::size_t). */ - template + template auto async_write_some(const ConstBufferSequence& buffers, CompletionToken&& completion_token = default_completion_token{}) { return boost::asio::async_initiate( [this](auto&& completion_handler, const auto& bufs) { using completion_handler_t = std::decay_t; - BOOST_ASIO_WRITE_HANDLER_CHECK(completion_handler_t, completion_handler) type_check; - boost::system::error_code ec; tls_encrypt(bufs, ec); @@ -611,15 +616,14 @@ class Stream { * @param completion_token The completion handler to be called when the read operation completes. The completion * signature of the handler must be: void(boost::system::error_code, std::size_t). */ - template + template auto async_read_some(const MutableBufferSequence& buffers, CompletionToken&& completion_token = default_completion_token{}) { return boost::asio::async_initiate( [this](auto&& completion_handler, const auto& bufs) { using completion_handler_t = std::decay_t; - BOOST_ASIO_READ_HANDLER_CHECK(completion_handler_t, completion_handler) type_check; - detail::AsyncReadOperation op{ std::forward(completion_handler), *this, bufs}; },