summaryrefslogtreecommitdiffstats
path: root/base/openssl_util.h
diff options
context:
space:
mode:
authorjoth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-17 09:57:18 +0000
committerjoth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-17 09:57:18 +0000
commit313834720d46a68071afe305975f8b70e9bc5782 (patch)
tree1d7b0dea339a8bcf3499cf29f27217cc985f35a1 /base/openssl_util.h
parent0d18ee21d5ddbfecf3951ac8fc0f5a30465e0ffe (diff)
downloadchromium_src-313834720d46a68071afe305975f8b70e9bc5782.zip
chromium_src-313834720d46a68071afe305975f8b70e9bc5782.tar.gz
chromium_src-313834720d46a68071afe305975f8b70e9bc5782.tar.bz2
Refactor EnsureOpenSSLInit and openssl_util into base
This allows the base/crypto methods to call EnsureOpenSSLInit. Also factors out the SSL_CTX and X509_STORE to be more closely associated with their consumers (ssl socket and X509Certificate resp.) rather than process wide globals. BUG=None TEST=None Review URL: http://codereview.chromium.org/4963002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66413 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/openssl_util.h')
-rw-r--r--base/openssl_util.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/base/openssl_util.h b/base/openssl_util.h
index ed4101f..1d290ae 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 ScopedOpenSSL {
+ public:
+ explicit ScopedOpenSSL(T* ptr_) : ptr_(ptr_) { }
+ ~ScopedOpenSSL() { 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();