Commit b60217fa authored by Neel Goyal's avatar Neel Goyal Committed by Facebook Github Bot

Add more types to OpenSSLPtrTypes

Summary: Add more types and a macro to make defining them easier.

Reviewed By: mingtaoy

Differential Revision: D6823450

fbshipit-source-id: eb13a8b48efb1625fc3f8035356812f918703c6d
parent 543aa5ca
......@@ -24,60 +24,62 @@
namespace folly {
namespace ssl {
// helper which translates (DEFINE_SSL_PTR_TYPE(Foo, FOO, FOO_free); into
// using FooDeleter = folly::static_function_deleter<FOO, &FOO_free>;
// using FooUniquePtr = std::unique_ptr<FOO, FooDeleter>;
#define DEFINE_SSL_PTR_TYPE(alias, object, deleter) \
using alias##Deleter = folly::static_function_deleter<object, &deleter>; \
using alias##UniquePtr = std::unique_ptr<object, alias##Deleter>
// ASN1
using ASN1TimeDeleter =
folly::static_function_deleter<ASN1_TIME, &ASN1_TIME_free>;
using ASN1TimeUniquePtr = std::unique_ptr<ASN1_TIME, ASN1TimeDeleter>;
DEFINE_SSL_PTR_TYPE(ASN1Time, ASN1_TIME, ASN1_TIME_free);
DEFINE_SSL_PTR_TYPE(ASN1Ia5Str, ASN1_IA5STRING, ASN1_IA5STRING_free);
DEFINE_SSL_PTR_TYPE(ASN1Int, ASN1_INTEGER, ASN1_INTEGER_free);
DEFINE_SSL_PTR_TYPE(ASN1Obj, ASN1_OBJECT, ASN1_OBJECT_free);
DEFINE_SSL_PTR_TYPE(ASN1Str, ASN1_STRING, ASN1_STRING_free);
DEFINE_SSL_PTR_TYPE(ASN1Type, ASN1_TYPE, ASN1_TYPE_free);
DEFINE_SSL_PTR_TYPE(ASN1UTF8Str, ASN1_UTF8STRING, ASN1_UTF8STRING_free);
// X509
using X509Deleter = folly::static_function_deleter<X509, &X509_free>;
using X509UniquePtr = std::unique_ptr<X509, X509Deleter>;
using X509ExtensionDeleter =
folly::static_function_deleter<X509_EXTENSION, &X509_EXTENSION_free>;
using X509ExtensionUniquePtr =
std::unique_ptr<X509_EXTENSION, X509ExtensionDeleter>;
using X509StoreDeleter =
folly::static_function_deleter<X509_STORE, &X509_STORE_free>;
using X509StoreUniquePtr = std::unique_ptr<X509_STORE, X509StoreDeleter>;
using X509StoreCtxDeleter =
folly::static_function_deleter<X509_STORE_CTX, &X509_STORE_CTX_free>;
using X509StoreCtxUniquePtr =
std::unique_ptr<X509_STORE_CTX, X509StoreCtxDeleter>;
DEFINE_SSL_PTR_TYPE(X509, X509, X509_free);
DEFINE_SSL_PTR_TYPE(X509Extension, X509_EXTENSION, X509_EXTENSION_free);
DEFINE_SSL_PTR_TYPE(X509Store, X509_STORE, X509_STORE_free);
DEFINE_SSL_PTR_TYPE(X509StoreCtx, X509_STORE_CTX, X509_STORE_CTX_free);
using X509VerifyParamDeleter =
folly::static_function_deleter<X509_VERIFY_PARAM, &X509_VERIFY_PARAM_free>;
using X509VerifyParam =
std::unique_ptr<X509_VERIFY_PARAM, X509VerifyParamDeleter>;
DEFINE_SSL_PTR_TYPE(GeneralName, GENERAL_NAME, GENERAL_NAME_free);
DEFINE_SSL_PTR_TYPE(GeneralNames, GENERAL_NAMES, GENERAL_NAMES_free);
DEFINE_SSL_PTR_TYPE(DistPointName, DIST_POINT_NAME, DIST_POINT_NAME_free);
DEFINE_SSL_PTR_TYPE(DistPoint, DIST_POINT, DIST_POINT_free);
DEFINE_SSL_PTR_TYPE(CrlDistPoints, CRL_DIST_POINTS, CRL_DIST_POINTS_free);
DEFINE_SSL_PTR_TYPE(X509Crl, X509_CRL, X509_CRL_free);
DEFINE_SSL_PTR_TYPE(X509Name, X509_NAME, X509_NAME_free);
DEFINE_SSL_PTR_TYPE(X509Req, X509_REQ, X509_REQ_free);
DEFINE_SSL_PTR_TYPE(X509Revoked, X509_REVOKED, X509_REVOKED_free);
// EVP
using EvpPkeyDel = folly::static_function_deleter<EVP_PKEY, &EVP_PKEY_free>;
using EvpPkeyUniquePtr = std::unique_ptr<EVP_PKEY, EvpPkeyDel>;
DEFINE_SSL_PTR_TYPE(EvpPkey, EVP_PKEY, EVP_PKEY_free);
using EvpPkeySharedPtr = std::shared_ptr<EVP_PKEY>;
// No EVP_PKEY_CTX <= 0.9.8b
#if OPENSSL_VERSION_NUMBER >= 0x10000002L
using EvpPkeyCtxDeleter =
folly::static_function_deleter<EVP_PKEY_CTX, &EVP_PKEY_CTX_free>;
using EvpPkeyCtxUniquePtr = std::unique_ptr<EVP_PKEY_CTX, EvpPkeyCtxDeleter>;
DEFINE_SSL_PTR_TYPE(EvpPkeyCtx, EVP_PKEY_CTX, EVP_PKEY_CTX_free);
#else
struct EVP_PKEY_CTX;
#endif
using EvpMdCtxDeleter =
folly::static_function_deleter<EVP_MD_CTX, &EVP_MD_CTX_free>;
using EvpMdCtxUniquePtr = std::unique_ptr<EVP_MD_CTX, EvpMdCtxDeleter>;
DEFINE_SSL_PTR_TYPE(EvpMdCtx, EVP_MD_CTX, EVP_MD_CTX_free);
// HMAC
using HmacCtxDeleter = folly::static_function_deleter<HMAC_CTX, &HMAC_CTX_free>;
using HmacCtxUniquePtr = std::unique_ptr<HMAC_CTX, HmacCtxDeleter>;
DEFINE_SSL_PTR_TYPE(HmacCtx, HMAC_CTX, HMAC_CTX_free);
// BIO
using BioMethodDeleter =
folly::static_function_deleter<BIO_METHOD, &BIO_meth_free>;
using BioMethodUniquePtr = std::unique_ptr<BIO_METHOD, BioMethodDeleter>;
using BioDeleter = folly::static_function_deleter<BIO, &BIO_vfree>;
using BioUniquePtr = std::unique_ptr<BIO, BioDeleter>;
using BioChainDeleter = folly::static_function_deleter<BIO, &BIO_free_all>;
using BioChainUniquePtr = std::unique_ptr<BIO, BioChainDeleter>;
DEFINE_SSL_PTR_TYPE(BioMethod, BIO_METHOD, BIO_meth_free);
DEFINE_SSL_PTR_TYPE(Bio, BIO, BIO_vfree);
DEFINE_SSL_PTR_TYPE(BioChain, BIO, BIO_free_all);
inline void BIO_free_fb(BIO* bio) {
CHECK_EQ(1, BIO_free(bio));
}
......@@ -85,26 +87,21 @@ using BioDeleterFb = folly::static_function_deleter<BIO, &BIO_free_fb>;
using BioUniquePtrFb = std::unique_ptr<BIO, BioDeleterFb>;
// RSA and EC
using RsaDeleter = folly::static_function_deleter<RSA, &RSA_free>;
using RsaUniquePtr = std::unique_ptr<RSA, RsaDeleter>;
DEFINE_SSL_PTR_TYPE(Rsa, RSA, RSA_free);
#ifndef OPENSSL_NO_EC
using EcKeyDeleter = folly::static_function_deleter<EC_KEY, &EC_KEY_free>;
using EcKeyUniquePtr = std::unique_ptr<EC_KEY, EcKeyDeleter>;
using EcGroupDeleter = folly::static_function_deleter<EC_GROUP, &EC_GROUP_free>;
using EcGroupUniquePtr = std::unique_ptr<EC_GROUP, EcGroupDeleter>;
using EcPointDeleter = folly::static_function_deleter<EC_POINT, &EC_POINT_free>;
using EcPointUniquePtr = std::unique_ptr<EC_POINT, EcPointDeleter>;
using EcdsaSignDeleter =
folly::static_function_deleter<ECDSA_SIG, &ECDSA_SIG_free>;
using EcdsaSigUniquePtr = std::unique_ptr<ECDSA_SIG, EcdsaSignDeleter>;
DEFINE_SSL_PTR_TYPE(EcKey, EC_KEY, EC_KEY_free);
DEFINE_SSL_PTR_TYPE(EcGroup, EC_GROUP, EC_GROUP_free);
DEFINE_SSL_PTR_TYPE(EcPoint, EC_POINT, EC_POINT_free);
DEFINE_SSL_PTR_TYPE(EcdsaSig, ECDSA_SIG, ECDSA_SIG_free);
#endif
// BIGNUMs
using BIGNUMDeleter = folly::static_function_deleter<BIGNUM, &BN_clear_free>;
using BIGNUMUniquePtr = std::unique_ptr<BIGNUM, BIGNUMDeleter>;
DEFINE_SSL_PTR_TYPE(BIGNUM, BIGNUM, BN_clear_free);
DEFINE_SSL_PTR_TYPE(BNCtx, BN_CTX, BN_CTX_free);
// SSL and SSL_CTX
using SSLDeleter = folly::static_function_deleter<SSL, &SSL_free>;
using SSLUniquePtr = std::unique_ptr<SSL, SSLDeleter>;
DEFINE_SSL_PTR_TYPE(SSL, SSL, SSL_free);
#undef DEFINE_SSL_PTR_TYPE
} // namespace ssl
} // namespace folly
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment