Index: base/openssl_util.h |
diff --git a/base/openssl_util.h b/base/openssl_util.h |
index 1d290ae3ad0cd6dcb13206d943961ceb75bd2a8b..0f69c8f95f60551810cb441a520cab3ccb325533 100644 |
--- a/base/openssl_util.h |
+++ b/base/openssl_util.h |
@@ -16,10 +16,17 @@ namespace base { |
template <typename T, void (*destructor)(T*)> |
class ScopedOpenSSL { |
public: |
- explicit ScopedOpenSSL(T* ptr_) : ptr_(ptr_) { } |
+ ScopedOpenSSL() : ptr_(NULL) { } |
+ explicit ScopedOpenSSL(T* ptr) : ptr_(ptr) { } |
~ScopedOpenSSL() { if (ptr_) (*destructor)(ptr_); } |
T* get() const { return ptr_; } |
+ void reset(T* ptr) { |
+ if (ptr != ptr_) { |
+ if (ptr_) (*destructor)(ptr_); |
+ ptr_ = ptr; |
+ } |
+ } |
private: |
T* ptr_; |
@@ -72,9 +79,24 @@ class ScopedOpenSSLSafeSizeBuffer { |
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. |
+// are send to VLOG(1), on a release build they are disregarded. An optional |
+// |message| can be passed, which will be prepended to the error stack output |
+// if present. |
+void ClearOpenSSLERRStack(const char* message); |
wtc
2010/11/17 20:30:48
Please consult the Style Guide's recommendations o
joth
2010/11/18 12:52:47
Done.
It falls under the "overloads must be obviou
|
void ClearOpenSSLERRStack(); |
+// Place an instance of this class on the call stack to automatically clear |
+// the OpenSSL error stack on function exit. If |message| is not null it will |
+// be included in any error dump. |
+class OpenSSLErrStackTracer { |
+ public: |
+ explicit OpenSSLErrStackTracer(const char* message) : message_(message) {} |
+ ~OpenSSLErrStackTracer() { ClearOpenSSLERRStack(message_); } |
+ |
+ private: |
+ const char* const message_; |
+}; |
+ |
} // namespace base |
#endif // BASE_OPENSSL_UTIL_H_ |