OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 BASE_OPENNSSL_UTIL_H_ | 5 #ifndef BASE_OPENNSSL_UTIL_H_ |
6 #define BASE_OPENNSSL_UTIL_H_ | 6 #define BASE_OPENNSSL_UTIL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/tracked.h" | |
10 | 11 |
11 namespace base { | 12 namespace base { |
12 | 13 |
13 // Provides a buffer of at least MIN_SIZE bytes, for use when calling OpenSSL's | 14 // Provides a buffer of at least MIN_SIZE bytes, for use when calling OpenSSL's |
14 // SHA256, HMAC, etc functions, adapting the buffer sizing rules to meet those | 15 // SHA256, HMAC, etc functions, adapting the buffer sizing rules to meet those |
15 // of the our base wrapper APIs. | 16 // of the our base wrapper APIs. |
16 // This allows the library to write directly to the caller's buffer if it is of | 17 // This allows the library to write directly to the caller's buffer if it is of |
17 // sufficient size, but if not it will write to temporary |min_sized_buffer_| | 18 // sufficient size, but if not it will write to temporary |min_sized_buffer_| |
18 // of required size and then its content is automatically copied out on | 19 // of required size and then its content is automatically copied out on |
19 // destruction, with truncation as appropriate. | 20 // destruction, with truncation as appropriate. |
(...skipping 19 matching lines...) Expand all Loading... | |
39 | 40 |
40 private: | 41 private: |
41 // Pointer to the caller's data area and it's associated size, where data | 42 // Pointer to the caller's data area and it's associated size, where data |
42 // written via safe_buffer() will [eventually] end up. | 43 // written via safe_buffer() will [eventually] end up. |
43 unsigned char* output_; | 44 unsigned char* output_; |
44 size_t output_len_; | 45 size_t output_len_; |
45 | 46 |
46 // Temporary buffer writen into in the case where the caller's | 47 // Temporary buffer writen into in the case where the caller's |
47 // buffer is not of sufficient size. | 48 // buffer is not of sufficient size. |
48 unsigned char min_sized_buffer_[MIN_SIZE]; | 49 unsigned char min_sized_buffer_[MIN_SIZE]; |
50 | |
51 DISALLOW_COPY_AND_ASSIGN(ScopedOpenSSLSafeSizeBuffer); | |
52 }; | |
53 | |
54 // Drains the OpenSSL ERR_get_error stack. On a debug build the error codes | |
55 // are send to VLOG(1), on a release build they are disregarded. | |
56 // Pass FROM_HERE as the parameter. | |
Ryan Sleevi
2010/11/11 18:07:15
What parameter?
joth
2010/11/11 19:54:36
Opps, removed.
| |
57 void ClearERRStack(); | |
58 | |
59 // Put an instance of this class on the call stack to automatically clear the | |
60 // OpenSSL error stack on exit of your function. | |
61 class ScopedERRStackClearer { | |
62 public: | |
63 ScopedERRStackClearer() {} | |
64 ~ScopedERRStackClearer() { ClearERRStack(); } | |
65 | |
66 private: | |
67 DISALLOW_COPY_AND_ASSIGN(ScopedERRStackClearer); | |
49 }; | 68 }; |
50 | 69 |
51 } // namespace base | 70 } // namespace base |
52 | 71 |
53 #endif // BASE_NSS_UTIL_H_ | 72 #endif // BASE_OPENNSSL_UTIL_H_ |
OLD | NEW |