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

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, 2 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 "net/base/net_util.h"
11 #include "ui/base/l10n/l10n_util.h" 12 #include "ui/base/l10n/l10n_util.h"
12 13
13 namespace x509_certificate_model { 14 namespace x509_certificate_model {
14 15
15 std::string ProcessIDN(const std::string& input) { 16 std::string ProcessIDN(const std::string& input) {
16 // Convert the ASCII input to a string16 for ICU. 17 // Convert the ASCII input to a string16 for ICU.
17 string16 input16; 18 string16 input16;
18 input16.reserve(input.length()); 19 input16.reserve(input.length());
19 input16.insert(input16.end(), input.begin(), input.end()); 20 input16.insert(input16.end(), input.begin(), input.end());
20 21
21 string16 output16; 22 string16 output16 = net::IDNToUnicode(input, std::string());
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) 23 if (input16 == output16)
44 return input; // Input did not contain any encoded data. 24 return input; // Input did not contain any encoded data.
45 25
46 // Input contained encoded data, return formatted string showing original and 26 // Input contained encoded data, return formatted string showing original and
47 // decoded forms. 27 // decoded forms.
48 return l10n_util::GetStringFUTF8(IDS_CERT_INFO_IDN_VALUE_FORMAT, 28 return l10n_util::GetStringFUTF8(IDS_CERT_INFO_IDN_VALUE_FORMAT,
49 input16, output16); 29 input16, output16);
50 } 30 }
51 31
52 std::string ProcessRawBytesWithSeparators(const unsigned char* data, 32 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) { 62 std::string ProcessRawBytes(const unsigned char* data, size_t data_length) {
83 return ProcessRawBytesWithSeparators(data, data_length, ' ', '\n'); 63 return ProcessRawBytesWithSeparators(data, data_length, ' ', '\n');
84 } 64 }
85 65
86 #if defined(USE_NSS) 66 #if defined(USE_NSS)
87 std::string ProcessRawBits(const unsigned char* data, size_t data_length) { 67 std::string ProcessRawBits(const unsigned char* data, size_t data_length) {
88 return ProcessRawBytes(data, (data_length + 7) / 8); 68 return ProcessRawBytes(data, (data_length + 7) / 8);
89 } 69 }
90 #endif // USE_NSS 70 #endif // USE_NSS
91 71
92 } // x509_certificate_model 72 } // namespace x509_certificate_model
93 73
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