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

Side by Side Diff: crypto/signature_verifier.cc

Issue 2095523002: Make //crypto factories return std::unique_ptr<>s (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comment Created 4 years, 6 months 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
OLDNEW
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 #include "crypto/signature_verifier.h" 5 #include "crypto/signature_verifier.h"
6 6
7 #include <openssl/bytestring.h> 7 #include <openssl/bytestring.h>
8 #include <openssl/digest.h> 8 #include <openssl/digest.h>
9 #include <openssl/evp.h> 9 #include <openssl/evp.h>
10 #include <stdint.h> 10 #include <stdint.h>
11 11
12 #include <memory> 12 #include <memory>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "crypto/openssl_util.h" 16 #include "crypto/openssl_util.h"
17 #include "crypto/scoped_openssl_types.h" 17 #include "crypto/scoped_openssl_types.h"
18 18
19 namespace crypto { 19 namespace crypto {
20 20
21 namespace { 21 namespace {
22 22
23 const EVP_MD* ToOpenSSLDigest(SignatureVerifier::HashAlgorithm hash_alg) { 23 const EVP_MD* ToOpenSSLDigest(SignatureVerifier::HashAlgorithm hash_alg) {
24 switch (hash_alg) { 24 switch (hash_alg) {
25 case SignatureVerifier::SHA1: 25 case SignatureVerifier::SHA1:
26 return EVP_sha1(); 26 return EVP_sha1();
27 case SignatureVerifier::SHA256: 27 case SignatureVerifier::SHA256:
28 return EVP_sha256(); 28 return EVP_sha256();
29 } 29 }
30 return NULL; 30 return nullptr;
31 } 31 }
32 32
33 } // namespace 33 } // namespace
34 34
35 struct SignatureVerifier::VerifyContext { 35 struct SignatureVerifier::VerifyContext {
36 ScopedEVP_MD_CTX ctx; 36 ScopedEVP_MD_CTX ctx;
37 }; 37 };
38 38
39 SignatureVerifier::SignatureVerifier() 39 SignatureVerifier::SignatureVerifier() : verify_context_(nullptr) {}
40 : verify_context_(NULL) {
41 }
42 40
43 SignatureVerifier::~SignatureVerifier() { 41 SignatureVerifier::~SignatureVerifier() {
44 Reset(); 42 Reset();
45 } 43 }
46 44
47 bool SignatureVerifier::VerifyInit(SignatureAlgorithm signature_algorithm, 45 bool SignatureVerifier::VerifyInit(SignatureAlgorithm signature_algorithm,
48 const uint8_t* signature, 46 const uint8_t* signature,
49 int signature_len, 47 int signature_len,
50 const uint8_t* public_key_info, 48 const uint8_t* public_key_info,
51 int public_key_info_len) { 49 int public_key_info_len) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 } 144 }
147 145
148 verify_context_->ctx.reset(EVP_MD_CTX_create()); 146 verify_context_->ctx.reset(EVP_MD_CTX_create());
149 int rv = EVP_DigestVerifyInit(verify_context_->ctx.get(), pkey_ctx, 147 int rv = EVP_DigestVerifyInit(verify_context_->ctx.get(), pkey_ctx,
150 digest, nullptr, public_key.get()); 148 digest, nullptr, public_key.get());
151 return rv == 1; 149 return rv == 1;
152 } 150 }
153 151
154 void SignatureVerifier::Reset() { 152 void SignatureVerifier::Reset() {
155 delete verify_context_; 153 delete verify_context_;
156 verify_context_ = NULL; 154 verify_context_ = nullptr;
157 signature_.clear(); 155 signature_.clear();
158 } 156 }
159 157
160 } // namespace crypto 158 } // namespace crypto
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698