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

Side by Side Diff: components/crx_file/crx_file.cc

Issue 2095523002: Make //crypto factories return std::unique_ptr<>s (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: I'm blind Created 4 years, 5 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/crx_file/crx_file.h" 5 #include "components/crx_file/crx_file.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/files/scoped_file.h" 10 #include "base/files/scoped_file.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // static 104 // static
105 CrxFile::ValidateError CrxFile::ValidateSignature( 105 CrxFile::ValidateError CrxFile::ValidateSignature(
106 const base::FilePath& crx_path, 106 const base::FilePath& crx_path,
107 const std::string& expected_hash, 107 const std::string& expected_hash,
108 std::string* public_key, 108 std::string* public_key,
109 std::string* extension_id, 109 std::string* extension_id,
110 CrxFile::Header* header_out) { 110 CrxFile::Header* header_out) {
111 base::ScopedFILE file(base::OpenFile(crx_path, "rb")); 111 base::ScopedFILE file(base::OpenFile(crx_path, "rb"));
112 std::unique_ptr<crypto::SecureHash> hash; 112 std::unique_ptr<crypto::SecureHash> hash;
113 if (!expected_hash.empty()) 113 if (!expected_hash.empty())
114 hash.reset(crypto::SecureHash::Create(crypto::SecureHash::SHA256)); 114 hash = crypto::SecureHash::Create(crypto::SecureHash::SHA256);
115 115
116 if (!file.get()) 116 if (!file.get())
117 return ValidateError::CRX_FILE_NOT_READABLE; 117 return ValidateError::CRX_FILE_NOT_READABLE;
118 118
119 CrxFile::Header header; 119 CrxFile::Header header;
120 size_t len = ReadAndHash(&header, sizeof(header), 1, file.get(), hash.get()); 120 size_t len = ReadAndHash(&header, sizeof(header), 1, file.get(), hash.get());
121 if (len != sizeof(header)) 121 if (len != sizeof(header))
122 return ValidateError::CRX_HEADER_INVALID; 122 return ValidateError::CRX_HEADER_INVALID;
123 if (header_out) 123 if (header_out)
124 *header_out = header; 124 *header_out = header;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 else if (header.signature_size > kMaxSignatureSize) 211 else if (header.signature_size > kMaxSignatureSize)
212 *error = kInvalidSignatureTooLarge; 212 *error = kInvalidSignatureTooLarge;
213 else if (header.signature_size == 0) 213 else if (header.signature_size == 0)
214 *error = kInvalidSignatureTooSmall; 214 *error = kInvalidSignatureTooSmall;
215 else 215 else
216 valid = true; 216 valid = true;
217 return valid; 217 return valid;
218 } 218 }
219 219
220 } // namespace crx_file 220 } // namespace crx_file
OLDNEW
« no previous file with comments | « chrome/browser/net/quota_policy_channel_id_store_unittest.cc ('k') | components/os_crypt/os_crypt_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698