Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-19 08:33:52

0001 //
0002 // Copyright (c) 2019-2024 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 
0008 #ifndef BOOST_MYSQL_IMPL_INTERNAL_SSL_CONTEXT_WITH_DEFAULT_HPP
0009 #define BOOST_MYSQL_IMPL_INTERNAL_SSL_CONTEXT_WITH_DEFAULT_HPP
0010 
0011 #include <boost/asio/ssl/context.hpp>
0012 #include <boost/variant2/variant.hpp>
0013 
0014 namespace boost {
0015 namespace mysql {
0016 namespace detail {
0017 
0018 inline asio::ssl::context create_default_ssl_context()
0019 {
0020     // As of MySQL 5.7.35, support for previous TLS versions is deprecated,
0021     // so this is a secure default. User can override it if they want
0022     asio::ssl::context ctx(asio::ssl::context::tlsv12_client);
0023     return ctx;
0024 }
0025 
0026 inline asio::ssl::context& default_ssl_context()
0027 {
0028     static asio::ssl::context ctx = create_default_ssl_context();
0029     return ctx;
0030 }
0031 
0032 class ssl_context_with_default
0033 {
0034     asio::ssl::context* impl_;
0035 
0036 public:
0037     ssl_context_with_default(asio::ssl::context* ctx) noexcept : impl_(ctx) {}
0038 
0039     asio::ssl::context& get()
0040     {
0041         if (impl_ == nullptr)
0042             impl_ = &default_ssl_context();
0043         return *impl_;
0044     }
0045 
0046     // Exposed for the sake of testing
0047     const asio::ssl::context* get_ptr() const noexcept { return impl_; }
0048 };
0049 
0050 }  // namespace detail
0051 }  // namespace mysql
0052 }  // namespace boost
0053 
0054 #endif