| 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 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 scoped_ptr<crypto::SecureHash> hasher( | 224 scoped_ptr<crypto::SecureHash> hasher( |
| 225 crypto::SecureHash::Create(crypto::SecureHash::SHA256)); | 225 crypto::SecureHash::Create(crypto::SecureHash::SHA256)); |
| 226 hasher->Update(mmfile.data(), mmfile.length()); | 226 hasher->Update(mmfile.data(), mmfile.length()); |
| 227 hasher->Finish(actual_hash, sizeof(actual_hash)); | 227 hasher->Finish(actual_hash, sizeof(actual_hash)); |
| 228 | 228 |
| 229 return memcmp(actual_hash, &expected_hash[0], sizeof(actual_hash)) == 0; | 229 return memcmp(actual_hash, &expected_hash[0], sizeof(actual_hash)) == 0; |
| 230 } | 230 } |
| 231 | 231 |
| 232 bool IsValidBrand(const std::string& brand) { | 232 bool IsValidBrand(const std::string& brand) { |
| 233 const size_t kMaxBrandSize = 4; | 233 const size_t kMaxBrandSize = 4; |
| 234 if (brand.size() > kMaxBrandSize) | 234 if (!brand.empty() && brand.size() != kMaxBrandSize) |
| 235 return false; | 235 return false; |
| 236 | 236 |
| 237 return std::find_if_not(brand.begin(), brand.end(), [](char ch) { | 237 return std::find_if_not(brand.begin(), brand.end(), [](char ch) { |
| 238 return base::IsAsciiAlpha(ch); | 238 return base::IsAsciiAlpha(ch); |
| 239 }) == brand.end(); | 239 }) == brand.end(); |
| 240 } | 240 } |
| 241 | 241 |
| 242 bool IsValidAp(const std::string& ap) { | 242 bool IsValidAp(const std::string& ap) { |
| 243 const size_t kMaxApSize = 256; | 243 const size_t kMaxApSize = 256; |
| 244 if (ap.size() > kMaxApSize) | 244 if (ap.size() > kMaxApSize) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 260 | 260 |
| 261 void RemoveUnsecureUrls(std::vector<GURL>* urls) { | 261 void RemoveUnsecureUrls(std::vector<GURL>* urls) { |
| 262 DCHECK(urls); | 262 DCHECK(urls); |
| 263 urls->erase(std::remove_if( | 263 urls->erase(std::remove_if( |
| 264 urls->begin(), urls->end(), | 264 urls->begin(), urls->end(), |
| 265 [](const GURL& url) { return !url.SchemeIsCryptographic(); }), | 265 [](const GURL& url) { return !url.SchemeIsCryptographic(); }), |
| 266 urls->end()); | 266 urls->end()); |
| 267 } | 267 } |
| 268 | 268 |
| 269 } // namespace update_client | 269 } // namespace update_client |
| OLD | NEW |