diff options
author | Hannes Rantzsch <[email protected]> | 2019-04-01 15:21:15 +0200 |
---|---|---|
committer | Hannes Rantzsch <[email protected]> | 2019-04-16 10:48:18 +0200 |
commit | 3ce24f23a3190f2ce0c2ec72d14171fcab3f2fda (patch) | |
tree | 7901788250ae7869f35f7a87a33552960c91220f /src | |
parent | c999829be4732a864b738ef178b2b347135b91e5 (diff) |
use boost::beast::flat_buffer instead of our own buffer type in core
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/tls/asio/asio_stream_core.h | 41 |
1 files changed, 16 insertions, 25 deletions
diff --git a/src/lib/tls/asio/asio_stream_core.h b/src/lib/tls/asio/asio_stream_core.h index 74b0998f1..6ae93ceea 100644 --- a/src/lib/tls/asio/asio_stream_core.h +++ b/src/lib/tls/asio/asio_stream_core.h @@ -14,6 +14,7 @@ #include <boost/version.hpp> #if BOOST_VERSION > 106600 +#include <boost/beast/core/flat_buffer.hpp> #include <botan/internal/asio_includes.h> #include <botan/tls_callbacks.h> #include <mutex> @@ -28,26 +29,16 @@ namespace TLS { */ struct StreamCore : public Botan::TLS::Callbacks { - struct Buffer - { - Buffer() : dynamicBuffer(data_buffer) {} - std::vector<uint8_t> data_buffer; - boost::asio::dynamic_vector_buffer< - uint8_t, typename decltype(data_buffer)::allocator_type> - dynamicBuffer; - }; - StreamCore() : m_input_buffer_space(17 * 1024, '\0'), // enough for a TLS Datagram - input_buffer(boost::asio::buffer(m_input_buffer_space)) {} + input_buffer(m_input_buffer_space.data(), m_input_buffer_space.size()) {} virtual ~StreamCore() = default; void tls_emit_data(const uint8_t data[], size_t size) override { - m_send_buffer.dynamicBuffer.commit(boost::asio::buffer_copy( - m_send_buffer.dynamicBuffer.prepare(size), - boost::asio::buffer(data, size))); + m_send_buffer.commit( + boost::asio::buffer_copy(m_send_buffer.prepare(size), boost::asio::buffer(data, size))); } void tls_record_received(uint64_t, const uint8_t data[], @@ -55,10 +46,10 @@ struct StreamCore : public Botan::TLS::Callbacks { // TODO: It would be nice to avoid this buffer copy. However, we need to deal with the case that the receive // buffer provided by the caller is smaller than the decrypted record. - auto buffer = m_receive_buffer.dynamicBuffer.prepare(size); + auto buffer = m_receive_buffer.prepare(size); auto copySize = boost::asio::buffer_copy(buffer, boost::asio::const_buffer(data, size)); - m_receive_buffer.dynamicBuffer.commit(copySize); + m_receive_buffer.commit(copySize); } void tls_alert(Botan::TLS::Alert alert) override @@ -82,40 +73,40 @@ struct StreamCore : public Botan::TLS::Callbacks bool hasReceivedData() const { - return m_receive_buffer.dynamicBuffer.size() > 0; + return m_receive_buffer.size() > 0; } template <typename MutableBufferSequence> std::size_t copyReceivedData(MutableBufferSequence buffers) { const auto copiedBytes = - boost::asio::buffer_copy(buffers, m_receive_buffer.dynamicBuffer.data()); - m_receive_buffer.dynamicBuffer.consume(copiedBytes); + boost::asio::buffer_copy(buffers, m_receive_buffer.data()); + m_receive_buffer.consume(copiedBytes); return copiedBytes; } - bool hasDataToSend() const { return m_send_buffer.dynamicBuffer.size() > 0; } + bool hasDataToSend() const { return m_send_buffer.size() > 0; } boost::asio::const_buffer sendBuffer() const { - return m_send_buffer.dynamicBuffer.data(); + return m_send_buffer.data(); } void consumeSendBuffer(std::size_t bytesConsumed) { - m_send_buffer.dynamicBuffer.consume(bytesConsumed); + m_send_buffer.consume(bytesConsumed); } void clearSendBuffer() { - consumeSendBuffer(m_send_buffer.dynamicBuffer.size()); + consumeSendBuffer(m_send_buffer.size()); } private: // Buffer space used to read input intended for the engine. - std::vector<uint8_t> m_input_buffer_space; - Buffer m_receive_buffer; - Buffer m_send_buffer; + std::vector<uint8_t> m_input_buffer_space; + boost::beast::flat_buffer m_receive_buffer; + boost::beast::flat_buffer m_send_buffer; public: // A buffer that may be used to read input intended for the engine. |