OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "crypto/crypto_export.h" |
11 | 12 |
12 namespace crypto { | 13 namespace crypto { |
13 | 14 |
14 // A helper class that takes care of destroying OpenSSL objects when it goes out | 15 // A helper class that takes care of destroying OpenSSL objects when it goes out |
15 // of scope. | 16 // of scope. |
16 template <typename T, void (*destructor)(T*)> | 17 template <typename T, void (*destructor)(T*)> |
17 class ScopedOpenSSL { | 18 class ScopedOpenSSL { |
18 public: | 19 public: |
19 ScopedOpenSSL() : ptr_(NULL) { } | 20 ScopedOpenSSL() : ptr_(NULL) { } |
20 explicit ScopedOpenSSL(T* ptr) : ptr_(ptr) { } | 21 explicit ScopedOpenSSL(T* ptr) : ptr_(ptr) { } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 // buffer is not of sufficient size. | 74 // buffer is not of sufficient size. |
74 unsigned char min_sized_buffer_[MIN_SIZE]; | 75 unsigned char min_sized_buffer_[MIN_SIZE]; |
75 | 76 |
76 DISALLOW_COPY_AND_ASSIGN(ScopedOpenSSLSafeSizeBuffer); | 77 DISALLOW_COPY_AND_ASSIGN(ScopedOpenSSLSafeSizeBuffer); |
77 }; | 78 }; |
78 | 79 |
79 // Initialize OpenSSL if it isn't already initialized. This must be called | 80 // Initialize OpenSSL if it isn't already initialized. This must be called |
80 // before any other OpenSSL functions. | 81 // before any other OpenSSL functions. |
81 // This function is thread-safe, and OpenSSL will only ever be initialized once. | 82 // This function is thread-safe, and OpenSSL will only ever be initialized once. |
82 // OpenSSL will be properly shut down on program exit. | 83 // OpenSSL will be properly shut down on program exit. |
83 void EnsureOpenSSLInit(); | 84 void CRYPTO_EXPORT EnsureOpenSSLInit(); |
84 | 85 |
85 // Drains the OpenSSL ERR_get_error stack. On a debug build the error codes | 86 // 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 | 87 // are send to VLOG(1), on a release build they are disregarded. In most |
87 // cases you should pass FROM_HERE as the |location|. | 88 // cases you should pass FROM_HERE as the |location|. |
88 void ClearOpenSSLERRStack(const tracked_objects::Location& location); | 89 void ClearOpenSSLERRStack(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: |
(...skipping 10 matching lines...) Expand all Loading... |
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 |