diff options
author | Tim Oesterreich <[email protected]> | 2019-02-25 11:00:02 +0100 |
---|---|---|
committer | Hannes Rantzsch <[email protected]> | 2019-04-16 10:47:59 +0200 |
commit | 5423ddfe4c58f4fe69107310c0ae4bdcbf891e48 (patch) | |
tree | 21127342c72527e24ee989c97dd9620b5e3f6bcf /src/lib/tls | |
parent | 41f0bff33965a86c40de7e2814bf24baa83d223f (diff) |
review: use specific buffer type where applicable
Diffstat (limited to 'src/lib/tls')
-rw-r--r-- | src/lib/tls/asio/asio_async_handshake_op.h | 7 | ||||
-rw-r--r-- | src/lib/tls/asio/asio_async_read_op.h | 5 | ||||
-rw-r--r-- | src/lib/tls/asio/asio_stream.h | 34 | ||||
-rw-r--r-- | src/lib/tls/asio/asio_stream_base.h | 1 | ||||
-rw-r--r-- | src/lib/tls/asio/asio_stream_core.h | 4 |
5 files changed, 26 insertions, 25 deletions
diff --git a/src/lib/tls/asio/asio_async_handshake_op.h b/src/lib/tls/asio/asio_async_handshake_op.h index c376cf85a..c9a8b8058 100644 --- a/src/lib/tls/asio/asio_async_handshake_op.h +++ b/src/lib/tls/asio/asio_async_handshake_op.h @@ -40,15 +40,14 @@ struct AsyncHandshakeOperation // process tls packets from socket first if(bytesTransferred > 0) { - auto read_buffer = - boost::asio::buffer(m_core.input_buffer, bytesTransferred); + boost::asio::const_buffer read_buffer {m_core.input_buffer.data(), bytesTransferred}; try { m_channel->received_data( static_cast<const uint8_t*>(read_buffer.data()), read_buffer.size()); } - catch(const std::exception &) + catch(const std::exception&) { ec = convertException(); m_handler(ec); @@ -76,7 +75,7 @@ struct AsyncHandshakeOperation { // don't call the handler directly, similar to io_context.post m_nextLayer.async_read_some( - boost::asio::buffer(m_core.input_buffer, 0), std::move(*this)); + boost::asio::mutable_buffer(m_core.input_buffer.data(), 0), std::move(*this)); return; } m_handler(ec); diff --git a/src/lib/tls/asio/asio_async_read_op.h b/src/lib/tls/asio/asio_async_read_op.h index 9bf2b393b..241f9ae5c 100644 --- a/src/lib/tls/asio/asio_async_read_op.h +++ b/src/lib/tls/asio/asio_async_read_op.h @@ -40,14 +40,13 @@ struct AsyncReadOperation if(bytes_transferred > 0 && !ec) { - auto read_buffer = - boost::asio::buffer(m_core.input_buffer, bytes_transferred); + boost::asio::const_buffer read_buffer {m_core.input_buffer.data(), bytes_transferred}; try { m_channel->received_data(static_cast<const uint8_t*>(read_buffer.data()), read_buffer.size()); } - catch(const std::exception &) + catch(const std::exception&) { ec = convertException(); } diff --git a/src/lib/tls/asio/asio_stream.h b/src/lib/tls/asio/asio_stream.h index 1286605a0..0d31b24d4 100644 --- a/src/lib/tls/asio/asio_stream.h +++ b/src/lib/tls/asio/asio_stream.h @@ -158,9 +158,12 @@ class Stream final : public StreamBase<Channel> if(ec) { return; } - auto read_buffer = boost::asio::buffer( - this->m_core.input_buffer, - m_nextLayer.read_some(this->m_core.input_buffer, ec)); + boost::asio::const_buffer read_buffer + { + this->m_core.input_buffer.data(), + m_nextLayer.read_some(this->m_core.input_buffer, ec) + }; + if(ec) { return; } @@ -169,7 +172,7 @@ class Stream final : public StreamBase<Channel> native_handle()->received_data(static_cast<const uint8_t*>(read_buffer.data()), read_buffer.size()); } - catch(const std::exception &ex) + catch(const std::exception& ex) { ec = Botan::TLS::convertException(); return; @@ -189,11 +192,8 @@ class Stream final : public StreamBase<Channel> boost::asio::async_completion<HandshakeHandler, void(boost::system::error_code)> init(handler); AsyncHandshakeOperation<typename std::decay<HandshakeHandler>::type, StreamLayer, Channel> - op{std::move(init.completion_handler), - m_nextLayer, - native_handle(), - this->m_core - }; + op{std::move(init.completion_handler), m_nextLayer, native_handle(), this->m_core}; + op(boost::system::error_code{}, 0, 1); return init.result.get(); @@ -270,7 +270,7 @@ class Stream final : public StreamBase<Channel> { native_handle()->close(); } - catch(const std::exception &ex) + catch(const std::exception& ex) { ec = Botan::TLS::convertException(); return; @@ -304,9 +304,11 @@ class Stream final : public StreamBase<Channel> if(this->m_core.hasReceivedData()) { return this->m_core.copyReceivedData(buffers); } - auto read_buffer = boost::asio::buffer( - this->m_core.input_buffer, - m_nextLayer.read_some(this->m_core.input_buffer, ec)); + boost::asio::const_buffer read_buffer = + { + this->m_core.input_buffer.data(), + m_nextLayer.read_some(this->m_core.input_buffer, ec) + }; if(ec) { return 0; } @@ -315,7 +317,7 @@ class Stream final : public StreamBase<Channel> native_handle()->received_data(static_cast<const uint8_t*>(read_buffer.data()), read_buffer.size()); } - catch(const std::exception &ex) + catch(const std::exception& ex) { ec = Botan::TLS::convertException(); return 0; @@ -351,7 +353,7 @@ class Stream final : public StreamBase<Channel> sent += to_send; } } - catch(const std::exception &ex) + catch(const std::exception& ex) { ec = Botan::TLS::convertException(); return 0; @@ -399,7 +401,7 @@ class Stream final : public StreamBase<Channel> sent += to_send; } } - catch(const std::exception &) + catch(const std::exception&) { init.completion_handler(Botan::TLS::convertException(), 0); return init.result.get(); diff --git a/src/lib/tls/asio/asio_stream_base.h b/src/lib/tls/asio/asio_stream_base.h index 62dba85ec..ecda81360 100644 --- a/src/lib/tls/asio/asio_stream_base.h +++ b/src/lib/tls/asio/asio_stream_base.h @@ -13,6 +13,7 @@ #include <botan/tls_client.h> #include <botan/tls_server.h> #include <botan/asio_error.h> +#include <botan/internal/asio_stream_core.h> namespace Botan { diff --git a/src/lib/tls/asio/asio_stream_core.h b/src/lib/tls/asio/asio_stream_core.h index ab2c30356..cfe44731d 100644 --- a/src/lib/tls/asio/asio_stream_core.h +++ b/src/lib/tls/asio/asio_stream_core.h @@ -42,7 +42,7 @@ struct StreamCore : public Botan::TLS::Callbacks { auto buffer = m_send_buffer.dynamicBuffer.prepare(size); auto copySize = - boost::asio::buffer_copy(buffer, boost::asio::buffer(data, size)); + boost::asio::buffer_copy(buffer, boost::asio::const_buffer(data, size)); m_send_buffer.dynamicBuffer.commit(copySize); } @@ -53,7 +53,7 @@ struct StreamCore : public Botan::TLS::Callbacks // buffer provided by the caller is smaller than the decrypted record. auto buffer = m_receive_buffer.dynamicBuffer.prepare(size); auto copySize = - boost::asio::buffer_copy(buffer, boost::asio::buffer(data, size)); + boost::asio::buffer_copy(buffer, boost::asio::const_buffer(data, size)); m_receive_buffer.dynamicBuffer.commit(copySize); } |