aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRenĂ© Meusel <[email protected]>2019-02-19 15:20:58 +0100
committerHannes Rantzsch <[email protected]>2019-04-16 10:47:45 +0200
commit96ffc33270ce3487bdb1290612244ad9e84e7889 (patch)
tree8e6a83161ba1c585006d6cfdba2229c1cdb2ebd3 /src
parentae8fb39545a8d574fba15b3690093edce93e7b18 (diff)
move stream implemention into TLS namespace
Diffstat (limited to 'src')
-rw-r--r--src/lib/tls/asio/asio_async_handshake_op.h6
-rw-r--r--src/lib/tls/asio/asio_async_read_op.h7
-rw-r--r--src/lib/tls/asio/asio_async_write_op.h5
-rw-r--r--src/lib/tls/asio/asio_convert_exceptions.h56
-rw-r--r--src/lib/tls/asio/asio_error.h14
-rw-r--r--src/lib/tls/asio/asio_stream.h36
-rw-r--r--src/lib/tls/asio/asio_stream_base.h18
-rw-r--r--src/lib/tls/asio/asio_stream_core.h8
-rw-r--r--src/tests/unit_asio_stream.cpp16
9 files changed, 106 insertions, 60 deletions
diff --git a/src/lib/tls/asio/asio_async_handshake_op.h b/src/lib/tls/asio/asio_async_handshake_op.h
index 6ef7fdf94..5a5a79fbf 100644
--- a/src/lib/tls/asio/asio_async_handshake_op.h
+++ b/src/lib/tls/asio/asio_async_handshake_op.h
@@ -7,6 +7,9 @@
#include <botan/internal/asio_includes.h>
namespace Botan {
+
+namespace TLS {
+
template <class Channel, class StreamLayer, class Handler>
struct AsyncHandshakeOperation
{
@@ -81,6 +84,9 @@ struct AsyncHandshakeOperation
StreamLayer& nextLayer_;
Handler handler_;
};
+
+} // namespace TLS
+
} // namespace Botan
#endif
diff --git a/src/lib/tls/asio/asio_async_read_op.h b/src/lib/tls/asio/asio_async_read_op.h
index 56e5da7b6..6317fb8c7 100644
--- a/src/lib/tls/asio/asio_async_read_op.h
+++ b/src/lib/tls/asio/asio_async_read_op.h
@@ -7,6 +7,8 @@
namespace Botan {
+namespace TLS {
+
template <class Channel, class StreamLayer, class Handler,
class MutableBufferSequence>
struct AsyncReadOperation
@@ -69,6 +71,9 @@ struct AsyncReadOperation
Handler handler_;
MutableBufferSequence buffers_;
};
-} // namespace Botan
+
+} // namespace TLS
+
+} // namespace Botan
#endif
diff --git a/src/lib/tls/asio/asio_async_write_op.h b/src/lib/tls/asio/asio_async_write_op.h
index 28611fe1f..b91c0de11 100644
--- a/src/lib/tls/asio/asio_async_write_op.h
+++ b/src/lib/tls/asio/asio_async_write_op.h
@@ -6,6 +6,8 @@
namespace Botan {
+namespace TLS {
+
template <typename Handler>
struct AsyncWriteOperation
{
@@ -35,6 +37,9 @@ struct AsyncWriteOperation
Handler handler_;
std::size_t plainBytesTransferred_;
};
+
+} // namespace TLS
+
} // namespace Botan
#endif
diff --git a/src/lib/tls/asio/asio_convert_exceptions.h b/src/lib/tls/asio/asio_convert_exceptions.h
index 3a054be10..484be61b8 100644
--- a/src/lib/tls/asio/asio_convert_exceptions.h
+++ b/src/lib/tls/asio/asio_convert_exceptions.h
@@ -5,6 +5,9 @@
#include <botan/tls_exceptn.h>
namespace Botan {
+
+namespace TLS {
+
inline boost::system::error_code convertException()
{
try
@@ -13,7 +16,7 @@ inline boost::system::error_code convertException()
}
catch(Botan::TLS::Unexpected_Message& e)
{
- return make_error_code(Botan::error::unexpected_message);
+ return make_error_code(Botan::TLS::error::unexpected_message);
}
catch(Botan::TLS::TLS_Exception& e)
{
@@ -21,97 +24,100 @@ inline boost::system::error_code convertException()
}
catch(Botan::Unsupported_Argument& e)
{
- return make_error_code(Botan::error::unsupported_argument);
+ return make_error_code(Botan::TLS::error::unsupported_argument);
}
catch(Botan::Invalid_Key_Length& e)
{
- return make_error_code(Botan::error::invalid_key_length);
+ return make_error_code(Botan::TLS::error::invalid_key_length);
}
catch(Botan::Invalid_IV_Length& e)
{
- return make_error_code(Botan::error::invalid_iv_length);
+ return make_error_code(Botan::TLS::error::invalid_iv_length);
}
catch(Botan::Invalid_Algorithm_Name& e)
{
- return make_error_code(Botan::error::invalid_algorithm_name);
+ return make_error_code(Botan::TLS::error::invalid_algorithm_name);
}
catch(Botan::Encoding_Error& e)
{
- return make_error_code(Botan::error::encoding_error);
+ return make_error_code(Botan::TLS::error::encoding_error);
}
catch(Botan::Invalid_OID& e)
{
- return make_error_code(Botan::error::invalid_oid);
+ return make_error_code(Botan::TLS::error::invalid_oid);
}
catch(Botan::Decoding_Error& e)
{
- return make_error_code(Botan::error::decoding_error);
+ return make_error_code(Botan::TLS::error::decoding_error);
}
catch(Botan::Invalid_Argument& e)
{
- return make_error_code(Botan::error::invalid_argument);
+ return make_error_code(Botan::TLS::error::invalid_argument);
}
catch(Botan::Key_Not_Set& e)
{
- return make_error_code(Botan::error::key_not_set);
+ return make_error_code(Botan::TLS::error::key_not_set);
}
catch(Botan::PRNG_Unseeded& e)
{
- return make_error_code(Botan::error::prng_unseeded);
+ return make_error_code(Botan::TLS::error::prng_unseeded);
}
catch(Botan::Policy_Violation& e)
{
- return make_error_code(Botan::error::policy_violation);
+ return make_error_code(Botan::TLS::error::policy_violation);
}
catch(Botan::Invalid_State& e)
{
- return make_error_code(Botan::error::invalid_state);
+ return make_error_code(Botan::TLS::error::invalid_state);
}
catch(Botan::Algorithm_Not_Found& e)
{
- return make_error_code(Botan::error::algorithm_not_found);
+ return make_error_code(Botan::TLS::error::algorithm_not_found);
}
catch(Botan::Provider_Not_Found& e)
{
- return make_error_code(Botan::error::provider_not_found);
+ return make_error_code(Botan::TLS::error::provider_not_found);
}
catch(Botan::Lookup_Error& e)
{
- return make_error_code(Botan::error::lookup_error);
+ return make_error_code(Botan::TLS::error::lookup_error);
}
catch(Botan::Self_Test_Failure& e)
{
- return make_error_code(Botan::error::self_test_failure);
+ return make_error_code(Botan::TLS::error::self_test_failure);
}
catch(Botan::Internal_Error& e)
{
- return make_error_code(Botan::error::internal_error);
+ return make_error_code(Botan::TLS::error::internal_error);
}
catch(Botan::No_Provider_Found& e)
{
- return make_error_code(Botan::error::no_provider_found);
+ return make_error_code(Botan::TLS::error::no_provider_found);
}
catch(Botan::Integrity_Failure& e)
{
- return make_error_code(Botan::error::integrity_failure);
+ return make_error_code(Botan::TLS::error::integrity_failure);
}
catch(Botan::Stream_IO_Error& e)
{
- return make_error_code(Botan::error::stream_io_error);
+ return make_error_code(Botan::TLS::error::stream_io_error);
}
catch(Botan::Not_Implemented& e)
{
- return make_error_code(Botan::error::not_implemented);
+ return make_error_code(Botan::TLS::error::not_implemented);
}
catch(Botan::Exception& e)
{
- return make_error_code(Botan::error::unknown);
+ return make_error_code(Botan::TLS::error::unknown);
}
catch(std::exception& e)
{
- return make_error_code(Botan::error::unknown);
+ return make_error_code(Botan::TLS::error::unknown);
}
}
-}
+
+} // namespace TLS
+
+} // namespace Botan
#endif
diff --git a/src/lib/tls/asio/asio_error.h b/src/lib/tls/asio/asio_error.h
index a285dff43..776e4e70c 100644
--- a/src/lib/tls/asio/asio_error.h
+++ b/src/lib/tls/asio/asio_error.h
@@ -7,6 +7,8 @@
namespace Botan {
+namespace TLS {
+
using error_code = boost::system::error_code;
using error_category = boost::system::error_category;
@@ -135,7 +137,10 @@ inline error_code make_error_code(error c)
{
return error_code(static_cast<int>(c), botan_category());
}
-}
+
+} // namespace TLS
+
+} // namespace Botan
namespace boost {
namespace system {
@@ -145,11 +150,12 @@ template<> struct is_error_code_enum<Botan::TLS::Alert::Type>
static const bool value = true;
};
-template<> struct is_error_code_enum<Botan::error>
+template<> struct is_error_code_enum<Botan::TLS::error>
{
static const bool value = true;
};
-}
-}
+
+} // namespace system
+} // namespace boost
#endif
diff --git a/src/lib/tls/asio/asio_stream.h b/src/lib/tls/asio/asio_stream.h
index f6bac7b27..b21bc1fb5 100644
--- a/src/lib/tls/asio/asio_stream.h
+++ b/src/lib/tls/asio/asio_stream.h
@@ -23,6 +23,8 @@ class context;
namespace Botan {
+namespace TLS {
+
/**
* boost::asio compatible SSL/TLS stream based on TLS::Client or TLS::Server.
*/
@@ -54,7 +56,7 @@ class Stream : public StreamBase<Channel>
{
if(type != handshake_type::client)
{
- ec = make_error_code(Botan::error::not_implemented);
+ ec = make_error_code(Botan::TLS::error::not_implemented);
return false;
}
@@ -122,7 +124,7 @@ class Stream : public StreamBase<Channel>
boost::system::error_code& ec)
{
BOTAN_UNUSED(callback);
- ec = make_error_code(Botan::error::not_implemented);
+ ec = make_error_code(Botan::TLS::error::not_implemented);
}
void set_verify_depth(int depth)
@@ -135,7 +137,7 @@ class Stream : public StreamBase<Channel>
boost::system::error_code& ec)
{
BOTAN_UNUSED(depth);
- ec = make_error_code(Botan::error::not_implemented);
+ ec = make_error_code(Botan::TLS::error::not_implemented);
}
template <typename verify_mode>
@@ -150,7 +152,7 @@ class Stream : public StreamBase<Channel>
boost::system::error_code& ec)
{
BOTAN_UNUSED(v);
- ec = make_error_code(Botan::error::not_implemented);
+ ec = make_error_code(Botan::TLS::error::not_implemented);
}
//
@@ -196,7 +198,7 @@ class Stream : public StreamBase<Channel>
}
catch(...)
{
- ec = Botan::convertException();
+ ec = Botan::TLS::convertException();
return;
}
@@ -217,7 +219,7 @@ class Stream : public StreamBase<Channel>
boost::system::error_code& ec)
{
BOTAN_UNUSED(type, buffers);
- ec = make_error_code(Botan::error::not_implemented);
+ ec = make_error_code(Botan::TLS::error::not_implemented);
}
template <typename HandshakeHandler>
@@ -267,7 +269,7 @@ class Stream : public StreamBase<Channel>
}
catch(...)
{
- ec = Botan::convertException();
+ ec = Botan::TLS::convertException();
return;
}
writePendingTlsData(ec);
@@ -318,7 +320,7 @@ class Stream : public StreamBase<Channel>
}
catch(...)
{
- ec = Botan::convertException();
+ ec = Botan::TLS::convertException();
return 0;
}
@@ -348,7 +350,7 @@ class Stream : public StreamBase<Channel>
}
catch(...)
{
- ec = Botan::convertException();
+ ec = Botan::TLS::convertException();
return 0;
}
@@ -388,7 +390,7 @@ class Stream : public StreamBase<Channel>
catch(...)
{
// TODO: don't call directly
- handler(Botan::convertException(), 0);
+ handler(Botan::TLS::convertException(), 0);
return;
}
@@ -430,36 +432,38 @@ class Stream : public StreamBase<Channel>
}
template <typename Handler>
- Botan::AsyncHandshakeOperation<Channel, StreamLayer, Handler>
+ Botan::TLS::AsyncHandshakeOperation<Channel, StreamLayer, Handler>
create_async_handshake_op(Handler&& handler)
{
- return Botan::AsyncHandshakeOperation<Channel, StreamLayer, Handler>(
+ return Botan::TLS::AsyncHandshakeOperation<Channel, StreamLayer, Handler>(
native_handle(), this->core_, nextLayer_, std::forward<Handler>(handler));
}
template <typename Handler, typename MutableBufferSequence>
- Botan::AsyncReadOperation<Channel, StreamLayer, Handler,
+ Botan::TLS::AsyncReadOperation<Channel, StreamLayer, Handler,
MutableBufferSequence>
create_async_read_op(Handler&& handler,
const MutableBufferSequence& buffers)
{
- return Botan::AsyncReadOperation<Channel, StreamLayer, Handler,
+ return Botan::TLS::AsyncReadOperation<Channel, StreamLayer, Handler,
MutableBufferSequence>(
native_handle(), this->core_, nextLayer_, std::forward<Handler>(handler),
buffers);
}
template <typename Handler>
- Botan::AsyncWriteOperation<Handler>
+ Botan::TLS::AsyncWriteOperation<Handler>
create_async_write_op(Handler&& handler, std::size_t plainBytesTransferred)
{
- return Botan::AsyncWriteOperation<Handler>(
+ return Botan::TLS::AsyncWriteOperation<Handler>(
this->core_, std::forward<Handler>(handler), plainBytesTransferred);
}
StreamLayer nextLayer_;
};
+} // TLS
+
} // namespace Botan
#endif
diff --git a/src/lib/tls/asio/asio_stream_base.h b/src/lib/tls/asio/asio_stream_base.h
index 93a14bd5c..d475bb667 100644
--- a/src/lib/tls/asio/asio_stream_base.h
+++ b/src/lib/tls/asio/asio_stream_base.h
@@ -7,6 +7,8 @@
namespace Botan {
+namespace TLS {
+
template <class Channel>
class StreamBase
{
@@ -34,9 +36,9 @@ class StreamBase<Botan::TLS::Client>
StreamBase& operator=(const StreamBase&) = delete;
protected:
- Botan::StreamCore core_;
- Botan::AutoSeeded_RNG rng_;
- Botan::TLS::Client channel_;
+ Botan::TLS::StreamCore core_;
+ Botan::AutoSeeded_RNG rng_;
+ Botan::TLS::Client channel_;
};
template <>
@@ -54,11 +56,13 @@ class StreamBase<Botan::TLS::Server>
StreamBase& operator=(const StreamBase&) = delete;
protected:
- Botan::StreamCore core_;
- Botan::AutoSeeded_RNG rng_;
- Botan::TLS::Server channel_;
+ Botan::TLS::StreamCore core_;
+ Botan::AutoSeeded_RNG rng_;
+ Botan::TLS::Server channel_;
};
-} // namespace botan
+} // namespace TLS
+
+} // namespace Botan
#endif
diff --git a/src/lib/tls/asio/asio_stream_core.h b/src/lib/tls/asio/asio_stream_core.h
index caac6d06a..c2e1d0d0c 100644
--- a/src/lib/tls/asio/asio_stream_core.h
+++ b/src/lib/tls/asio/asio_stream_core.h
@@ -7,6 +7,9 @@
#include <vector>
namespace Botan {
+
+namespace TLS {
+
/**
* Contains the buffers for reading/sending, and the needed botan callbacks
*/
@@ -99,6 +102,9 @@ struct StreamCore : public Botan::TLS::Callbacks
Buffer receive_buffer_;
Buffer send_buffer_;
};
-} // namespace Botan
+
+} // namespace TLS
+
+} // namespace Botan
#endif
diff --git a/src/tests/unit_asio_stream.cpp b/src/tests/unit_asio_stream.cpp
index 91a7dc5f3..aed016005 100644
--- a/src/tests/unit_asio_stream.cpp
+++ b/src/tests/unit_asio_stream.cpp
@@ -33,7 +33,7 @@ bool contains(const void* a, const void* b) { return memcmp(a, b, sizeof(a)) ==
class MockChannel
{
public:
- MockChannel(Botan::StreamCore& core)
+ MockChannel(Botan::TLS::StreamCore& core)
: callbacks_(core)
, bytes_till_complete_record_(TEST_DATA_SIZE)
, active_(false)
@@ -58,9 +58,9 @@ class MockChannel
bool is_active() { return active_; }
protected:
- Botan::StreamCore& callbacks_;
- std::size_t bytes_till_complete_record_; // number of bytes still to read before tls record is completed
- bool active_;
+ Botan::TLS::StreamCore& callbacks_;
+ std::size_t bytes_till_complete_record_; // number of bytes still to read before tls record is completed
+ bool active_;
};
/**
@@ -122,6 +122,8 @@ struct MockSocket
namespace Botan {
+namespace TLS {
+
/**
* A specification of StreamBase for the MockChannel used in this test. It
* matches the specifications for StreamBase<Botan::TLS::Client> and
@@ -146,6 +148,8 @@ class StreamBase<Botan_Tests::MockChannel>
Botan_Tests::MockChannel channel_;
};
+} // namespace TLS
+
} // namespace Botan
namespace Botan_Tests {
@@ -160,7 +164,7 @@ namespace Botan_Tests {
*/
class ASIO_Stream_Tests final : public Test
{
- using AsioStream = Botan::Stream<MockSocket&, MockChannel>;
+ using AsioStream = Botan::TLS::Stream<MockSocket&, MockChannel>;
void test_sync_handshake(std::vector<Test::Result>& results)
{
@@ -506,7 +510,7 @@ namespace beast = boost::beast;
*/
class Async_Asio_Stream_Tests final : public Test
{
- using AsioStream = Botan::Stream<beast::test::stream&, MockChannel>;
+ using AsioStream = Botan::TLS::Stream<beast::test::stream&, MockChannel>;
beast::string_view test_data() const
{