//////////////////////////////////////////////////////////////////////////////// // Copyright 2016 Google LLC. // // This software is licensed under the terms defined in the Widevine Master // License Agreement. For a copy of this agreement, please contact // widevine-licensing@google.com. //////////////////////////////////////////////////////////////////////////////// // // RAII wrapper classes for cleaning up various OpenSSL dynamically allocated // structures. #ifndef COMMON_OPENSSL_UTIL_H_ #define COMMON_OPENSSL_UTIL_H_ #include "openssl/bio.h" #include "openssl/evp.h" #include "openssl/pkcs7.h" #include "openssl/rsa.h" #include "openssl/x509v3.h" 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 OpenSSLStackOnlyDeleter { void operator()(StackType *obj) { sk_free(reinterpret_cast<_STACK *>(obj)); } }; template using ScopedOpenSSLType = std::unique_ptr>; template using ScopedOpenSSLStack = std::unique_ptr>; template using ScopedOpenSSLStackOnly = std::unique_ptr>; using ScopedBIGNUM = ScopedOpenSSLType; using ScopedBIO = ScopedOpenSSLType; using ScopedECGROUP = ScopedOpenSSLType; using ScopedECKEY = ScopedOpenSSLType; using ScopedECPOINT = ScopedOpenSSLType; using ScopedPKCS7 = ScopedOpenSSLType; using ScopedPKEY = ScopedOpenSSLType; using ScopedRSA = ScopedOpenSSLType; using ScopedX509 = ScopedOpenSSLType; using ScopedX509Extension = ScopedOpenSSLType; using ScopedX509Name = ScopedOpenSSLType; using ScopedX509NameEntry = ScopedOpenSSLType; using ScopedX509Store = ScopedOpenSSLType; using ScopedX509StoreCtx = ScopedOpenSSLType; using ScopedX509Req = ScopedOpenSSLType; using ScopedAsn1UtcTime = ScopedOpenSSLType; using ScopedAsn1Time = ScopedOpenSSLType; using ScopedAsn1Utc8String = ScopedOpenSSLType; using ScopedAsn1Integer = ScopedOpenSSLType; using ScopedAsn1Object = ScopedOpenSSLType; using ScopedAsn1OctetString = ScopedOpenSSLType; // XxxStack deallocates the stack and its members while XxxStackOnly deallocates // the stack only. using ScopedX509Stack = ScopedOpenSSLStack; using ScopedX509StackOnly = ScopedOpenSSLStackOnly; using ScopedX509InfoStack = ScopedOpenSSLStack; using ScopedX509InfoStackOnly = ScopedOpenSSLStackOnly; #endif // COMMON_OPENSSL_UTIL_H_