| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CRYPTO_OPENSSL_UTIL_H_ | 5 #ifndef CRYPTO_OPENSSL_UTIL_H_ |
| 6 #define CRYPTO_OPENSSL_UTIL_H_ | 6 #define CRYPTO_OPENSSL_UTIL_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "crypto/crypto_export.h" | 10 #include "crypto/crypto_export.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 78 |
| 79 // Initialize OpenSSL if it isn't already initialized. This must be called | 79 // Initialize OpenSSL if it isn't already initialized. This must be called |
| 80 // before any other OpenSSL functions. | 80 // before any other OpenSSL functions. |
| 81 // This function is thread-safe, and OpenSSL will only ever be initialized once. | 81 // This function is thread-safe, and OpenSSL will only ever be initialized once. |
| 82 // OpenSSL will be properly shut down on program exit. | 82 // OpenSSL will be properly shut down on program exit. |
| 83 void CRYPTO_EXPORT EnsureOpenSSLInit(); | 83 void CRYPTO_EXPORT EnsureOpenSSLInit(); |
| 84 | 84 |
| 85 // Drains the OpenSSL ERR_get_error stack. On a debug build the error codes | 85 // Drains the OpenSSL ERR_get_error stack. On a debug build the error codes |
| 86 // are send to VLOG(1), on a release build they are disregarded. In most | 86 // are send to VLOG(1), on a release build they are disregarded. In most |
| 87 // cases you should pass FROM_HERE as the |location|. | 87 // cases you should pass FROM_HERE as the |location|. |
| 88 void ClearOpenSSLERRStack(const tracked_objects::Location& location); | 88 void CRYPTO_EXPORT ClearOpenSSLERRStack( |
| 89 const tracked_objects::Location& location); |
| 89 | 90 |
| 90 // Place an instance of this class on the call stack to automatically clear | 91 // Place an instance of this class on the call stack to automatically clear |
| 91 // the OpenSSL error stack on function exit. | 92 // the OpenSSL error stack on function exit. |
| 92 class OpenSSLErrStackTracer { | 93 class OpenSSLErrStackTracer { |
| 93 public: | 94 public: |
| 94 // Pass FROM_HERE as |location|, to help track the source of OpenSSL error | 95 // Pass FROM_HERE as |location|, to help track the source of OpenSSL error |
| 95 // messages. Note any diagnostic emitted will be tagged with the location of | 96 // messages. Note any diagnostic emitted will be tagged with the location of |
| 96 // the constructor call as it's not possible to trace a destructor's callsite. | 97 // the constructor call as it's not possible to trace a destructor's callsite. |
| 97 explicit OpenSSLErrStackTracer(const tracked_objects::Location& location) | 98 explicit OpenSSLErrStackTracer(const tracked_objects::Location& location) |
| 98 : location_(location) { | 99 : location_(location) { |
| 99 EnsureOpenSSLInit(); | 100 EnsureOpenSSLInit(); |
| 100 } | 101 } |
| 101 ~OpenSSLErrStackTracer() { | 102 ~OpenSSLErrStackTracer() { |
| 102 ClearOpenSSLERRStack(location_); | 103 ClearOpenSSLERRStack(location_); |
| 103 } | 104 } |
| 104 | 105 |
| 105 private: | 106 private: |
| 106 const tracked_objects::Location location_; | 107 const tracked_objects::Location location_; |
| 107 | 108 |
| 108 DISALLOW_IMPLICIT_CONSTRUCTORS(OpenSSLErrStackTracer); | 109 DISALLOW_IMPLICIT_CONSTRUCTORS(OpenSSLErrStackTracer); |
| 109 }; | 110 }; |
| 110 | 111 |
| 111 } // namespace crypto | 112 } // namespace crypto |
| 112 | 113 |
| 113 #endif // CRYPTO_OPENSSL_UTIL_H_ | 114 #endif // CRYPTO_OPENSSL_UTIL_H_ |
| OLD | NEW |