// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CRYPTO_SCOPED_OPENSSL_TYPES_H_ #define CRYPTO_SCOPED_OPENSSL_TYPES_H_ #include #include #include #include #include #include #include #include #include #include "base/memory/scoped_ptr.h" namespace crypto { // Simplistic helper that wraps a call to a deleter function. In a C++11 world, // this would be std::function<>. An alternative would be to re-use // base::internal::RunnableAdapter<>, but that's far too heavy weight. template struct OpenSSLDestroyer { void operator()(Type* ptr) const { Destroyer(ptr); } }; template using ScopedOpenSSL = scoped_ptr>; struct OpenSSLFree { void operator()(uint8_t* ptr) const { OPENSSL_free(ptr); } }; // Several typedefs are provided for crypto-specific primitives, for // short-hand and prevalence. Note that OpenSSL types related to X.509 are // intentionally not included, as crypto/ does not generally deal with // certificates or PKI. using ScopedBIGNUM = ScopedOpenSSL; using ScopedEC_Key = ScopedOpenSSL; using ScopedBIO = ScopedOpenSSL; using ScopedDSA = ScopedOpenSSL; using ScopedECDSA_SIG = ScopedOpenSSL; using ScopedEC_GROUP = ScopedOpenSSL; using ScopedEC_KEY = ScopedOpenSSL; using ScopedEC_POINT = ScopedOpenSSL; using ScopedEVP_MD_CTX = ScopedOpenSSL; using ScopedEVP_PKEY = ScopedOpenSSL; using ScopedEVP_PKEY_CTX = ScopedOpenSSL; using ScopedRSA = ScopedOpenSSL; // The bytes must have been allocated with OPENSSL_malloc. using ScopedOpenSSLBytes = scoped_ptr; } // namespace crypto #endif // CRYPTO_SCOPED_OPENSSL_TYPES_H_