MongoDB C++ Driver 4.2.0
Loading...
Searching...
No Matches
tls.hpp
Go to the documentation of this file.
1// Copyright 2009-present MongoDB, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <mongocxx/options/tls-fwd.hpp> // IWYU pragma: export
18
19//
20
21#include <mongocxx/v1/tls.hpp> // IWYU pragma: export
22
23#include <memory> // IWYU pragma: keep: backward compatibility, to be removed.
24#include <string>
25#include <utility>
26
29
31
32namespace mongocxx {
33namespace v_noabi {
34namespace options {
35
39class tls {
40 public:
44 tls() = default;
45
49 /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() tls(v1::tls v);
50
54 explicit operator v1::tls() const {
55 v1::tls ret;
56
57 if (_pem_file) {
58 ret.pem_file(std::string{_pem_file->view()});
59 }
60
61 if (_pem_password) {
62 ret.pem_password(std::string{_pem_password->view()});
63 }
64
65 if (_ca_file) {
66 ret.ca_file(std::string{_ca_file->view()});
67 }
68
69 if (_ca_dir) {
70 ret.ca_dir(std::string{_ca_dir->view()});
71 }
72
73 if (_crl_file) {
74 ret.crl_file(std::string{_crl_file->view()});
75 }
76
77 if (_allow_invalid_certificates) {
78 ret.allow_invalid_certificates(*_allow_invalid_certificates);
79 }
80
81 return ret;
82 }
83
96 _pem_file = std::move(pem_file);
97 return *this;
98 }
99
108
120 _pem_password = std::move(pem_password);
121 return *this;
122 }
123
132
145 _ca_file = std::move(ca_file);
146 return *this;
147 }
148
157
169 _ca_dir = std::move(ca_dir);
170 return *this;
171 }
172
181
193 _crl_file = std::move(crl_file);
194 return *this;
195 }
196
205
217 _allow_invalid_certificates = std::move(allow_invalid_certificates);
218 return *this;
219 }
220
227 return _allow_invalid_certificates;
228 }
229
230 class internal;
231
232 private:
238 bsoncxx::v_noabi::stdx::optional<bool> _allow_invalid_certificates;
239};
240
241} // namespace options
242} // namespace v_noabi
243} // namespace mongocxx
244
245namespace mongocxx {
246namespace v_noabi {
247
252 return {std::move(v)};
253}
254
259 return v1::tls{v};
260}
261
262} // namespace v_noabi
263} // namespace mongocxx
264
266
A polyfill for std::optional<T>.
Definition optional.hpp:799
A view-or-value variant type for strings.
Definition view_or_value.hpp:41
tls()=default
Default initialization.
Options related to TLS configuration.
Definition tls.hpp:48
tls & ca_file(std::string v)
Set the "ca_file" field.
tls & allow_invalid_certificates(bool v)
Set the "weak_cert_validation" field.
tls & crl_file(std::string v)
Set the "crl_file" field.
tls & ca_dir(std::string v)
Set the "ca_dir" field.
tls & pem_file(std::string v)
Set the "pem_file" field.
tls & pem_password(std::string v)
Set the "pem_pwd" field.
Used by mongocxx::v_noabi::options::client::tls_opts.
Definition tls.hpp:39
tls & ca_dir(bsoncxx::v_noabi::string::view_or_value ca_dir)
The path to the Certificate Authority directory.
Definition tls.hpp:168
tls & pem_file(bsoncxx::v_noabi::string::view_or_value pem_file)
The path to the .pem file containing a public key certificate and its associated private key.
Definition tls.hpp:95
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::string::view_or_value > const & pem_file() const
Retrieves the current path to the .pem file.
Definition tls.hpp:105
tls & allow_invalid_certificates(bool allow_invalid_certificates)
If true, the driver will not verify the server's CA file.
Definition tls.hpp:216
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::string::view_or_value > const & pem_password() const
Retrieves the current decryption pass phrase.
Definition tls.hpp:129
tls & crl_file(bsoncxx::v_noabi::string::view_or_value crl_file)
The path to the .pem file that contains revoked certificates.
Definition tls.hpp:192
tls & ca_file(bsoncxx::v_noabi::string::view_or_value ca_file)
The path to the .pem file that contains the root certificate chain from the Certificate Authority.
Definition tls.hpp:144
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::string::view_or_value > const & ca_dir() const
Retrieves the current path to the CA directory.
Definition tls.hpp:178
bsoncxx::v_noabi::stdx::optional< bool > const & allow_invalid_certificates() const
Retrieves whether or not the driver will check the server's CA file.
Definition tls.hpp:226
tls()=default
Default initialization.
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::string::view_or_value > const & ca_file() const
Retrieves the current path to the CA file.
Definition tls.hpp:154
tls & pem_password(bsoncxx::v_noabi::string::view_or_value pem_password)
The pass phrase used to decrypt an encrypted PEM file.
Definition tls.hpp:119
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::string::view_or_value > const & crl_file() const
Retrieves the current path to the .pem file that contains revoked certificates.
Definition tls.hpp:202
#define MONGOCXX_ABI_EXPORT_CDECL(...)
Equivalent to MONGOCXX_ABI_EXPORT with MONGOCXX_ABI_CDECL.
Definition export.hpp:52
The mongocxx v_noabi macro guard postlude header.
The mongocxx v_noabi macro guard prelude header.
Declares entities whose ABI stability is guaranteed for documented symbols.
Declares entities representing options to use with various commands.
Declares entities whose ABI stability is NOT guaranteed.
v1::bulk_write to_v1(v_noabi::bulk_write v)
Convert to the mongocxx::v1 equivalent of v.
Definition bulk_write.hpp:162
v_noabi::bulk_write from_v1(v1::bulk_write v)
Convert to the mongocxx::v_noabi equivalent of v.
Definition bulk_write.hpp:155
The top-level namespace within which all mongocxx library entities are declared.
Provides bsoncxx::v_noabi::string::view_or_value.
Provides mongocxx::v1::tls.
Provides std::optional-related polyfills for library API usage.
Declares mongocxx::v_noabi::options::tls.