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

Side by Side Diff: blimp/common/blob_cache/id_util.cc

Issue 1912153004: [blimp] Change to use SHA-256 instead of SHA-1 for unique ids (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "blimp/common/blob_cache/id_util.h" 5 #include "blimp/common/blob_cache/id_util.h"
6 6
7 #include "base/sha1.h"
8 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_piece.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "blimp/common/blob_cache/blob_cache.h" 10 #include "blimp/common/blob_cache/blob_cache.h"
11 #include "crypto/sha2.h"
11 12
12 namespace blimp { 13 namespace blimp {
13 14
14 const BlobId CalculateBlobId(const void* data, size_t data_size) { 15 const BlobId CalculateBlobId(const void* data, size_t data_size) {
15 std::vector<unsigned char> sha1_hash(base::kSHA1Length); 16 return crypto::SHA256HashString(
16 base::SHA1HashBytes(static_cast<const unsigned char*>(data), data_size, 17 base::StringPiece(reinterpret_cast<const char*>(data), data_size));
17 sha1_hash.data());
18 return std::string(reinterpret_cast<char*>(sha1_hash.data()),
19 sha1_hash.size());
20 } 18 }
21 19
22 const std::string FormatBlobId(const BlobId& data) { 20 const std::string FormatBlobId(const BlobId& id) {
23 DCHECK_EQ(base::kSHA1Length, data.length()); 21 DCHECK(BlobIdHasCorrectLength(id));
24 return base::ToLowerASCII(base::HexEncode(data.data(), data.length())); 22 return base::ToLowerASCII(base::HexEncode(id.data(), id.length()));
23 }
24
25 bool BlobIdHasCorrectLength(const BlobId& id) {
26 return crypto::kSHA256Length == id.length();
25 } 27 }
26 28
27 } // namespace blimp 29 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698