Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 08:52:42

0001 //
0002 // Copyright (c) 2019-2025 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& 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     static asio::ssl::context ctx(asio::ssl::context::tlsv12_client);
0023     return ctx;
0024 }
0025 
0026 class ssl_context_with_default
0027 {
0028     asio::ssl::context* impl_;
0029 
0030 public:
0031     ssl_context_with_default(asio::ssl::context* ctx) noexcept : impl_(ctx) {}
0032 
0033     asio::ssl::context& get()
0034     {
0035         if (impl_ == nullptr)
0036             impl_ = &default_ssl_context();
0037         return *impl_;
0038     }
0039 
0040     // Exposed for the sake of testing
0041     const asio::ssl::context* get_ptr() const noexcept { return impl_; }
0042 };
0043 
0044 }  // namespace detail
0045 }  // namespace mysql
0046 }  // namespace boost
0047 
0048 #endif