Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(963)

Side by Side Diff: chrome/browser/internal_auth.cc

Issue 270183002: Move IsStringUTF8/ASCII to base namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more minor nit Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <algorithm> 7 #include <algorithm>
8 #include <deque> 8 #include <deque>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 tick < kKeyRegenerationHardTicks || 82 tick < kKeyRegenerationHardTicks ||
83 tick > kint64max - kKeyRegenerationHardTicks) { 83 tick > kint64max - kKeyRegenerationHardTicks) {
84 return 0; 84 return 0;
85 } 85 }
86 return tick; 86 return tick;
87 } 87 }
88 88
89 bool IsDomainSane(const std::string& domain) { 89 bool IsDomainSane(const std::string& domain) {
90 return !domain.empty() && 90 return !domain.empty() &&
91 domain.size() <= kStringLengthLimit && 91 domain.size() <= kStringLengthLimit &&
92 IsStringUTF8(domain) && 92 base::IsStringUTF8(domain) &&
93 domain.find_first_of(kItemSeparator) == std::string::npos; 93 domain.find_first_of(kItemSeparator) == std::string::npos;
94 } 94 }
95 95
96 bool IsVarSane(const std::string& var) { 96 bool IsVarSane(const std::string& var) {
97 static const char kAllowedChars[] = 97 static const char kAllowedChars[] =
98 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 98 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
99 "abcdefghijklmnopqrstuvwxyz" 99 "abcdefghijklmnopqrstuvwxyz"
100 "0123456789" 100 "0123456789"
101 "_"; 101 "_";
102 COMPILE_ASSERT( 102 COMPILE_ASSERT(
103 sizeof(kAllowedChars) == 26 + 26 + 10 + 1 + 1, some_mess_with_chars); 103 sizeof(kAllowedChars) == 26 + 26 + 10 + 1 + 1, some_mess_with_chars);
104 // We must not allow kItemSeparator in anything used as an input to construct 104 // We must not allow kItemSeparator in anything used as an input to construct
105 // message to sign. 105 // message to sign.
106 DCHECK(std::find(kAllowedChars, kAllowedChars + arraysize(kAllowedChars), 106 DCHECK(std::find(kAllowedChars, kAllowedChars + arraysize(kAllowedChars),
107 kItemSeparator) == kAllowedChars + arraysize(kAllowedChars)); 107 kItemSeparator) == kAllowedChars + arraysize(kAllowedChars));
108 DCHECK(std::find(kAllowedChars, kAllowedChars + arraysize(kAllowedChars), 108 DCHECK(std::find(kAllowedChars, kAllowedChars + arraysize(kAllowedChars),
109 kVarValueSeparator) == kAllowedChars + arraysize(kAllowedChars)); 109 kVarValueSeparator) == kAllowedChars + arraysize(kAllowedChars));
110 return !var.empty() && 110 return !var.empty() &&
111 var.size() <= kStringLengthLimit && 111 var.size() <= kStringLengthLimit &&
112 IsStringASCII(var) && 112 base::IsStringASCII(var) &&
113 var.find_first_not_of(kAllowedChars) == std::string::npos && 113 var.find_first_not_of(kAllowedChars) == std::string::npos &&
114 !IsAsciiDigit(var[0]); 114 !IsAsciiDigit(var[0]);
115 } 115 }
116 116
117 bool IsValueSane(const std::string& value) { 117 bool IsValueSane(const std::string& value) {
118 return value.size() <= kStringLengthLimit && 118 return value.size() <= kStringLengthLimit &&
119 IsStringUTF8(value) && 119 base::IsStringUTF8(value) &&
120 value.find_first_of(kItemSeparator) == std::string::npos; 120 value.find_first_of(kItemSeparator) == std::string::npos;
121 } 121 }
122 122
123 bool IsVarValueMapSane(const VarValueMap& map) { 123 bool IsVarValueMapSane(const VarValueMap& map) {
124 if (map.size() > kVarsLimit) 124 if (map.size() > kVarsLimit)
125 return false; 125 return false;
126 for (VarValueMap::const_iterator it = map.begin(); it != map.end(); ++it) { 126 for (VarValueMap::const_iterator it = map.begin(); it != map.end(); ++it) {
127 const std::string& var = it->first; 127 const std::string& var = it->first;
128 const std::string& value = it->second; 128 const std::string& value = it->second;
129 if (!IsVarSane(var) || !IsValueSane(value)) 129 if (!IsVarSane(var) || !IsValueSane(value))
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 static int get_verification_window_ticks() { 258 static int get_verification_window_ticks() {
259 return InternalAuthVerification::get_verification_window_ticks(); 259 return InternalAuthVerification::get_verification_window_ticks();
260 } 260 }
261 261
262 // Returns tick bound to given passport on success or zero on failure. 262 // Returns tick bound to given passport on success or zero on failure.
263 int64 PreVerifyPassport( 263 int64 PreVerifyPassport(
264 const std::string& passport, 264 const std::string& passport,
265 const std::string& domain, 265 const std::string& domain,
266 int64 current_tick) { 266 int64 current_tick) {
267 if (passport.size() != kPassportSize || 267 if (passport.size() != kPassportSize ||
268 !IsStringASCII(passport) || 268 !base::IsStringASCII(passport) ||
269 !IsDomainSane(domain) || 269 !IsDomainSane(domain) ||
270 current_tick <= dark_tick_ || 270 current_tick <= dark_tick_ ||
271 current_tick > key_change_tick_ + kKeyRegenerationHardTicks || 271 current_tick > key_change_tick_ + kKeyRegenerationHardTicks ||
272 key_.empty() || 272 key_.empty() ||
273 engine_ == NULL) { 273 engine_ == NULL) {
274 return 0; 274 return 0;
275 } 275 }
276 276
277 // Passport consists of 2 parts: first hmac and then tick. 277 // Passport consists of 2 parts: first hmac and then tick.
278 std::string tick_decimal = 278 std::string tick_decimal =
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 const std::string& domain, const VarValueMap& var_value_map) { 465 const std::string& domain, const VarValueMap& var_value_map) {
466 return g_generation_service.Get().GeneratePassport(domain, var_value_map, 0); 466 return g_generation_service.Get().GeneratePassport(domain, var_value_map, 0);
467 } 467 }
468 468
469 // static 469 // static
470 void InternalAuthGeneration::GenerateNewKey() { 470 void InternalAuthGeneration::GenerateNewKey() {
471 g_generation_service.Get().GenerateNewKey(); 471 g_generation_service.Get().GenerateNewKey();
472 } 472 }
473 473
474 } // namespace chrome 474 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/extensions/url_request_util.cc ('k') | chrome/browser/invalidation/invalidator_storage_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698