annotate DEPENDENCIES/generic/include/boost/asio/ssl/old/basic_context.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 //
Chris@16 2 // ssl/old/basic_context.hpp
Chris@16 3 // ~~~~~~~~~~~~~~~~~~~~~~~~~
Chris@16 4 //
Chris@16 5 // Copyright (c) 2005 Voipster / Indrek dot Juhani at voipster dot com
Chris@101 6 // Copyright (c) 2005-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
Chris@16 7 //
Chris@16 8 // Distributed under the Boost Software License, Version 1.0. (See accompanying
Chris@16 9 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 10 //
Chris@16 11
Chris@16 12 #ifndef BOOST_ASIO_SSL_OLD_BASIC_CONTEXT_HPP
Chris@16 13 #define BOOST_ASIO_SSL_OLD_BASIC_CONTEXT_HPP
Chris@16 14
Chris@16 15 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
Chris@16 16 # pragma once
Chris@16 17 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
Chris@16 18
Chris@16 19 #include <boost/asio/detail/config.hpp>
Chris@16 20 #include <string>
Chris@16 21 #include <boost/noncopyable.hpp>
Chris@16 22 #include <boost/asio/detail/throw_error.hpp>
Chris@16 23 #include <boost/asio/error.hpp>
Chris@16 24 #include <boost/asio/io_service.hpp>
Chris@16 25 #include <boost/asio/ssl/context_base.hpp>
Chris@16 26
Chris@16 27 #include <boost/asio/detail/push_options.hpp>
Chris@16 28
Chris@16 29 namespace boost {
Chris@16 30 namespace asio {
Chris@16 31 namespace ssl {
Chris@16 32 namespace old {
Chris@16 33
Chris@16 34 /// SSL context.
Chris@16 35 template <typename Service>
Chris@16 36 class basic_context
Chris@16 37 : public context_base,
Chris@16 38 private boost::noncopyable
Chris@16 39 {
Chris@16 40 public:
Chris@16 41 /// The type of the service that will be used to provide context operations.
Chris@16 42 typedef Service service_type;
Chris@16 43
Chris@16 44 /// The native implementation type of the SSL context.
Chris@16 45 typedef typename service_type::impl_type impl_type;
Chris@16 46
Chris@16 47 /// Constructor.
Chris@16 48 basic_context(boost::asio::io_service& io_service, method m)
Chris@16 49 : service_(boost::asio::use_service<Service>(io_service)),
Chris@16 50 impl_(service_.null())
Chris@16 51 {
Chris@16 52 service_.create(impl_, m);
Chris@16 53 }
Chris@16 54
Chris@16 55 /// Destructor.
Chris@16 56 ~basic_context()
Chris@16 57 {
Chris@16 58 service_.destroy(impl_);
Chris@16 59 }
Chris@16 60
Chris@16 61 /// Get the underlying implementation in the native type.
Chris@16 62 /**
Chris@16 63 * This function may be used to obtain the underlying implementation of the
Chris@16 64 * context. This is intended to allow access to context functionality that is
Chris@16 65 * not otherwise provided.
Chris@16 66 */
Chris@16 67 impl_type impl()
Chris@16 68 {
Chris@16 69 return impl_;
Chris@16 70 }
Chris@16 71
Chris@16 72 /// Set options on the context.
Chris@16 73 /**
Chris@16 74 * This function may be used to configure the SSL options used by the context.
Chris@16 75 *
Chris@16 76 * @param o A bitmask of options. The available option values are defined in
Chris@16 77 * the context_base class. The options are bitwise-ored with any existing
Chris@16 78 * value for the options.
Chris@16 79 *
Chris@16 80 * @throws boost::system::system_error Thrown on failure.
Chris@16 81 */
Chris@16 82 void set_options(options o)
Chris@16 83 {
Chris@16 84 boost::system::error_code ec;
Chris@16 85 service_.set_options(impl_, o, ec);
Chris@16 86 boost::asio::detail::throw_error(ec);
Chris@16 87 }
Chris@16 88
Chris@16 89 /// Set options on the context.
Chris@16 90 /**
Chris@16 91 * This function may be used to configure the SSL options used by the context.
Chris@16 92 *
Chris@16 93 * @param o A bitmask of options. The available option values are defined in
Chris@16 94 * the context_base class. The options are bitwise-ored with any existing
Chris@16 95 * value for the options.
Chris@16 96 *
Chris@16 97 * @param ec Set to indicate what error occurred, if any.
Chris@16 98 */
Chris@16 99 boost::system::error_code set_options(options o,
Chris@16 100 boost::system::error_code& ec)
Chris@16 101 {
Chris@16 102 return service_.set_options(impl_, o, ec);
Chris@16 103 }
Chris@16 104
Chris@16 105 /// Set the peer verification mode.
Chris@16 106 /**
Chris@16 107 * This function may be used to configure the peer verification mode used by
Chris@16 108 * the context.
Chris@16 109 *
Chris@16 110 * @param v A bitmask of peer verification modes. The available verify_mode
Chris@16 111 * values are defined in the context_base class.
Chris@16 112 *
Chris@16 113 * @throws boost::system::system_error Thrown on failure.
Chris@16 114 */
Chris@16 115 void set_verify_mode(verify_mode v)
Chris@16 116 {
Chris@16 117 boost::system::error_code ec;
Chris@16 118 service_.set_verify_mode(impl_, v, ec);
Chris@16 119 boost::asio::detail::throw_error(ec);
Chris@16 120 }
Chris@16 121
Chris@16 122 /// Set the peer verification mode.
Chris@16 123 /**
Chris@16 124 * This function may be used to configure the peer verification mode used by
Chris@16 125 * the context.
Chris@16 126 *
Chris@16 127 * @param v A bitmask of peer verification modes. The available verify_mode
Chris@16 128 * values are defined in the context_base class.
Chris@16 129 *
Chris@16 130 * @param ec Set to indicate what error occurred, if any.
Chris@16 131 */
Chris@16 132 boost::system::error_code set_verify_mode(verify_mode v,
Chris@16 133 boost::system::error_code& ec)
Chris@16 134 {
Chris@16 135 return service_.set_verify_mode(impl_, v, ec);
Chris@16 136 }
Chris@16 137
Chris@16 138 /// Load a certification authority file for performing verification.
Chris@16 139 /**
Chris@16 140 * This function is used to load one or more trusted certification authorities
Chris@16 141 * from a file.
Chris@16 142 *
Chris@16 143 * @param filename The name of a file containing certification authority
Chris@16 144 * certificates in PEM format.
Chris@16 145 *
Chris@16 146 * @throws boost::system::system_error Thrown on failure.
Chris@16 147 */
Chris@16 148 void load_verify_file(const std::string& filename)
Chris@16 149 {
Chris@16 150 boost::system::error_code ec;
Chris@16 151 service_.load_verify_file(impl_, filename, ec);
Chris@16 152 boost::asio::detail::throw_error(ec);
Chris@16 153 }
Chris@16 154
Chris@16 155 /// Load a certification authority file for performing verification.
Chris@16 156 /**
Chris@16 157 * This function is used to load the certificates for one or more trusted
Chris@16 158 * certification authorities from a file.
Chris@16 159 *
Chris@16 160 * @param filename The name of a file containing certification authority
Chris@16 161 * certificates in PEM format.
Chris@16 162 *
Chris@16 163 * @param ec Set to indicate what error occurred, if any.
Chris@16 164 */
Chris@16 165 boost::system::error_code load_verify_file(const std::string& filename,
Chris@16 166 boost::system::error_code& ec)
Chris@16 167 {
Chris@16 168 return service_.load_verify_file(impl_, filename, ec);
Chris@16 169 }
Chris@16 170
Chris@16 171 /// Add a directory containing certificate authority files to be used for
Chris@16 172 /// performing verification.
Chris@16 173 /**
Chris@16 174 * This function is used to specify the name of a directory containing
Chris@16 175 * certification authority certificates. Each file in the directory must
Chris@16 176 * contain a single certificate. The files must be named using the subject
Chris@16 177 * name's hash and an extension of ".0".
Chris@16 178 *
Chris@16 179 * @param path The name of a directory containing the certificates.
Chris@16 180 *
Chris@16 181 * @throws boost::system::system_error Thrown on failure.
Chris@16 182 */
Chris@16 183 void add_verify_path(const std::string& path)
Chris@16 184 {
Chris@16 185 boost::system::error_code ec;
Chris@16 186 service_.add_verify_path(impl_, path, ec);
Chris@16 187 boost::asio::detail::throw_error(ec);
Chris@16 188 }
Chris@16 189
Chris@16 190 /// Add a directory containing certificate authority files to be used for
Chris@16 191 /// performing verification.
Chris@16 192 /**
Chris@16 193 * This function is used to specify the name of a directory containing
Chris@16 194 * certification authority certificates. Each file in the directory must
Chris@16 195 * contain a single certificate. The files must be named using the subject
Chris@16 196 * name's hash and an extension of ".0".
Chris@16 197 *
Chris@16 198 * @param path The name of a directory containing the certificates.
Chris@16 199 *
Chris@16 200 * @param ec Set to indicate what error occurred, if any.
Chris@16 201 */
Chris@16 202 boost::system::error_code add_verify_path(const std::string& path,
Chris@16 203 boost::system::error_code& ec)
Chris@16 204 {
Chris@16 205 return service_.add_verify_path(impl_, path, ec);
Chris@16 206 }
Chris@16 207
Chris@16 208 /// Use a certificate from a file.
Chris@16 209 /**
Chris@16 210 * This function is used to load a certificate into the context from a file.
Chris@16 211 *
Chris@16 212 * @param filename The name of the file containing the certificate.
Chris@16 213 *
Chris@16 214 * @param format The file format (ASN.1 or PEM).
Chris@16 215 *
Chris@16 216 * @throws boost::system::system_error Thrown on failure.
Chris@16 217 */
Chris@16 218 void use_certificate_file(const std::string& filename, file_format format)
Chris@16 219 {
Chris@16 220 boost::system::error_code ec;
Chris@16 221 service_.use_certificate_file(impl_, filename, format, ec);
Chris@16 222 boost::asio::detail::throw_error(ec);
Chris@16 223 }
Chris@16 224
Chris@16 225 /// Use a certificate from a file.
Chris@16 226 /**
Chris@16 227 * This function is used to load a certificate into the context from a file.
Chris@16 228 *
Chris@16 229 * @param filename The name of the file containing the certificate.
Chris@16 230 *
Chris@16 231 * @param format The file format (ASN.1 or PEM).
Chris@16 232 *
Chris@16 233 * @param ec Set to indicate what error occurred, if any.
Chris@16 234 */
Chris@16 235 boost::system::error_code use_certificate_file(const std::string& filename,
Chris@16 236 file_format format, boost::system::error_code& ec)
Chris@16 237 {
Chris@16 238 return service_.use_certificate_file(impl_, filename, format, ec);
Chris@16 239 }
Chris@16 240
Chris@16 241 /// Use a certificate chain from a file.
Chris@16 242 /**
Chris@16 243 * This function is used to load a certificate chain into the context from a
Chris@16 244 * file.
Chris@16 245 *
Chris@16 246 * @param filename The name of the file containing the certificate. The file
Chris@16 247 * must use the PEM format.
Chris@16 248 *
Chris@16 249 * @throws boost::system::system_error Thrown on failure.
Chris@16 250 */
Chris@16 251 void use_certificate_chain_file(const std::string& filename)
Chris@16 252 {
Chris@16 253 boost::system::error_code ec;
Chris@16 254 service_.use_certificate_chain_file(impl_, filename, ec);
Chris@16 255 boost::asio::detail::throw_error(ec);
Chris@16 256 }
Chris@16 257
Chris@16 258 /// Use a certificate chain from a file.
Chris@16 259 /**
Chris@16 260 * This function is used to load a certificate chain into the context from a
Chris@16 261 * file.
Chris@16 262 *
Chris@16 263 * @param filename The name of the file containing the certificate. The file
Chris@16 264 * must use the PEM format.
Chris@16 265 *
Chris@16 266 * @param ec Set to indicate what error occurred, if any.
Chris@16 267 */
Chris@16 268 boost::system::error_code use_certificate_chain_file(
Chris@16 269 const std::string& filename, boost::system::error_code& ec)
Chris@16 270 {
Chris@16 271 return service_.use_certificate_chain_file(impl_, filename, ec);
Chris@16 272 }
Chris@16 273
Chris@16 274 /// Use a private key from a file.
Chris@16 275 /**
Chris@16 276 * This function is used to load a private key into the context from a file.
Chris@16 277 *
Chris@16 278 * @param filename The name of the file containing the private key.
Chris@16 279 *
Chris@16 280 * @param format The file format (ASN.1 or PEM).
Chris@16 281 *
Chris@16 282 * @throws boost::system::system_error Thrown on failure.
Chris@16 283 */
Chris@16 284 void use_private_key_file(const std::string& filename, file_format format)
Chris@16 285 {
Chris@16 286 boost::system::error_code ec;
Chris@16 287 service_.use_private_key_file(impl_, filename, format, ec);
Chris@16 288 boost::asio::detail::throw_error(ec);
Chris@16 289 }
Chris@16 290
Chris@16 291 /// Use a private key from a file.
Chris@16 292 /**
Chris@16 293 * This function is used to load a private key into the context from a file.
Chris@16 294 *
Chris@16 295 * @param filename The name of the file containing the private key.
Chris@16 296 *
Chris@16 297 * @param format The file format (ASN.1 or PEM).
Chris@16 298 *
Chris@16 299 * @param ec Set to indicate what error occurred, if any.
Chris@16 300 */
Chris@16 301 boost::system::error_code use_private_key_file(const std::string& filename,
Chris@16 302 file_format format, boost::system::error_code& ec)
Chris@16 303 {
Chris@16 304 return service_.use_private_key_file(impl_, filename, format, ec);
Chris@16 305 }
Chris@16 306
Chris@16 307 /// Use an RSA private key from a file.
Chris@16 308 /**
Chris@16 309 * This function is used to load an RSA private key into the context from a
Chris@16 310 * file.
Chris@16 311 *
Chris@16 312 * @param filename The name of the file containing the RSA private key.
Chris@16 313 *
Chris@16 314 * @param format The file format (ASN.1 or PEM).
Chris@16 315 *
Chris@16 316 * @throws boost::system::system_error Thrown on failure.
Chris@16 317 */
Chris@16 318 void use_rsa_private_key_file(const std::string& filename, file_format format)
Chris@16 319 {
Chris@16 320 boost::system::error_code ec;
Chris@16 321 service_.use_rsa_private_key_file(impl_, filename, format, ec);
Chris@16 322 boost::asio::detail::throw_error(ec);
Chris@16 323 }
Chris@16 324
Chris@16 325 /// Use an RSA private key from a file.
Chris@16 326 /**
Chris@16 327 * This function is used to load an RSA private key into the context from a
Chris@16 328 * file.
Chris@16 329 *
Chris@16 330 * @param filename The name of the file containing the RSA private key.
Chris@16 331 *
Chris@16 332 * @param format The file format (ASN.1 or PEM).
Chris@16 333 *
Chris@16 334 * @param ec Set to indicate what error occurred, if any.
Chris@16 335 */
Chris@16 336 boost::system::error_code use_rsa_private_key_file(
Chris@16 337 const std::string& filename, file_format format,
Chris@16 338 boost::system::error_code& ec)
Chris@16 339 {
Chris@16 340 return service_.use_rsa_private_key_file(impl_, filename, format, ec);
Chris@16 341 }
Chris@16 342
Chris@16 343 /// Use the specified file to obtain the temporary Diffie-Hellman parameters.
Chris@16 344 /**
Chris@16 345 * This function is used to load Diffie-Hellman parameters into the context
Chris@16 346 * from a file.
Chris@16 347 *
Chris@16 348 * @param filename The name of the file containing the Diffie-Hellman
Chris@16 349 * parameters. The file must use the PEM format.
Chris@16 350 *
Chris@16 351 * @throws boost::system::system_error Thrown on failure.
Chris@16 352 */
Chris@16 353 void use_tmp_dh_file(const std::string& filename)
Chris@16 354 {
Chris@16 355 boost::system::error_code ec;
Chris@16 356 service_.use_tmp_dh_file(impl_, filename, ec);
Chris@16 357 boost::asio::detail::throw_error(ec);
Chris@16 358 }
Chris@16 359
Chris@16 360 /// Use the specified file to obtain the temporary Diffie-Hellman parameters.
Chris@16 361 /**
Chris@16 362 * This function is used to load Diffie-Hellman parameters into the context
Chris@16 363 * from a file.
Chris@16 364 *
Chris@16 365 * @param filename The name of the file containing the Diffie-Hellman
Chris@16 366 * parameters. The file must use the PEM format.
Chris@16 367 *
Chris@16 368 * @param ec Set to indicate what error occurred, if any.
Chris@16 369 */
Chris@16 370 boost::system::error_code use_tmp_dh_file(const std::string& filename,
Chris@16 371 boost::system::error_code& ec)
Chris@16 372 {
Chris@16 373 return service_.use_tmp_dh_file(impl_, filename, ec);
Chris@16 374 }
Chris@16 375
Chris@16 376 /// Set the password callback.
Chris@16 377 /**
Chris@16 378 * This function is used to specify a callback function to obtain password
Chris@16 379 * information about an encrypted key in PEM format.
Chris@16 380 *
Chris@16 381 * @param callback The function object to be used for obtaining the password.
Chris@16 382 * The function signature of the handler must be:
Chris@16 383 * @code std::string password_callback(
Chris@16 384 * std::size_t max_length, // The maximum size for a password.
Chris@16 385 * password_purpose purpose // Whether password is for reading or writing.
Chris@16 386 * ); @endcode
Chris@16 387 * The return value of the callback is a string containing the password.
Chris@16 388 *
Chris@16 389 * @throws boost::system::system_error Thrown on failure.
Chris@16 390 */
Chris@16 391 template <typename PasswordCallback>
Chris@16 392 void set_password_callback(PasswordCallback callback)
Chris@16 393 {
Chris@16 394 boost::system::error_code ec;
Chris@16 395 service_.set_password_callback(impl_, callback, ec);
Chris@16 396 boost::asio::detail::throw_error(ec);
Chris@16 397 }
Chris@16 398
Chris@16 399 /// Set the password callback.
Chris@16 400 /**
Chris@16 401 * This function is used to specify a callback function to obtain password
Chris@16 402 * information about an encrypted key in PEM format.
Chris@16 403 *
Chris@16 404 * @param callback The function object to be used for obtaining the password.
Chris@16 405 * The function signature of the handler must be:
Chris@16 406 * @code std::string password_callback(
Chris@16 407 * std::size_t max_length, // The maximum size for a password.
Chris@16 408 * password_purpose purpose // Whether password is for reading or writing.
Chris@16 409 * ); @endcode
Chris@16 410 * The return value of the callback is a string containing the password.
Chris@16 411 *
Chris@16 412 * @param ec Set to indicate what error occurred, if any.
Chris@16 413 */
Chris@16 414 template <typename PasswordCallback>
Chris@16 415 boost::system::error_code set_password_callback(PasswordCallback callback,
Chris@16 416 boost::system::error_code& ec)
Chris@16 417 {
Chris@16 418 return service_.set_password_callback(impl_, callback, ec);
Chris@16 419 }
Chris@16 420
Chris@16 421 private:
Chris@16 422 /// The backend service implementation.
Chris@16 423 service_type& service_;
Chris@16 424
Chris@16 425 /// The underlying native implementation.
Chris@16 426 impl_type impl_;
Chris@16 427 };
Chris@16 428
Chris@16 429 } // namespace old
Chris@16 430 } // namespace ssl
Chris@16 431 } // namespace asio
Chris@16 432 } // namespace boost
Chris@16 433
Chris@16 434 #include <boost/asio/detail/pop_options.hpp>
Chris@16 435
Chris@16 436 #endif // BOOST_ASIO_SSL_OLD_BASIC_CONTEXT_HPP