Simplify CryptoSSLRequestManager using unified futures API
[folly.git] / folly / io / async / ssl / OpenSSLPtrTypes.h
1 /*
2  * Copyright 2016 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 #include <openssl/bn.h>
21 #include <openssl/evp.h>
22 #include <openssl/rsa.h>
23 #include <openssl/ssl.h>
24 #ifndef OPENSSL_NO_EC
25 #include <openssl/ec.h>
26 #endif
27 #include <folly/Memory.h>
28 #include <openssl/bio.h>
29 #include <openssl/x509.h>
30
31 namespace folly {
32 namespace ssl {
33
34 // X509
35 using X509Deleter = folly::static_function_deleter<X509, &X509_free>;
36 using X509UniquePtr = std::unique_ptr<X509, X509Deleter>;
37 using X509StoreCtxDeleter =
38     folly::static_function_deleter<X509_STORE_CTX, &X509_STORE_CTX_free>;
39 using X509StoreCtxUniquePtr =
40     std::unique_ptr<X509_STORE_CTX, X509StoreCtxDeleter>;
41 using X509VerifyParamDeleter =
42     folly::static_function_deleter<X509_VERIFY_PARAM, &X509_VERIFY_PARAM_free>;
43 using X509VerifyParam =
44     std::unique_ptr<X509_VERIFY_PARAM, X509VerifyParamDeleter>;
45
46 // EVP
47 using EvpPkeyDel = folly::static_function_deleter<EVP_PKEY, &EVP_PKEY_free>;
48 using EvpPkeyUniquePtr = std::unique_ptr<EVP_PKEY, EvpPkeyDel>;
49 using EvpPkeySharedPtr = std::shared_ptr<EVP_PKEY>;
50
51 // No EVP_PKEY_CTX <= 0.9.8b
52 #if OPENSSL_VERSION_NUMBER >= 0x10000002L
53 using EvpPkeyCtxDeleter =
54     folly::static_function_deleter<EVP_PKEY_CTX, &EVP_PKEY_CTX_free>;
55 using EvpPkeyCtxUniquePtr = std::unique_ptr<EVP_PKEY_CTX, EvpPkeyCtxDeleter>;
56 #else
57 struct EVP_PKEY_CTX;
58 #endif
59 using EvpMdCtxDeleter =
60     folly::static_function_deleter<EVP_MD_CTX, &EVP_MD_CTX_destroy>;
61 using EvpMdCtxUniquePtr = std::unique_ptr<EVP_MD_CTX, EvpMdCtxDeleter>;
62
63 // BIO
64 using BioDeleter = folly::static_function_deleter<BIO, &BIO_vfree>;
65 using BioUniquePtr = std::unique_ptr<BIO, BioDeleter>;
66 using BioChainDeleter = folly::static_function_deleter<BIO, &BIO_free_all>;
67 using BioChainUniquePtr = std::unique_ptr<BIO, BioChainDeleter>;
68 inline void BIO_free_fb(BIO* bio) { CHECK_EQ(1, BIO_free(bio)); }
69 using BioDeleterFb = folly::static_function_deleter<BIO, &BIO_free_fb>;
70 using BioUniquePtrFb = std::unique_ptr<BIO, BioDeleterFb>;
71
72 // RSA and EC
73 using RsaDeleter = folly::static_function_deleter<RSA, &RSA_free>;
74 using RsaUniquePtr = std::unique_ptr<RSA, RsaDeleter>;
75 #ifndef OPENSSL_NO_EC
76 using EcKeyDeleter = folly::static_function_deleter<EC_KEY, &EC_KEY_free>;
77 using EcKeyUniquePtr = std::unique_ptr<EC_KEY, EcKeyDeleter>;
78 #endif
79
80 // BIGNUMs
81 using BIGNUMDeleter = folly::static_function_deleter<BIGNUM, &BN_clear_free>;
82 using BIGNUMUniquePtr = std::unique_ptr<BIGNUM, BIGNUMDeleter>;
83
84 // SSL and SSL_CTX
85 using SSLDeleter = folly::static_function_deleter<SSL, &SSL_free>;
86 using SSLUniquePtr = std::unique_ptr<SSL, SSLDeleter>;
87 }
88 }