Skip to content

Commit 8eaa184

Browse files
committed
introduce botan/boost_compat.h as feature flag
1 parent 0981814 commit 8eaa184

8 files changed

Lines changed: 70 additions & 33 deletions

File tree

src/lib/tls/asio/asio_async_ops.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99
#ifndef BOTAN_ASIO_ASYNC_OPS_H_
1010
#define BOTAN_ASIO_ASYNC_OPS_H_
1111

12-
#include <botan/types.h>
13-
14-
#include <boost/version.hpp>
15-
#if BOOST_VERSION >= 107300
12+
#include <botan/boost_compat.h>
13+
#if defined(BOTAN_FOUND_COMPATIBLE_BOOST_VERSION)
1614

1715
#include <botan/asio_error.h>
1816

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

306304
#include <boost/asio/unyield.hpp>
307305

308-
#endif // BOOST_VERSION
306+
#endif
309307
#endif // BOTAN_ASIO_ASYNC_OPS_H_

src/lib/tls/asio/asio_context.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99
#ifndef BOTAN_ASIO_TLS_CONTEXT_H_
1010
#define BOTAN_ASIO_TLS_CONTEXT_H_
1111

12-
#include <botan/types.h>
13-
14-
#include <boost/version.hpp>
15-
#if BOOST_VERSION >= 107300
12+
#include <botan/boost_compat.h>
13+
#if defined(BOTAN_FOUND_COMPATIBLE_BOOST_VERSION)
1614

1715
#include <functional>
1816

@@ -99,5 +97,5 @@ class Context {
9997

10098
} // namespace Botan::TLS
10199

102-
#endif // BOOST_VERSION
100+
#endif
103101
#endif // BOTAN_ASIO_TLS_CONTEXT_H_

src/lib/tls/asio/asio_error.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99
#ifndef BOTAN_ASIO_ERROR_H_
1010
#define BOTAN_ASIO_ERROR_H_
1111

12-
#include <botan/types.h>
13-
14-
#include <boost/version.hpp>
15-
#if BOOST_VERSION >= 107300
12+
#include <botan/boost_compat.h>
13+
#if defined(BOTAN_FOUND_COMPATIBLE_BOOST_VERSION)
1614

1715
#include <boost/system/system_error.hpp>
1816

@@ -122,5 +120,5 @@ struct is_error_code_enum<Botan::ErrorType> {
122120

123121
} // namespace boost::system
124122

125-
#endif // BOOST_VERSION
123+
#endif
126124
#endif // BOTAN_ASIO_ERROR_H_

src/lib/tls/asio/asio_stream.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
#ifndef BOTAN_ASIO_STREAM_H_
1111
#define BOTAN_ASIO_STREAM_H_
1212

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

2018
#include <botan/asio_async_ops.h>
2119
#include <botan/asio_context.h>
@@ -800,5 +798,5 @@ class Stream {
800798

801799
} // namespace Botan::TLS
802800

803-
#endif // BOOST_VERSION
801+
#endif
804802
#endif // BOTAN_ASIO_STREAM_H_

src/lib/utils/boost/boost_compat.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Checks compatibility between the existing headers of Botan and boost
3+
* (C) 2023 Jack Lloyd
4+
* 2023 René Meusel - Rohde & Schwarz Cybersecurity
5+
*
6+
* Botan is released under the Simplified BSD License (see license.txt)
7+
*/
8+
9+
#ifndef BOTAN_BOOST_COMPAT_H_
10+
#define BOTAN_BOOST_COMPAT_H_
11+
12+
#include <botan/build.h>
13+
14+
#if defined(BOTAN_HAS_BOOST_ASIO)
15+
16+
/** @brief minimum supported boost version as defined in <boost/version.hpp>
17+
*
18+
* BOOST_VERSION % 100 is the patch level
19+
* BOOST_VERSION / 100 % 1000 is the minor version
20+
* BOOST_VERSION / 100000 is the major version
21+
*
22+
* until Botan 3.2.0
23+
* 1.66.0 - first version to be compatible with Networking TS (N4656) and boost::beast
24+
*
25+
* as of Botan 3.3.0
26+
* 1.73.0 - first version supporting the C++20 concepts syntax
27+
*/
28+
#define BOTAN_MINIMUM_SUPPORTED_BOOST_VERSION 107300
29+
30+
#include <boost/version.hpp>
31+
#if BOOST_VERSION >= BOTAN_MINIMUM_SUPPORTED_BOOST_VERSION
32+
33+
/**
34+
* Indicates that the local boost and botan headers are compatible.
35+
*/
36+
#define BOTAN_FOUND_COMPATIBLE_BOOST_VERSION 1
37+
38+
#endif
39+
40+
#endif
41+
#endif

src/lib/utils/boost/info.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ name -> "Boost"
88

99
load_on vendor
1010

11+
<header:public>
12+
boost_compat.h
13+
</header:public>
14+
1115
<libs>
1216
linux -> rt
1317
mingw -> ws2_32

src/tests/test_tls_stream_integration.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

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

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

1717
#include <functional>
1818
#include <memory>
@@ -835,5 +835,5 @@ BOTAN_REGISTER_TEST("tls", "tls_stream_integration", Tls_Stream_Integration_Test
835835

836836
} // namespace Botan_Tests
837837

838-
#endif // BOOST_VERSION
839-
#endif // BOTAN_HAS_TLS && BOTAN_HAS_BOOST_ASIO
838+
#endif
839+
#endif // BOTAN_HAS_TLS && BOTAN_HAS_BOOST_ASIO

src/tests/unit_asio_stream.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010

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

13-
#include <botan/asio_stream.h>
14-
#include <botan/tls_callbacks.h>
15-
#include <botan/tls_session_manager_noop.h>
13+
#include <botan/boost_compat.h>
14+
#if defined(BOTAN_FOUND_COMPATIBLE_BOOST_VERSION)
1615

17-
#include <boost/version.hpp>
18-
#if BOOST_VERSION >= 107300
16+
#include <botan/asio_stream.h>
17+
#include <botan/tls_callbacks.h>
18+
#include <botan/tls_session_manager_noop.h>
1919

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

737737
} // namespace Botan_Tests
738738

739-
#endif // BOOST_VERSION
740-
#endif // BOTAN_HAS_TLS && BOTAN_HAS_BOOST_ASIO
739+
#endif
740+
#endif // BOTAN_HAS_TLS && BOTAN_HAS_BOOST_ASIO

0 commit comments

Comments
 (0)