aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2020-11-24 06:54:04 -0500
committerJack Lloyd <[email protected]>2020-11-24 06:54:04 -0500
commitdfb04b43d77b1d985e77096afd2f850964bfec8a (patch)
tree68cbd47d6a1feaedfcc816a7fc3475098792c6cd /src
parent02fbe09f89a928ec9def3980f9358cc8d7680464 (diff)
parentd4bd5cf689e7d69fae44aaf4c1774bdc254cb814 (diff)
Merge GH #2510 Fix some C++17 todos
Diffstat (limited to 'src')
-rw-r--r--src/lib/tls/asio/asio_stream.h63
-rw-r--r--src/lib/x509/certstor_system_macos/certstor_macos.cpp17
2 files changed, 37 insertions, 43 deletions
diff --git a/src/lib/tls/asio/asio_stream.h b/src/lib/tls/asio/asio_stream.h
index bc2d47cbf..42cb65a1e 100644
--- a/src/lib/tls/asio/asio_stream.h
+++ b/src/lib/tls/asio/asio_stream.h
@@ -666,14 +666,6 @@ class Stream
//! @brief Mark bytes in the send buffer as consumed, removing them from the buffer
void consume_send_buffer(std::size_t bytesConsumed) { m_send_buffer.consume(bytesConsumed); }
- // This is a helper construct to allow mocking the native_handle in test code. It is activated by explicitly
- // specifying a (mocked) channel type template parameter when constructing the stream and does not attempt to
- // instantiate the native_handle.
- // Note: once we have C++17 we can achieve this much more elegantly using constexpr if.
- template<class T = ChannelT>
- typename std::enable_if<!std::is_same<Channel, T>::value>::type
- setup_native_handle(Connection_Side, boost::system::error_code&) {}
-
/**
* @brief Create the native handle.
*
@@ -683,34 +675,39 @@ class Stream
* @param side The desired connection side (client or server)
* @param ec Set to indicate what error occurred, if any.
*/
- template<class T = ChannelT>
- typename std::enable_if<std::is_same<Channel, T>::value>::type
- setup_native_handle(Connection_Side side, boost::system::error_code& ec)
+ void setup_native_handle(Connection_Side side, boost::system::error_code& ec)
{
- try_with_error_code([&]
+ BOTAN_UNUSED(side); // workaround: GCC 9 produces a warning claiming side is unused
+
+ // Do not attempt to instantiate the native_handle when a custom (mocked) channel type template parameter has
+ // been specified. This allows mocking the native_handle in test code.
+ if constexpr(std::is_same<ChannelT, Channel>::value)
{
- if(side == CLIENT)
- {
- m_native_handle = std::unique_ptr<Client>(
- new Client(m_core,
- m_context.m_session_manager,
- m_context.m_credentials_manager,
- m_context.m_policy,
- m_context.m_rng,
- m_context.m_server_info,
- Protocol_Version::latest_tls_version()));
- }
- else
+ try_with_error_code([&]
{
- m_native_handle = std::unique_ptr<Server>(
- new Server(m_core,
- m_context.m_session_manager,
- m_context.m_credentials_manager,
- m_context.m_policy,
- m_context.m_rng,
- false /* no DTLS */));
- }
- }, ec);
+ if(side == CLIENT)
+ {
+ m_native_handle = std::unique_ptr<Client>(
+ new Client(m_core,
+ m_context.m_session_manager,
+ m_context.m_credentials_manager,
+ m_context.m_policy,
+ m_context.m_rng,
+ m_context.m_server_info,
+ Protocol_Version::latest_tls_version()));
+ }
+ else
+ {
+ m_native_handle = std::unique_ptr<Server>(
+ new Server(m_core,
+ m_context.m_session_manager,
+ m_context.m_credentials_manager,
+ m_context.m_policy,
+ m_context.m_rng,
+ false /* no DTLS */));
+ }
+ }, ec);
+ }
}
/** @brief Synchronously write encrypted data from the send buffer to the next layer.
diff --git a/src/lib/x509/certstor_system_macos/certstor_macos.cpp b/src/lib/x509/certstor_system_macos/certstor_macos.cpp
index 662ebd0ab..9885e33a8 100644
--- a/src/lib/x509/certstor_system_macos/certstor_macos.cpp
+++ b/src/lib/x509/certstor_system_macos/certstor_macos.cpp
@@ -209,16 +209,13 @@ class Certificate_Store_MacOS_Impl
void addParameter(CFStringRef key, std::vector<uint8_t> value)
{
- // TODO C++17: std::vector::emplace_back will return the reference
- // to the inserted object straight away.
- m_data_store.emplace_back(std::move(value));
- const auto& data = m_data_store.back();
-
- m_data_refs.emplace_back(CFDataCreateWithBytesNoCopy(kCFAllocatorDefault,
- data.data(),
- data.size(),
- kCFAllocatorNull));
- const auto& data_ref = m_data_refs.back();
+ const auto& data = m_data_store.emplace_back(std::move(value));
+
+ const auto& data_ref = m_data_refs.emplace_back(
+ CFDataCreateWithBytesNoCopy(kCFAllocatorDefault,
+ data.data(),
+ data.size(),
+ kCFAllocatorNull));
check_notnull(data_ref, "create CFDataRef of search object failed");
addParameter(key, data_ref.get());