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 "google_apis/gaia/oauth_request_signer.h" | 5 #include "google_apis/gaia/oauth_request_signer.h" |
6 | 6 |
7 #include <cctype> | 7 #include <cctype> |
8 #include <cstddef> | 8 #include <cstddef> |
9 #include <cstdlib> | 9 #include <cstdlib> |
10 #include <cstring> | 10 #include <cstring> |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 ++cursor; | 315 ++cursor; |
316 if (cursor == limit) | 316 if (cursor == limit) |
317 return false; | 317 return false; |
318 char* second = strchr(kHexDigits, *cursor); | 318 char* second = strchr(kHexDigits, *cursor); |
319 if (!second) | 319 if (!second) |
320 return false; | 320 return false; |
321 int low = second - kHexDigits; | 321 int low = second - kHexDigits; |
322 DCHECK(low >= 0 || low < kHexBase); | 322 DCHECK(low >= 0 || low < kHexBase); |
323 | 323 |
324 char decoded = static_cast<char>(high * kHexBase + low); | 324 char decoded = static_cast<char>(high * kHexBase + low); |
325 DCHECK(!(IsAsciiAlpha(decoded) || IsAsciiDigit(decoded))); | 325 DCHECK(!(base::IsAsciiAlpha(decoded) || base::IsAsciiDigit(decoded))); |
326 DCHECK(!(decoded && strchr("-._~", decoded))); | 326 DCHECK(!(decoded && strchr("-._~", decoded))); |
327 accumulator += decoded; | 327 accumulator += decoded; |
328 } else { | 328 } else { |
329 accumulator += character; | 329 accumulator += character; |
330 } | 330 } |
331 } | 331 } |
332 *decoded_text = accumulator; | 332 *decoded_text = accumulator; |
333 return true; | 333 return true; |
334 } | 334 } |
335 | 335 |
336 // static | 336 // static |
337 std::string OAuthRequestSigner::Encode(const std::string& text) { | 337 std::string OAuthRequestSigner::Encode(const std::string& text) { |
338 std::string result; | 338 std::string result; |
339 std::string::const_iterator cursor; | 339 std::string::const_iterator cursor; |
340 std::string::const_iterator limit; | 340 std::string::const_iterator limit; |
341 for (limit = text.end(), cursor = text.begin(); cursor != limit; ++cursor) { | 341 for (limit = text.end(), cursor = text.begin(); cursor != limit; ++cursor) { |
342 char character = *cursor; | 342 char character = *cursor; |
343 if (IsAsciiAlpha(character) || IsAsciiDigit(character)) { | 343 if (base::IsAsciiAlpha(character) || base::IsAsciiDigit(character)) { |
344 result += character; | 344 result += character; |
345 } else { | 345 } else { |
346 switch (character) { | 346 switch (character) { |
347 case '-': | 347 case '-': |
348 case '.': | 348 case '.': |
349 case '_': | 349 case '_': |
350 case '~': | 350 case '~': |
351 result += character; | 351 result += character; |
352 break; | 352 break; |
353 default: | 353 default: |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 signed_text += | 450 signed_text += |
451 base::StringPrintf( | 451 base::StringPrintf( |
452 "%s=\"%s\"", | 452 "%s=\"%s\"", |
453 OAuthRequestSigner::Encode(param->first).c_str(), | 453 OAuthRequestSigner::Encode(param->first).c_str(), |
454 OAuthRequestSigner::Encode(param->second).c_str()); | 454 OAuthRequestSigner::Encode(param->second).c_str()); |
455 } | 455 } |
456 *signed_text_return = signed_text; | 456 *signed_text_return = signed_text; |
457 } | 457 } |
458 return is_signed; | 458 return is_signed; |
459 } | 459 } |
OLD | NEW |