Clarify folly::ssl::init documentation
[folly.git] / folly / ssl / OpenSSLPtrTypes.h
1 /*
2  * Copyright 2017 Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #pragma once
18
19 #include <glog/logging.h>
20
21 #include <folly/Memory.h>
22 #include <folly/portability/OpenSSL.h>
23
24 namespace folly {
25 namespace ssl {
26
27 // ASN1
28 using ASN1TimeDeleter =
29     folly::static_function_deleter<ASN1_TIME, &ASN1_TIME_free>;
30 using ASN1TimeUniquePtr = std::unique_ptr<ASN1_TIME, ASN1TimeDeleter>;
31
32 // X509
33 using X509Deleter = folly::static_function_deleter<X509, &X509_free>;
34 using X509UniquePtr = std::unique_ptr<X509, X509Deleter>;
35 using X509ExtensionDeleter =
36     folly::static_function_deleter<X509_EXTENSION, &X509_EXTENSION_free>;
37 using X509ExtensionUniquePtr =
38     std::unique_ptr<X509_EXTENSION, X509ExtensionDeleter>;
39 using X509StoreDeleter =
40     folly::static_function_deleter<X509_STORE, &X509_STORE_free>;
41 using X509StoreUniquePtr = std::unique_ptr<X509_STORE, X509StoreDeleter>;
42 using X509StoreCtxDeleter =
43     folly::static_function_deleter<X509_STORE_CTX, &X509_STORE_CTX_free>;
44 using X509StoreCtxUniquePtr =
45     std::unique_ptr<X509_STORE_CTX, X509StoreCtxDeleter>;
46 using X509VerifyParamDeleter =
47     folly::static_function_deleter<X509_VERIFY_PARAM, &X509_VERIFY_PARAM_free>;
48 using X509VerifyParam =
49     std::unique_ptr<X509_VERIFY_PARAM, X509VerifyParamDeleter>;
50
51 // EVP
52 using EvpPkeyDel = folly::static_function_deleter<EVP_PKEY, &EVP_PKEY_free>;
53 using EvpPkeyUniquePtr = std::unique_ptr<EVP_PKEY, EvpPkeyDel>;
54 using EvpPkeySharedPtr = std::shared_ptr<EVP_PKEY>;
55
56 // No EVP_PKEY_CTX <= 0.9.8b
57 #if OPENSSL_VERSION_NUMBER >= 0x10000002L
58 using EvpPkeyCtxDeleter =
59     folly::static_function_deleter<EVP_PKEY_CTX, &EVP_PKEY_CTX_free>;
60 using EvpPkeyCtxUniquePtr = std::unique_ptr<EVP_PKEY_CTX, EvpPkeyCtxDeleter>;
61 #else
62 struct EVP_PKEY_CTX;
63 #endif
64
65 using EvpMdCtxDeleter =
66     folly::static_function_deleter<EVP_MD_CTX, &EVP_MD_CTX_free>;
67 using EvpMdCtxUniquePtr = std::unique_ptr<EVP_MD_CTX, EvpMdCtxDeleter>;
68
69 // HMAC
70 using HmacCtxDeleter = folly::static_function_deleter<HMAC_CTX, &HMAC_CTX_free>;
71 using HmacCtxUniquePtr = std::unique_ptr<HMAC_CTX, HmacCtxDeleter>;
72
73 // BIO
74 using BioMethodDeleter =
75     folly::static_function_deleter<BIO_METHOD, &BIO_meth_free>;
76 using BioMethodUniquePtr = std::unique_ptr<BIO_METHOD, BioMethodDeleter>;
77 using BioDeleter = folly::static_function_deleter<BIO, &BIO_vfree>;
78 using BioUniquePtr = std::unique_ptr<BIO, BioDeleter>;
79 using BioChainDeleter = folly::static_function_deleter<BIO, &BIO_free_all>;
80 using BioChainUniquePtr = std::unique_ptr<BIO, BioChainDeleter>;
81 inline void BIO_free_fb(BIO* bio) {
82   CHECK_EQ(1, BIO_free(bio));
83 }
84 using BioDeleterFb = folly::static_function_deleter<BIO, &BIO_free_fb>;
85 using BioUniquePtrFb = std::unique_ptr<BIO, BioDeleterFb>;
86
87 // RSA and EC
88 using RsaDeleter = folly::static_function_deleter<RSA, &RSA_free>;
89 using RsaUniquePtr = std::unique_ptr<RSA, RsaDeleter>;
90 #ifndef OPENSSL_NO_EC
91 using EcKeyDeleter = folly::static_function_deleter<EC_KEY, &EC_KEY_free>;
92 using EcKeyUniquePtr = std::unique_ptr<EC_KEY, EcKeyDeleter>;
93 using EcGroupDeleter = folly::static_function_deleter<EC_GROUP, &EC_GROUP_free>;
94 using EcGroupUniquePtr = std::unique_ptr<EC_GROUP, EcGroupDeleter>;
95 using EcPointDeleter = folly::static_function_deleter<EC_POINT, &EC_POINT_free>;
96 using EcPointUniquePtr = std::unique_ptr<EC_POINT, EcPointDeleter>;
97 using EcdsaSignDeleter =
98     folly::static_function_deleter<ECDSA_SIG, &ECDSA_SIG_free>;
99 using EcdsaSigUniquePtr = std::unique_ptr<ECDSA_SIG, EcdsaSignDeleter>;
100 #endif
101
102 // BIGNUMs
103 using BIGNUMDeleter = folly::static_function_deleter<BIGNUM, &BN_clear_free>;
104 using BIGNUMUniquePtr = std::unique_ptr<BIGNUM, BIGNUMDeleter>;
105
106 // SSL and SSL_CTX
107 using SSLDeleter = folly::static_function_deleter<SSL, &SSL_free>;
108 using SSLUniquePtr = std::unique_ptr<SSL, SSLDeleter>;
109 } // namespace ssl
110 } // namespace folly