Treat OpenSSL as a non-portable include
[folly.git] / folly / io / async / 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 X509StoreCtxDeleter =
36     folly::static_function_deleter<X509_STORE_CTX, &X509_STORE_CTX_free>;
37 using X509StoreCtxUniquePtr =
38     std::unique_ptr<X509_STORE_CTX, X509StoreCtxDeleter>;
39 using X509VerifyParamDeleter =
40     folly::static_function_deleter<X509_VERIFY_PARAM, &X509_VERIFY_PARAM_free>;
41 using X509VerifyParam =
42     std::unique_ptr<X509_VERIFY_PARAM, X509VerifyParamDeleter>;
43
44 // EVP
45 using EvpPkeyDel = folly::static_function_deleter<EVP_PKEY, &EVP_PKEY_free>;
46 using EvpPkeyUniquePtr = std::unique_ptr<EVP_PKEY, EvpPkeyDel>;
47 using EvpPkeySharedPtr = std::shared_ptr<EVP_PKEY>;
48
49 // No EVP_PKEY_CTX <= 0.9.8b
50 #if OPENSSL_VERSION_NUMBER >= 0x10000002L
51 using EvpPkeyCtxDeleter =
52     folly::static_function_deleter<EVP_PKEY_CTX, &EVP_PKEY_CTX_free>;
53 using EvpPkeyCtxUniquePtr = std::unique_ptr<EVP_PKEY_CTX, EvpPkeyCtxDeleter>;
54 #else
55 struct EVP_PKEY_CTX;
56 #endif
57
58 using EvpMdCtxDeleter =
59     folly::static_function_deleter<EVP_MD_CTX, &EVP_MD_CTX_free>;
60 using EvpMdCtxUniquePtr = std::unique_ptr<EVP_MD_CTX, EvpMdCtxDeleter>;
61
62 // HMAC
63 using HmacCtxDeleter = folly::static_function_deleter<HMAC_CTX, &HMAC_CTX_free>;
64 using HmacCtxUniquePtr = std::unique_ptr<HMAC_CTX, HmacCtxDeleter>;
65
66 // BIO
67 using BioMethodDeleter =
68     folly::static_function_deleter<BIO_METHOD, &BIO_meth_free>;
69 using BioMethodUniquePtr = std::unique_ptr<BIO_METHOD, BioMethodDeleter>;
70 using BioDeleter = folly::static_function_deleter<BIO, &BIO_vfree>;
71 using BioUniquePtr = std::unique_ptr<BIO, BioDeleter>;
72 using BioChainDeleter = folly::static_function_deleter<BIO, &BIO_free_all>;
73 using BioChainUniquePtr = std::unique_ptr<BIO, BioChainDeleter>;
74 inline void BIO_free_fb(BIO* bio) { CHECK_EQ(1, BIO_free(bio)); }
75 using BioDeleterFb = folly::static_function_deleter<BIO, &BIO_free_fb>;
76 using BioUniquePtrFb = std::unique_ptr<BIO, BioDeleterFb>;
77
78 // RSA and EC
79 using RsaDeleter = folly::static_function_deleter<RSA, &RSA_free>;
80 using RsaUniquePtr = std::unique_ptr<RSA, RsaDeleter>;
81 #ifndef OPENSSL_NO_EC
82 using EcKeyDeleter = folly::static_function_deleter<EC_KEY, &EC_KEY_free>;
83 using EcKeyUniquePtr = std::unique_ptr<EC_KEY, EcKeyDeleter>;
84 using EcGroupDeleter = folly::static_function_deleter<EC_GROUP, &EC_GROUP_free>;
85 using EcGroupUniquePtr = std::unique_ptr<EC_GROUP, EcGroupDeleter>;
86 using EcPointDeleter = folly::static_function_deleter<EC_POINT, &EC_POINT_free>;
87 using EcPointUniquePtr = std::unique_ptr<EC_POINT, EcPointDeleter>;
88 using EcdsaSignDeleter =
89     folly::static_function_deleter<ECDSA_SIG, &ECDSA_SIG_free>;
90 using EcdsaSigUniquePtr = std::unique_ptr<ECDSA_SIG, EcdsaSignDeleter>;
91 #endif
92
93 // BIGNUMs
94 using BIGNUMDeleter = folly::static_function_deleter<BIGNUM, &BN_clear_free>;
95 using BIGNUMUniquePtr = std::unique_ptr<BIGNUM, BIGNUMDeleter>;
96
97 // SSL and SSL_CTX
98 using SSLDeleter = folly::static_function_deleter<SSL, &SSL_free>;
99 using SSLUniquePtr = std::unique_ptr<SSL, SSLDeleter>;
100 }
101 }