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 | |
parent | 41f0bff33965a86c40de7e2814bf24baa83d223f (diff) |
review: use specific buffer type where applicable
Diffstat (limited to 'src')
-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 | ||||
-rw-r--r-- | src/tests/unit_asio_stream.cpp | 32 |
6 files changed, 42 insertions, 41 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); } diff --git a/src/tests/unit_asio_stream.cpp b/src/tests/unit_asio_stream.cpp index b634e9f05..84713e0c7 100644 --- a/src/tests/unit_asio_stream.cpp +++ b/src/tests/unit_asio_stream.cpp @@ -214,7 +214,7 @@ class Asio_Stream_Tests final : public Test uint8_t buf[buf_size]; error_code ec; - auto bytes_transferred = asio::read(ssl, asio::buffer(buf, sizeof(buf)), ec); + auto bytes_transferred = asio::read(ssl, asio::mutable_buffer(buf, sizeof(buf)), ec); Test::Result result("sync read_some success"); result.confirm("reads the correct data", contains(buf, TEST_DATA, buf_size)); @@ -236,8 +236,8 @@ class Asio_Stream_Tests final : public Test std::vector<asio::mutable_buffer> data; uint8_t buf1[TEST_DATA_SIZE/2]; uint8_t buf2[TEST_DATA_SIZE/2]; - data.emplace_back(asio::buffer(buf1, TEST_DATA_SIZE/2)); - data.emplace_back(asio::buffer(buf2, TEST_DATA_SIZE/2)); + data.emplace_back(asio::mutable_buffer(buf1, TEST_DATA_SIZE/2)); + data.emplace_back(asio::mutable_buffer(buf2, TEST_DATA_SIZE/2)); auto bytes_transferred = asio::read(ssl, data, ec); @@ -265,7 +265,7 @@ class Asio_Stream_Tests final : public Test uint8_t buf[128]; error_code ec; - auto bytes_transferred = asio::read(ssl, asio::buffer(buf, sizeof(buf)), ec); + auto bytes_transferred = asio::read(ssl, asio::mutable_buffer(buf, sizeof(buf)), ec); Test::Result result("sync read_some error"); result.test_eq("didn't transfer anything", bytes_transferred, 0); @@ -293,7 +293,7 @@ class Asio_Stream_Tests final : public Test result.confirm("does not report an error", !ec); }; - asio::mutable_buffer buf = asio::buffer(data, TEST_DATA_SIZE); + asio::mutable_buffer buf {data, TEST_DATA_SIZE}; asio::async_read(ssl, buf, read_handler); socket.close_remote(); @@ -313,8 +313,8 @@ class Asio_Stream_Tests final : public Test std::vector<asio::mutable_buffer> data; uint8_t buf1[TEST_DATA_SIZE/2]; uint8_t buf2[TEST_DATA_SIZE/2]; - data.emplace_back(asio::buffer(buf1, TEST_DATA_SIZE/2)); - data.emplace_back(asio::buffer(buf2, TEST_DATA_SIZE/2)); + data.emplace_back(asio::mutable_buffer(buf1, TEST_DATA_SIZE/2)); + data.emplace_back(asio::mutable_buffer(buf2, TEST_DATA_SIZE/2)); Test::Result result("async read_some buffer sequence"); @@ -352,7 +352,7 @@ class Asio_Stream_Tests final : public Test result.confirm("propagates error code", (bool)ec); }; - asio::mutable_buffer buf = asio::buffer(data, TEST_DATA_SIZE); + asio::mutable_buffer buf {data, TEST_DATA_SIZE}; asio::async_read(ssl, buf, read_handler); socket.close_remote(); @@ -369,7 +369,7 @@ class Asio_Stream_Tests final : public Test AsioStream ssl{socket}; error_code ec; - auto bytes_transferred = asio::write(ssl, asio::buffer(TEST_DATA, TEST_DATA_SIZE), ec); + auto bytes_transferred = asio::write(ssl, asio::const_buffer(TEST_DATA, TEST_DATA_SIZE), ec); Test::Result result("sync write_some success"); result.confirm("writes the correct data", remote.str() == test_data()); @@ -394,10 +394,10 @@ class Asio_Stream_Tests final : public Test random_data.back() = '5'; std::vector<asio::const_buffer> data; - data.emplace_back(asio::buffer(random_data.data(), 1)); + data.emplace_back(asio::const_buffer(random_data.data(), 1)); for(std::size_t i = 1; i < random_data.size(); i += 1024) { - data.emplace_back(asio::buffer(random_data.data() + i, 1024)); + data.emplace_back(asio::const_buffer(random_data.data() + i, 1024)); } auto bytes_transferred = asio::write(ssl, data, ec); @@ -425,7 +425,7 @@ class Asio_Stream_Tests final : public Test AsioStream ssl{socket}; error_code ec; - auto bytes_transferred = asio::write(ssl, asio::buffer(TEST_DATA, TEST_DATA_SIZE), ec); + auto bytes_transferred = asio::write(ssl, asio::const_buffer(TEST_DATA, TEST_DATA_SIZE), ec); Test::Result result("sync write_some error"); result.test_eq("didn't transfer anything", bytes_transferred, 0); @@ -452,7 +452,7 @@ class Asio_Stream_Tests final : public Test result.confirm("does not report an error", !ec); }; - asio::async_write(ssl, asio::buffer(TEST_DATA, TEST_DATA_SIZE), write_handler); + asio::async_write(ssl, asio::const_buffer(TEST_DATA, TEST_DATA_SIZE), write_handler); ioc.run(); results.push_back(result); @@ -473,10 +473,10 @@ class Asio_Stream_Tests final : public Test random_data.back() = '5'; std::vector<asio::const_buffer> src; - src.emplace_back(asio::buffer(random_data.data(), 1)); + src.emplace_back(asio::const_buffer(random_data.data(), 1)); for(std::size_t i = 1; i < random_data.size(); i += 1024) { - src.emplace_back(asio::buffer(random_data.data() + i, 1024)); + src.emplace_back(asio::const_buffer(random_data.data() + i, 1024)); } Test::Result result("async write_some buffer sequence"); @@ -516,7 +516,7 @@ class Asio_Stream_Tests final : public Test result.confirm("propagates error code", (bool)ec); }; - asio::async_write(ssl, asio::buffer(TEST_DATA, TEST_DATA_SIZE), write_handler); + asio::async_write(ssl, asio::const_buffer(TEST_DATA, TEST_DATA_SIZE), write_handler); ioc.run(); results.push_back(result); |