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

Side by Side Diff: chrome/common/net/x509_certificate_model.cc

Issue 23642003: Support IDNA 2008 (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 3 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
« no previous file with comments | « no previous file | net/base/net_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/common/net/x509_certificate_model.h" 5 #include "chrome/common/net/x509_certificate_model.h"
6 6
7 #include <unicode/uidna.h> 7 #include <unicode/uidna.h>
8 8
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "grit/generated_resources.h" 10 #include "grit/generated_resources.h"
11 #include "ui/base/l10n/l10n_util.h" 11 #include "ui/base/l10n/l10n_util.h"
12 12
13 namespace x509_certificate_model { 13 namespace x509_certificate_model {
14 14
15 std::string ProcessIDN(const std::string& input) { 15 std::string ProcessIDN(const std::string& input) {
16 // Convert the ASCII input to a string16 for ICU. 16 // Convert the ASCII input to a string16 for ICU.
17 string16 input16; 17 string16 input16;
18 input16.reserve(input.length()); 18 input16.reserve(input.length());
19 input16.insert(input16.end(), input.begin(), input.end()); 19 input16.insert(input16.end(), input.begin(), input.end());
20 20
21 string16 output16; 21 string16 output16 = IDNToUnicode(input, std::string());
Ryan Sleevi 2013/09/21 00:46:14 IWYU: include net/base/net_util.h on line 10/11 n
jungshik at Google 2013/09/23 17:54:54 Done. Absolutely. I realized that on the way hom
22 output16.resize(input.length());
23
24 UErrorCode status = U_ZERO_ERROR;
25 int output_chars = uidna_IDNToUnicode(input16.data(), input.length(),
26 &output16[0], output16.length(),
27 UIDNA_DEFAULT, NULL, &status);
28 if (status == U_ZERO_ERROR) {
29 output16.resize(output_chars);
30 } else if (status != U_BUFFER_OVERFLOW_ERROR) {
31 return input;
32 } else {
33 output16.resize(output_chars);
34 output_chars = uidna_IDNToUnicode(input16.data(), input.length(),
35 &output16[0], output16.length(),
36 UIDNA_DEFAULT, NULL, &status);
37 if (status != U_ZERO_ERROR)
38 return input;
39 DCHECK_EQ(static_cast<size_t>(output_chars), output16.length());
40 output16.resize(output_chars); // Just to be safe.
41 }
42
43 if (input16 == output16) 22 if (input16 == output16)
44 return input; // Input did not contain any encoded data. 23 return input; // Input did not contain any encoded data.
45 24
46 // Input contained encoded data, return formatted string showing original and 25 // Input contained encoded data, return formatted string showing original and
47 // decoded forms. 26 // decoded forms.
48 return l10n_util::GetStringFUTF8(IDS_CERT_INFO_IDN_VALUE_FORMAT, 27 return l10n_util::GetStringFUTF8(IDS_CERT_INFO_IDN_VALUE_FORMAT,
49 input16, output16); 28 input16, output16);
50 } 29 }
51 30
52 std::string ProcessRawBytesWithSeparators(const unsigned char* data, 31 std::string ProcessRawBytesWithSeparators(const unsigned char* data,
(...skipping 29 matching lines...) Expand all
82 std::string ProcessRawBytes(const unsigned char* data, size_t data_length) { 61 std::string ProcessRawBytes(const unsigned char* data, size_t data_length) {
83 return ProcessRawBytesWithSeparators(data, data_length, ' ', '\n'); 62 return ProcessRawBytesWithSeparators(data, data_length, ' ', '\n');
84 } 63 }
85 64
86 #if defined(USE_NSS) 65 #if defined(USE_NSS)
87 std::string ProcessRawBits(const unsigned char* data, size_t data_length) { 66 std::string ProcessRawBits(const unsigned char* data, size_t data_length) {
88 return ProcessRawBytes(data, (data_length + 7) / 8); 67 return ProcessRawBytes(data, (data_length + 7) / 8);
89 } 68 }
90 #endif // USE_NSS 69 #endif // USE_NSS
91 70
92 } // x509_certificate_model 71 } // namespace x509_certificate_model
93 72
OLDNEW
« no previous file with comments | « no previous file | net/base/net_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698