OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/internal_auth.h" | 5 #include "chrome/browser/internal_auth.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> |
11 #include <deque> | 11 #include <deque> |
12 #include <limits> | 12 #include <limits> |
13 #include <memory> | 13 #include <memory> |
14 | 14 |
15 #include "base/base64.h" | 15 #include "base/base64.h" |
16 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/rand_util.h" | 18 #include "base/rand_util.h" |
| 19 #include "base/stl_util.h" |
19 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
20 #include "base/strings/string_split.h" | 21 #include "base/strings/string_split.h" |
21 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
22 #include "base/synchronization/lock.h" | 23 #include "base/synchronization/lock.h" |
23 #include "base/threading/thread_checker.h" | 24 #include "base/threading/thread_checker.h" |
24 #include "base/time/time.h" | 25 #include "base/time/time.h" |
25 #include "base/values.h" | 26 #include "base/values.h" |
26 #include "crypto/hmac.h" | 27 #include "crypto/hmac.h" |
27 | 28 |
28 namespace { | 29 namespace { |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 DCHECK(used_ticks_.size() <= kGenerationWindowTicks + 0u); | 382 DCHECK(used_ticks_.size() <= kGenerationWindowTicks + 0u); |
382 if (used_ticks_.size() >= kGenerationWindowTicks + 0u) { | 383 if (used_ticks_.size() >= kGenerationWindowTicks + 0u) { |
383 // Average speed of GeneratePassport calls exceeds limit. | 384 // Average speed of GeneratePassport calls exceeds limit. |
384 return 0; | 385 return 0; |
385 } | 386 } |
386 for (int64_t tick = current_tick; | 387 for (int64_t tick = current_tick; |
387 tick > current_tick - kGenerationWindowTicks; --tick) { | 388 tick > current_tick - kGenerationWindowTicks; --tick) { |
388 int idx = static_cast<int>(used_ticks_.size()) - | 389 int idx = static_cast<int>(used_ticks_.size()) - |
389 static_cast<int>(current_tick - tick + 1); | 390 static_cast<int>(current_tick - tick + 1); |
390 if (idx < 0 || used_ticks_[idx] != tick) { | 391 if (idx < 0 || used_ticks_[idx] != tick) { |
391 DCHECK(used_ticks_.end() == | 392 DCHECK(!base::ContainsValue(used_ticks_, tick)); |
392 std::find(used_ticks_.begin(), used_ticks_.end(), tick)); | |
393 return tick; | 393 return tick; |
394 } | 394 } |
395 } | 395 } |
396 NOTREACHED(); | 396 NOTREACHED(); |
397 return 0; | 397 return 0; |
398 } | 398 } |
399 | 399 |
400 std::string GeneratePassport(const std::string& domain, | 400 std::string GeneratePassport(const std::string& domain, |
401 const VarValueMap& map, | 401 const VarValueMap& map, |
402 int64_t tick) { | 402 int64_t tick) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 const std::string& domain, const VarValueMap& var_value_map) { | 471 const std::string& domain, const VarValueMap& var_value_map) { |
472 return g_generation_service.Get().GeneratePassport(domain, var_value_map, 0); | 472 return g_generation_service.Get().GeneratePassport(domain, var_value_map, 0); |
473 } | 473 } |
474 | 474 |
475 // static | 475 // static |
476 void InternalAuthGeneration::GenerateNewKey() { | 476 void InternalAuthGeneration::GenerateNewKey() { |
477 g_generation_service.Get().GenerateNewKey(); | 477 g_generation_service.Get().GenerateNewKey(); |
478 } | 478 } |
479 | 479 |
480 } // namespace chrome | 480 } // namespace chrome |
OLD | NEW |