OLD | NEW |
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 "chrome/common/safe_browsing/binary_feature_extractor.h" | 5 #include "chrome/common/safe_browsing/binary_feature_extractor.h" |
6 | 6 |
| 7 #include <memory> |
7 #include <utility> | 8 #include <utility> |
8 | 9 |
9 #include "base/files/file.h" | 10 #include "base/files/file.h" |
10 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
11 #include "base/files/memory_mapped_file.h" | 12 #include "base/files/memory_mapped_file.h" |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "chrome/common/safe_browsing/csd.pb.h" | 13 #include "chrome/common/safe_browsing/csd.pb.h" |
14 #include "crypto/secure_hash.h" | 14 #include "crypto/secure_hash.h" |
15 #include "crypto/sha2.h" | 15 #include "crypto/sha2.h" |
16 | 16 |
17 namespace safe_browsing { | 17 namespace safe_browsing { |
18 | 18 |
19 BinaryFeatureExtractor::BinaryFeatureExtractor() {} | 19 BinaryFeatureExtractor::BinaryFeatureExtractor() {} |
20 | 20 |
21 BinaryFeatureExtractor::~BinaryFeatureExtractor() {} | 21 BinaryFeatureExtractor::~BinaryFeatureExtractor() {} |
22 | 22 |
(...skipping 20 matching lines...) Expand all Loading... |
43 return ExtractImageFeaturesFromData(mapped_file.data(), mapped_file.length(), | 43 return ExtractImageFeaturesFromData(mapped_file.data(), mapped_file.length(), |
44 options, image_headers, signed_data); | 44 options, image_headers, signed_data); |
45 } | 45 } |
46 | 46 |
47 void BinaryFeatureExtractor::ExtractDigest( | 47 void BinaryFeatureExtractor::ExtractDigest( |
48 const base::FilePath& file_path, | 48 const base::FilePath& file_path, |
49 ClientDownloadRequest_Digests* digests) { | 49 ClientDownloadRequest_Digests* digests) { |
50 base::File file(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ); | 50 base::File file(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ); |
51 if (file.IsValid()) { | 51 if (file.IsValid()) { |
52 const int kBufferSize = 1 << 12; | 52 const int kBufferSize = 1 << 12; |
53 scoped_ptr<char[]> buf(new char[kBufferSize]); | 53 std::unique_ptr<char[]> buf(new char[kBufferSize]); |
54 scoped_ptr<crypto::SecureHash> ctx( | 54 std::unique_ptr<crypto::SecureHash> ctx( |
55 crypto::SecureHash::Create(crypto::SecureHash::SHA256)); | 55 crypto::SecureHash::Create(crypto::SecureHash::SHA256)); |
56 int len = 0; | 56 int len = 0; |
57 while (true) { | 57 while (true) { |
58 len = file.ReadAtCurrentPos(buf.get(), kBufferSize); | 58 len = file.ReadAtCurrentPos(buf.get(), kBufferSize); |
59 if (len <= 0) | 59 if (len <= 0) |
60 break; | 60 break; |
61 ctx->Update(buf.get(), len); | 61 ctx->Update(buf.get(), len); |
62 } | 62 } |
63 if (!len) { | 63 if (!len) { |
64 uint8_t hash[crypto::kSHA256Length]; | 64 uint8_t hash[crypto::kSHA256Length]; |
65 ctx->Finish(hash, sizeof(hash)); | 65 ctx->Finish(hash, sizeof(hash)); |
66 digests->set_sha256(hash, sizeof(hash)); | 66 digests->set_sha256(hash, sizeof(hash)); |
67 } | 67 } |
68 } | 68 } |
69 } | 69 } |
70 | 70 |
71 } // namespace safe_browsing | 71 } // namespace safe_browsing |
OLD | NEW |