| 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 "components/update_client/utils.h" | 5 #include "components/update_client/utils.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 |
| 10 #include <algorithm> |
| 9 #include <cmath> | 11 #include <cmath> |
| 10 #include <cstring> | 12 #include <cstring> |
| 11 #include <vector> | 13 #include <vector> |
| 12 | 14 |
| 13 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 14 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
| 15 #include "base/files/memory_mapped_file.h" | 17 #include "base/files/memory_mapped_file.h" |
| 16 #include "base/guid.h" | 18 #include "base/guid.h" |
| 17 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/string_piece.h" | 20 #include "base/strings/string_piece.h" |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 | 221 |
| 220 uint8_t actual_hash[crypto::kSHA256Length] = {0}; | 222 uint8_t actual_hash[crypto::kSHA256Length] = {0}; |
| 221 scoped_ptr<crypto::SecureHash> hasher( | 223 scoped_ptr<crypto::SecureHash> hasher( |
| 222 crypto::SecureHash::Create(crypto::SecureHash::SHA256)); | 224 crypto::SecureHash::Create(crypto::SecureHash::SHA256)); |
| 223 hasher->Update(mmfile.data(), mmfile.length()); | 225 hasher->Update(mmfile.data(), mmfile.length()); |
| 224 hasher->Finish(actual_hash, sizeof(actual_hash)); | 226 hasher->Finish(actual_hash, sizeof(actual_hash)); |
| 225 | 227 |
| 226 return memcmp(actual_hash, &expected_hash[0], sizeof(actual_hash)) == 0; | 228 return memcmp(actual_hash, &expected_hash[0], sizeof(actual_hash)) == 0; |
| 227 } | 229 } |
| 228 | 230 |
| 231 bool IsValidBrand(const std::string& brand) { |
| 232 const size_t kMaxBrandSize = 4; |
| 233 if (brand.size() > kMaxBrandSize) |
| 234 return false; |
| 235 |
| 236 return std::find_if_not(brand.begin(), brand.end(), [](char ch) { |
| 237 return base::IsAsciiAlpha(ch); |
| 238 }) == brand.end(); |
| 239 } |
| 240 |
| 229 } // namespace update_client | 241 } // namespace update_client |
| OLD | NEW |