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

Side by Side Diff: chrome/browser/safe_browsing/binary_feature_extractor.cc

Issue 1015363003: Move BinaryFeatureExtractor and PEImageReader to common. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@zip2
Patch Set: sync to position 321353 Created 5 years, 9 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/safe_browsing/binary_feature_extractor.h"
6
7 #include "base/files/file.h"
8 #include "base/files/file_path.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/common/safe_browsing/csd.pb.h"
11 #include "crypto/secure_hash.h"
12 #include "crypto/sha2.h"
13
14 namespace safe_browsing {
15
16 void BinaryFeatureExtractor::ExtractDigest(
17 const base::FilePath& file_path,
18 ClientDownloadRequest_Digests* digests) {
19 base::File file(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ);
20 if (file.IsValid()) {
21 const int kBufferSize = 1 << 12;
22 scoped_ptr<char[]> buf(new char[kBufferSize]);
23 scoped_ptr<crypto::SecureHash> ctx(
24 crypto::SecureHash::Create(crypto::SecureHash::SHA256));
25 int len = 0;
26 while (true) {
27 len = file.ReadAtCurrentPos(buf.get(), kBufferSize);
28 if (len <= 0)
29 break;
30 ctx->Update(buf.get(), len);
31 }
32 if (!len) {
33 uint8_t hash[crypto::kSHA256Length];
34 ctx->Finish(hash, sizeof(hash));
35 digests->set_sha256(hash, sizeof(hash));
36 }
37 }
38 }
39
40 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698