mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Core/Misc: Minor refactors in BaseEncoding and SslSocket to prepare for future bnetserver changes
This commit is contained in:
@@ -49,7 +49,7 @@ struct B32Impl
|
||||
return Trinity::Impl::GenericBaseEncoding<B32Impl>::Encode(data);
|
||||
}
|
||||
|
||||
/*static*/ Optional<std::vector<uint8>> Trinity::Encoding::Base32::Decode(std::string const& data)
|
||||
/*static*/ Optional<std::vector<uint8>> Trinity::Encoding::Base32::Decode(std::string_view data)
|
||||
{
|
||||
return Trinity::Impl::GenericBaseEncoding<B32Impl>::Decode(data);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "Define.h"
|
||||
#include "Optional.h"
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace Trinity
|
||||
@@ -30,7 +31,7 @@ namespace Encoding
|
||||
struct TC_COMMON_API Base32
|
||||
{
|
||||
static std::string Encode(std::vector<uint8> const& data);
|
||||
static Optional<std::vector<uint8>> Decode(std::string const& data);
|
||||
static Optional<std::vector<uint8>> Decode(std::string_view data);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ struct B64Impl
|
||||
return Trinity::Impl::GenericBaseEncoding<B64Impl>::Encode(data);
|
||||
}
|
||||
|
||||
/*static*/ Optional<std::vector<uint8>> Trinity::Encoding::Base64::Decode(std::string const& data)
|
||||
/*static*/ Optional<std::vector<uint8>> Trinity::Encoding::Base64::Decode(std::string_view data)
|
||||
{
|
||||
return Trinity::Impl::GenericBaseEncoding<B64Impl>::Decode(data);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "Define.h"
|
||||
#include "Optional.h"
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace Trinity
|
||||
@@ -30,7 +31,7 @@ namespace Encoding
|
||||
struct TC_COMMON_API Base64
|
||||
{
|
||||
static std::string Encode(std::vector<uint8> const& data);
|
||||
static Optional<std::vector<uint8>> Decode(std::string const& data);
|
||||
static Optional<std::vector<uint8>> Decode(std::string_view data);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "Optional.h"
|
||||
#include <numeric>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace Trinity
|
||||
@@ -100,7 +101,7 @@ struct GenericBaseEncoding
|
||||
return s;
|
||||
}
|
||||
|
||||
static Optional<std::vector<uint8>> Decode(std::string const& data)
|
||||
static Optional<std::vector<uint8>> Decode(std::string_view data)
|
||||
{
|
||||
auto it = data.begin(), end = data.end();
|
||||
if (it == end)
|
||||
|
||||
@@ -24,11 +24,11 @@
|
||||
|
||||
namespace boostssl = boost::asio::ssl;
|
||||
|
||||
template<class SslContext>
|
||||
template<class SslContext, class Stream = boostssl::stream<boost::asio::ip::tcp::socket>>
|
||||
class SslSocket
|
||||
{
|
||||
public:
|
||||
explicit SslSocket(boost::asio::ip::tcp::socket&& socket) : _socket(std::move(socket)), _sslSocket(_socket, SslContext::instance())
|
||||
explicit SslSocket(boost::asio::ip::tcp::socket&& socket) : _sslSocket(std::move(socket), SslContext::instance())
|
||||
{
|
||||
_sslSocket.set_verify_mode(boostssl::verify_none);
|
||||
}
|
||||
@@ -36,13 +36,13 @@ public:
|
||||
// adapting tcp::socket api
|
||||
void close(boost::system::error_code& error)
|
||||
{
|
||||
_socket.close(error);
|
||||
_sslSocket.lowest_layer().close(error);
|
||||
}
|
||||
|
||||
void shutdown(boost::asio::socket_base::shutdown_type what, boost::system::error_code& shutdownError)
|
||||
{
|
||||
_sslSocket.shutdown(shutdownError);
|
||||
_socket.shutdown(what, shutdownError);
|
||||
_sslSocket.lowest_layer().shutdown(what, shutdownError);
|
||||
}
|
||||
|
||||
template<typename MutableBufferSequence, typename ReadHandlerType>
|
||||
@@ -66,12 +66,12 @@ public:
|
||||
template<typename SettableSocketOption>
|
||||
void set_option(SettableSocketOption const& option, boost::system::error_code& error)
|
||||
{
|
||||
_socket.set_option(option, error);
|
||||
_sslSocket.lowest_layer().set_option(option, error);
|
||||
}
|
||||
|
||||
boost::asio::ip::tcp::socket::endpoint_type remote_endpoint() const
|
||||
{
|
||||
return _socket.remote_endpoint();
|
||||
return _sslSocket.lowest_layer().remote_endpoint();
|
||||
}
|
||||
|
||||
// ssl api
|
||||
@@ -81,9 +81,8 @@ public:
|
||||
_sslSocket.async_handshake(type, std::move(handler));
|
||||
}
|
||||
|
||||
private:
|
||||
boost::asio::ip::tcp::socket _socket;
|
||||
boostssl::stream<boost::asio::ip::tcp::socket&> _sslSocket;
|
||||
protected:
|
||||
Stream _sslSocket;
|
||||
};
|
||||
|
||||
#endif // SslSocket_h__
|
||||
|
||||
Reference in New Issue
Block a user