Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5410)

Unified Diff: base/openssl_util.h

Issue 4963002: Refactor EnsureOpenSSLInit and openssl_util into base (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/openssl_util.h
diff --git a/base/openssl_util.h b/base/openssl_util.h
index ed4101f4366b1a1723acd7b6e0073bbfe348929d..512fc20360fc5ab2227719551e3c4bedf8b62fed 100644
--- a/base/openssl_util.h
+++ b/base/openssl_util.h
@@ -11,6 +11,20 @@
namespace base {
+// A helper class that takes care of destroying OpenSSL objects when it goes out
+// of scope.
+template <typename T, void (*destructor)(T*)>
+class ScopedSSL {
wtc 2010/11/16 15:35:07 This template class should be named ScopedOpenSSL.
joth 2010/11/16 16:07:19 Done.
+ public:
+ explicit ScopedSSL(T* ptr_) : ptr_(ptr_) { }
+ ~ScopedSSL() { if (ptr_) (*destructor)(ptr_); }
+
+ T* get() const { return ptr_; }
+
+ private:
+ T* ptr_;
+};
+
// Provides a buffer of at least MIN_SIZE bytes, for use when calling OpenSSL's
// SHA256, HMAC, etc functions, adapting the buffer sizing rules to meet those
// of the our base wrapper APIs.
@@ -51,6 +65,12 @@ class ScopedOpenSSLSafeSizeBuffer {
DISALLOW_COPY_AND_ASSIGN(ScopedOpenSSLSafeSizeBuffer);
};
+// Initialize OpenSSL if it isn't already initialized. This must be called
+// before any other OpenSSL functions.
+// This function is thread-safe, and OpenSSL will only ever be initialized once.
+// OpenSSL will be properly shut down on program exit.
+void EnsureOpenSSLInit();
+
// Drains the OpenSSL ERR_get_error stack. On a debug build the error codes
// are send to VLOG(1), on a release build they are disregarded.
void ClearOpenSSLERRStack();

Powered by Google App Engine
This is Rietveld 408576698