Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: base/openssl_util.h

Issue 5105003: Implements Signature Creator & Verifier for openssl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: bulach comments Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/crypto/signature_verifier_openssl.cc ('k') | base/openssl_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_OPENSSL_UTIL_H_ 5 #ifndef BASE_OPENSSL_UTIL_H_
6 #define BASE_OPENSSL_UTIL_H_ 6 #define BASE_OPENSSL_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 #include "base/tracked.h"
11 11
12 namespace base { 12 namespace base {
13 13
14 // A helper class that takes care of destroying OpenSSL objects when it goes out 14 // A helper class that takes care of destroying OpenSSL objects when it goes out
15 // of scope. 15 // of scope.
16 template <typename T, void (*destructor)(T*)> 16 template <typename T, void (*destructor)(T*)>
17 class ScopedOpenSSL { 17 class ScopedOpenSSL {
18 public: 18 public:
19 explicit ScopedOpenSSL(T* ptr_) : ptr_(ptr_) { } 19 ScopedOpenSSL() : ptr_(NULL) { }
20 explicit ScopedOpenSSL(T* ptr) : ptr_(ptr) { }
20 ~ScopedOpenSSL() { if (ptr_) (*destructor)(ptr_); } 21 ~ScopedOpenSSL() { if (ptr_) (*destructor)(ptr_); }
21 22
22 T* get() const { return ptr_; } 23 T* get() const { return ptr_; }
24 void reset(T* ptr) {
25 if (ptr != ptr_) {
26 if (ptr_) (*destructor)(ptr_);
27 ptr_ = ptr;
28 }
29 }
23 30
24 private: 31 private:
25 T* ptr_; 32 T* ptr_;
26 }; 33 };
27 34
28 // Provides a buffer of at least MIN_SIZE bytes, for use when calling OpenSSL's 35 // Provides a buffer of at least MIN_SIZE bytes, for use when calling OpenSSL's
29 // SHA256, HMAC, etc functions, adapting the buffer sizing rules to meet those 36 // SHA256, HMAC, etc functions, adapting the buffer sizing rules to meet those
30 // of the our base wrapper APIs. 37 // of the our base wrapper APIs.
31 // This allows the library to write directly to the caller's buffer if it is of 38 // This allows the library to write directly to the caller's buffer if it is of
32 // sufficient size, but if not it will write to temporary |min_sized_buffer_| 39 // sufficient size, but if not it will write to temporary |min_sized_buffer_|
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 DISALLOW_COPY_AND_ASSIGN(ScopedOpenSSLSafeSizeBuffer); 72 DISALLOW_COPY_AND_ASSIGN(ScopedOpenSSLSafeSizeBuffer);
66 }; 73 };
67 74
68 // Initialize OpenSSL if it isn't already initialized. This must be called 75 // Initialize OpenSSL if it isn't already initialized. This must be called
69 // before any other OpenSSL functions. 76 // before any other OpenSSL functions.
70 // This function is thread-safe, and OpenSSL will only ever be initialized once. 77 // This function is thread-safe, and OpenSSL will only ever be initialized once.
71 // OpenSSL will be properly shut down on program exit. 78 // OpenSSL will be properly shut down on program exit.
72 void EnsureOpenSSLInit(); 79 void EnsureOpenSSLInit();
73 80
74 // Drains the OpenSSL ERR_get_error stack. On a debug build the error codes 81 // Drains the OpenSSL ERR_get_error stack. On a debug build the error codes
75 // are send to VLOG(1), on a release build they are disregarded. 82 // are send to VLOG(1), on a release build they are disregarded. An optional
83 // |message| can be passed, which will be prepended to the error stack output
84 // if present.
85 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
76 void ClearOpenSSLERRStack(); 86 void ClearOpenSSLERRStack();
77 87
88 // Place an instance of this class on the call stack to automatically clear
89 // the OpenSSL error stack on function exit. If |message| is not null it will
90 // be included in any error dump.
91 class OpenSSLErrStackTracer {
92 public:
93 explicit OpenSSLErrStackTracer(const char* message) : message_(message) {}
94 ~OpenSSLErrStackTracer() { ClearOpenSSLERRStack(message_); }
95
96 private:
97 const char* const message_;
98 };
99
78 } // namespace base 100 } // namespace base
79 101
80 #endif // BASE_OPENSSL_UTIL_H_ 102 #endif // BASE_OPENSSL_UTIL_H_
OLDNEW
« no previous file with comments | « base/crypto/signature_verifier_openssl.cc ('k') | base/openssl_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698