Skip to content

Commit

Permalink
introduce botan/boost_compat.h as feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
reneme committed Oct 18, 2023
1 parent 0981814 commit 8eaa184
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 33 deletions.
8 changes: 3 additions & 5 deletions src/lib/tls/asio/asio_async_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
#ifndef BOTAN_ASIO_ASYNC_OPS_H_
#define BOTAN_ASIO_ASYNC_OPS_H_

#include <botan/types.h>

#include <boost/version.hpp>
#if BOOST_VERSION >= 107300
#include <botan/boost_compat.h>
#if defined(BOTAN_FOUND_COMPATIBLE_BOOST_VERSION)

#include <botan/asio_error.h>

Expand Down Expand Up @@ -305,5 +303,5 @@ class AsyncHandshakeOperation : public AsyncBase<Handler, typename Stream::execu

#include <boost/asio/unyield.hpp>

#endif // BOOST_VERSION
#endif
#endif // BOTAN_ASIO_ASYNC_OPS_H_
8 changes: 3 additions & 5 deletions src/lib/tls/asio/asio_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
#ifndef BOTAN_ASIO_TLS_CONTEXT_H_
#define BOTAN_ASIO_TLS_CONTEXT_H_

#include <botan/types.h>

#include <boost/version.hpp>
#if BOOST_VERSION >= 107300
#include <botan/boost_compat.h>
#if defined(BOTAN_FOUND_COMPATIBLE_BOOST_VERSION)

#include <functional>

Expand Down Expand Up @@ -99,5 +97,5 @@ class Context {

} // namespace Botan::TLS

#endif // BOOST_VERSION
#endif
#endif // BOTAN_ASIO_TLS_CONTEXT_H_
8 changes: 3 additions & 5 deletions src/lib/tls/asio/asio_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
#ifndef BOTAN_ASIO_ERROR_H_
#define BOTAN_ASIO_ERROR_H_

#include <botan/types.h>

#include <boost/version.hpp>
#if BOOST_VERSION >= 107300
#include <botan/boost_compat.h>
#if defined(BOTAN_FOUND_COMPATIBLE_BOOST_VERSION)

#include <boost/system/system_error.hpp>

Expand Down Expand Up @@ -122,5 +120,5 @@ struct is_error_code_enum<Botan::ErrorType> {

} // namespace boost::system

#endif // BOOST_VERSION
#endif
#endif // BOTAN_ASIO_ERROR_H_
12 changes: 5 additions & 7 deletions src/lib/tls/asio/asio_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@
#ifndef BOTAN_ASIO_STREAM_H_
#define BOTAN_ASIO_STREAM_H_

#include <botan/types.h>

#include <boost/version.hpp>

// First version of boost asio that is prepared to use C++20 concepts
#if BOOST_VERSION >= 107300
#include <botan/boost_compat.h>
#if !defined(BOTAN_FOUND_COMPATIBLE_BOOST_VERSION)
#error Available boost headers are too old for the boost asio stream.
#else

#include <botan/asio_async_ops.h>
#include <botan/asio_context.h>
Expand Down Expand Up @@ -800,5 +798,5 @@ class Stream {

} // namespace Botan::TLS

#endif // BOOST_VERSION
#endif
#endif // BOTAN_ASIO_STREAM_H_
41 changes: 41 additions & 0 deletions src/lib/utils/boost/boost_compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Checks compatibility between the existing headers of Botan and boost
* (C) 2023 Jack Lloyd
* 2023 René Meusel - Rohde & Schwarz Cybersecurity
*
* Botan is released under the Simplified BSD License (see license.txt)
*/

#ifndef BOTAN_BOOST_COMPAT_H_
#define BOTAN_BOOST_COMPAT_H_

#include <botan/build.h>

#if defined(BOTAN_HAS_BOOST_ASIO)

/** @brief minimum supported boost version as defined in <boost/version.hpp>
*
* BOOST_VERSION % 100 is the patch level
* BOOST_VERSION / 100 % 1000 is the minor version
* BOOST_VERSION / 100000 is the major version
*
* until Botan 3.2.0
* 1.66.0 - first version to be compatible with Networking TS (N4656) and boost::beast
*
* as of Botan 3.3.0
* 1.73.0 - first version supporting the C++20 concepts syntax
*/
#define BOTAN_MINIMUM_SUPPORTED_BOOST_VERSION 107300

#include <boost/version.hpp>
#if BOOST_VERSION >= BOTAN_MINIMUM_SUPPORTED_BOOST_VERSION

/**
* Indicates that the local boost and botan headers are compatible.
*/
#define BOTAN_FOUND_COMPATIBLE_BOOST_VERSION 1

#endif

#endif
#endif
4 changes: 4 additions & 0 deletions src/lib/utils/boost/info.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ name -> "Boost"

load_on vendor

<header:public>
boost_compat.h
</header:public>

<libs>
linux -> rt
mingw -> ws2_32
Expand Down
8 changes: 4 additions & 4 deletions src/tests/test_tls_stream_integration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

#if defined(BOTAN_HAS_TLS) && defined(BOTAN_HAS_TLS_ASIO_STREAM) && defined(BOTAN_TARGET_OS_HAS_THREADS)

#include <boost/version.hpp>
#if BOOST_VERSION >= 107300
#include <botan/boost_compat.h>
#if defined(BOTAN_FOUND_COMPATIBLE_BOOST_VERSION)

#include <functional>
#include <memory>
Expand Down Expand Up @@ -835,5 +835,5 @@ BOTAN_REGISTER_TEST("tls", "tls_stream_integration", Tls_Stream_Integration_Test

} // namespace Botan_Tests

#endif // BOOST_VERSION
#endif // BOTAN_HAS_TLS && BOTAN_HAS_BOOST_ASIO
#endif
#endif // BOTAN_HAS_TLS && BOTAN_HAS_BOOST_ASIO
14 changes: 7 additions & 7 deletions src/tests/unit_asio_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

#if defined(BOTAN_HAS_TLS) && defined(BOTAN_HAS_TLS_ASIO_STREAM)

#include <botan/asio_stream.h>
#include <botan/tls_callbacks.h>
#include <botan/tls_session_manager_noop.h>
#include <botan/boost_compat.h>
#if defined(BOTAN_FOUND_COMPATIBLE_BOOST_VERSION)

#include <boost/version.hpp>
#if BOOST_VERSION >= 107300
#include <botan/asio_stream.h>
#include <botan/tls_callbacks.h>
#include <botan/tls_session_manager_noop.h>

#include <boost/beast/_experimental/test/stream.hpp>
#include <boost/bind.hpp>
Expand Down Expand Up @@ -736,5 +736,5 @@ BOTAN_REGISTER_TEST("tls", "tls_asio_stream", Asio_Stream_Tests);

} // namespace Botan_Tests

#endif // BOOST_VERSION
#endif // BOTAN_HAS_TLS && BOTAN_HAS_BOOST_ASIO
#endif
#endif // BOTAN_HAS_TLS && BOTAN_HAS_BOOST_ASIO

0 comments on commit 8eaa184

Please sign in to comment.