Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
openssl_compat.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2024, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
5#pragma once
6
20#include <openssl/opensslv.h>
21#include <openssl/ssl.h>
22#include <openssl/err.h>
23#include <openssl/evp.h>
24
25// ============================================================================
26// Version Detection Macros
27// ============================================================================
28
40static_assert(OPENSSL_VERSION_NUMBER >= 0x30000000L,
41 "OpenSSL 3.x or newer is required. OpenSSL 1.1.x reached EOL on September 11, 2023.");
42
43// ============================================================================
44// Deprecation Warning Suppression for OpenSSL 3.x
45// ============================================================================
46
58#if defined(__GNUC__) || defined(__clang__)
59 #define NETWORK_OPENSSL_SUPPRESS_DEPRECATED_START \
60 _Pragma("GCC diagnostic push") \
61 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
62 #define NETWORK_OPENSSL_SUPPRESS_DEPRECATED_END \
63 _Pragma("GCC diagnostic pop")
64#elif defined(_MSC_VER)
65 #define NETWORK_OPENSSL_SUPPRESS_DEPRECATED_START \
66 __pragma(warning(push)) \
67 __pragma(warning(disable: 4996))
68 #define NETWORK_OPENSSL_SUPPRESS_DEPRECATED_END \
69 __pragma(warning(pop))
70#else
71 #define NETWORK_OPENSSL_SUPPRESS_DEPRECATED_START
72 #define NETWORK_OPENSSL_SUPPRESS_DEPRECATED_END
73#endif
74
75// ============================================================================
76// API Compatibility Utilities
77// ============================================================================
78
80{
81
86inline const char* openssl_version_string() noexcept
87{
88 return OpenSSL_version(OPENSSL_VERSION);
89}
90
97inline std::string get_openssl_error() noexcept
98{
99 unsigned long err = ERR_get_error();
100 if (err == 0)
101 {
102 return "No OpenSSL error";
103 }
104 char buf[256];
105 ERR_error_string_n(err, buf, sizeof(buf));
106 return std::string(buf);
107}
108
115inline void clear_openssl_errors() noexcept
116{
117 ERR_clear_error();
118}
119
120} // namespace kcenon::network::internal
121
122// ============================================================================
123// OpenSSL 3.x Provider Notes
124// ============================================================================
125
std::string get_openssl_error() noexcept
Get last OpenSSL error as string.
const char * openssl_version_string() noexcept
Get OpenSSL version string.
void clear_openssl_errors() noexcept
Clear all OpenSSL errors from the thread's error queue.