Chromium Code Reviews| Index: base/openssl_util.h |
| diff --git a/base/openssl_util.h b/base/openssl_util.h |
| index 1d290ae3ad0cd6dcb13206d943961ceb75bd2a8b..ef9bd6784b782df4d6461f8e2e8c8c0743fce713 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); |
| void ClearOpenSSLERRStack(); |
| +// Place an instance of this class on the call stack to automatically clear |
| +// the OpenSSL error stack on function exit. The |message| passed, if not null, |
| +// we be included in any error dump. |
|
bulach
2010/11/17 14:35:09
s/we be/will be/
but perhaps even more direct:
If
joth
2010/11/17 14:49:31
Done.
|
| +class OpenSSLErrStackTracer { |
| + public: |
| + OpenSSLErrStackTracer(const char* message) : message_(message) {} |
|
bulach
2010/11/17 14:35:09
explicit
joth
2010/11/17 14:49:31
Done.
|
| + ~OpenSSLErrStackTracer() { ClearOpenSSLERRStack(message_); } |
| + |
| + private: |
| + const char* message_; |
|
bulach
2010/11/17 14:35:09
const char* const
joth
2010/11/17 14:49:31
Done.
(Although, this rule is mostly useful for gl
|
| +}; |
| + |
| } // namespace base |
| #endif // BASE_OPENSSL_UTIL_H_ |