| OLD | NEW |
| 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/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "base/strings/string_piece.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 #include "crypto/sha2.h" |
| 12 | 12 |
| 13 namespace blimp { | 13 namespace blimp { |
| 14 | 14 |
| 15 const BlobId CalculateBlobId(const void* data, size_t data_size) { | 15 const BlobId CalculateBlobId(const void* data, size_t data_size) { |
| 16 return crypto::SHA256HashString( | 16 return crypto::SHA256HashString( |
| 17 base::StringPiece(reinterpret_cast<const char*>(data), data_size)); | 17 base::StringPiece(reinterpret_cast<const char*>(data), data_size)); |
| 18 } | 18 } |
| 19 | 19 |
| 20 const BlobId CalculateBlobId(const std::string& data) { |
| 21 return crypto::SHA256HashString(data); |
| 22 } |
| 23 |
| 20 const std::string BlobIdToString(const BlobId& id) { | 24 const std::string BlobIdToString(const BlobId& id) { |
| 21 DCHECK(IsValidBlobId(id)); | 25 DCHECK(IsValidBlobId(id)) << "Invalid blob ID: " << id; |
| 22 return base::ToLowerASCII(base::HexEncode(id.data(), id.length())); | 26 return base::ToLowerASCII(base::HexEncode(id.data(), id.length())); |
| 23 } | 27 } |
| 24 | 28 |
| 25 bool IsValidBlobId(const BlobId& id) { | 29 bool IsValidBlobId(const BlobId& id) { |
| 26 return crypto::kSHA256Length == id.length(); | 30 return crypto::kSHA256Length == id.length(); |
| 27 } | 31 } |
| 28 | 32 |
| 29 } // namespace blimp | 33 } // namespace blimp |
| OLD | NEW |