/* Copyright (c) 2015, Google Inc. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #ifndef OPENSSL_HEADER_CRYPTO_TEST_SCOPED_TYPES_H #define OPENSSL_HEADER_CRYPTO_TEST_SCOPED_TYPES_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template struct OpenSSLDeleter { void operator()(T *obj) { func(obj); } }; template struct OpenSSLStackDeleter { void operator()(StackType *obj) { sk_pop_free(reinterpret_cast<_STACK*>(obj), reinterpret_cast(func)); } }; template struct OpenSSLFree { void operator()(T *buf) { OPENSSL_free(buf); } }; struct FileCloser { void operator()(FILE *file) { fclose(file); } }; template using ScopedOpenSSLType = std::unique_ptr>; template using ScopedOpenSSLStack = std::unique_ptr>; template class ScopedOpenSSLContext { public: ScopedOpenSSLContext() { init_func(&ctx_); } ~ScopedOpenSSLContext() { cleanup_func(&ctx_); } T *get() { return &ctx_; } const T *get() const { return &ctx_; } void Reset() { cleanup_func(&ctx_); init_func(&ctx_); } private: T ctx_; }; using ScopedBIO = ScopedOpenSSLType; using ScopedBIGNUM = ScopedOpenSSLType; using ScopedBN_CTX = ScopedOpenSSLType; using ScopedBN_MONT_CTX = ScopedOpenSSLType; using ScopedCMAC_CTX = ScopedOpenSSLType; using ScopedDH = ScopedOpenSSLType; using ScopedECDSA_SIG = ScopedOpenSSLType; using ScopedEC_GROUP = ScopedOpenSSLType; using ScopedEC_KEY = ScopedOpenSSLType; using ScopedEC_POINT = ScopedOpenSSLType; using ScopedEVP_PKEY = ScopedOpenSSLType; using ScopedEVP_PKEY_CTX = ScopedOpenSSLType; using ScopedPKCS8_PRIV_KEY_INFO = ScopedOpenSSLType; using ScopedPKCS12 = ScopedOpenSSLType; using ScopedRSA = ScopedOpenSSLType; using ScopedX509 = ScopedOpenSSLType; using ScopedX509_ALGOR = ScopedOpenSSLType; using ScopedX509_SIG = ScopedOpenSSLType; using ScopedX509Stack = ScopedOpenSSLStack; using ScopedCBB = ScopedOpenSSLContext; using ScopedEVP_AEAD_CTX = ScopedOpenSSLContext; using ScopedEVP_CIPHER_CTX = ScopedOpenSSLContext; using ScopedEVP_MD_CTX = ScopedOpenSSLContext; using ScopedHMAC_CTX = ScopedOpenSSLContext; using ScopedOpenSSLBytes = std::unique_ptr>; using ScopedOpenSSLString = std::unique_ptr>; using ScopedFILE = std::unique_ptr; #endif // OPENSSL_HEADER_CRYPTO_TEST_SCOPED_TYPES_H