| Index: chrome/browser/supervised_user/supervised_user_site_list.cc
|
| diff --git a/chrome/browser/supervised_user/supervised_user_site_list.cc b/chrome/browser/supervised_user/supervised_user_site_list.cc
|
| index bd8301608d0743c12cc0b8b791e53821bcfa1d18..1533e4014f8ad6557e0e1f32ed8a544e7b3bfd97 100644
|
| --- a/chrome/browser/supervised_user/supervised_user_site_list.cc
|
| +++ b/chrome/browser/supervised_user/supervised_user_site_list.cc
|
| @@ -8,7 +8,7 @@
|
| #include "base/json/json_file_value_serializer.h"
|
| #include "base/logging.h"
|
| #include "base/metrics/histogram_macros.h"
|
| -#include "base/sha1.h"
|
| +#include "base/strings/string_number_conversions.h"
|
| #include "base/task_runner_util.h"
|
| #include "base/values.h"
|
| #include "content/public/browser/browser_thread.h"
|
| @@ -39,6 +39,23 @@ scoped_ptr<base::Value> ReadFileOnBlockingThread(const base::FilePath& path) {
|
|
|
| } // namespace
|
|
|
| +SupervisedUserSiteList::HostnameHash::HostnameHash(
|
| + const std::string& hostname) {
|
| + base::SHA1HashBytes(reinterpret_cast<const unsigned char*>(hostname.c_str()),
|
| + hostname.size(), bytes_);
|
| +}
|
| +
|
| +SupervisedUserSiteList::HostnameHash::HostnameHash(
|
| + const std::vector<uint8>& bytes) {
|
| + DCHECK_GE(bytes.size(), base::kSHA1Length);
|
| + memcpy(bytes_, bytes.data(), base::kSHA1Length);
|
| +}
|
| +
|
| +bool SupervisedUserSiteList::HostnameHash::operator==(
|
| + const HostnameHash& rhs) const {
|
| + return memcmp(bytes_, rhs.bytes_, sizeof(bytes_)) == 0;
|
| +}
|
| +
|
| void SupervisedUserSiteList::Load(const base::string16& title,
|
| const base::FilePath& path,
|
| const LoadedCallback& callback) {
|
| @@ -72,15 +89,17 @@ SupervisedUserSiteList::SupervisedUserSiteList(
|
|
|
| if (hostname_hashes) {
|
| for (const base::Value* entry : *hostname_hashes) {
|
| - // |hash| should be a hex-encoded SHA1 hash.
|
| - std::string hash;
|
| - if (!entry->GetAsString(&hash) || hash.size() != 2 * base::kSHA1Length) {
|
| + // |hash_str| should be a hex-encoded SHA1 hash string.
|
| + std::string hash_str;
|
| + std::vector<uint8> hash_bytes;
|
| + if (!entry->GetAsString(&hash_str) ||
|
| + hash_str.size() != 2 * base::kSHA1Length ||
|
| + !base::HexStringToBytes(hash_str, &hash_bytes)) {
|
| LOG(ERROR) << "Invalid hostname_hashes entry";
|
| continue;
|
| }
|
| - // TODO(treib): Check that |hash| has only characters from [0-9a-fA-F].
|
| - // Or just store the raw bytes (from base::HexStringToBytes).
|
| - hostname_hashes_.push_back(hash);
|
| + DCHECK(hash_bytes.size() == base::kSHA1Length);
|
| + hostname_hashes_.push_back(HostnameHash(hash_bytes));
|
| }
|
| }
|
|
|
|
|