Chromium Code Reviews| OLD | NEW |
|---|---|
| 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) { |
|
Ryan Sleevi
2013/09/19 20:21:02
We should remove this.
We never handle IDN for th
| |
| 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; |
| 22 output16.resize(input.length()); | 22 output16.resize(input.length()); |
| 23 | 23 |
| 24 // TODO(jungshik): Is this called from multiple threads? | |
| 25 static UIDNA* uidna = NULL; // will be leaked. | |
| 26 if (uidna == NULL) { | |
| 27 UErrorCode status = U_ZERO_ERROR; | |
| 28 // TODO(jungshik) : Review and change options as different | |
| 29 // parties (browsers, registrars, search engines) converge toward | |
| 30 // a consensus. Below is the most compatible with IDNA 2003 we used to use. | |
| 31 int32_t options = UIDNA_CHECK_BIDI; | |
| 32 uidna = uidna_openUTS46(options, &status); | |
| 33 if (U_FAILURE(status)) | |
| 34 return input; | |
| 35 } | |
| 36 | |
| 24 UErrorCode status = U_ZERO_ERROR; | 37 UErrorCode status = U_ZERO_ERROR; |
| 25 int output_chars = uidna_IDNToUnicode(input16.data(), input.length(), | 38 UIDNAInfo idna_info = UIDNA_INFO_INITIALIZER; |
| 26 &output16[0], output16.length(), | 39 int output_chars = uidna_nameToUnicode(uidna, input16.data(), input.length(), |
| 27 UIDNA_DEFAULT, NULL, &status); | 40 &output16[0], output16.length(), |
| 28 if (status == U_ZERO_ERROR) { | 41 &idna_info, &status); |
| 42 if (U_SUCCESS(status) && idna_info.errors == 0) { | |
| 29 output16.resize(output_chars); | 43 output16.resize(output_chars); |
| 30 } else if (status != U_BUFFER_OVERFLOW_ERROR) { | 44 } else if (status != U_BUFFER_OVERFLOW_ERROR || idna_info.errors != 0) { |
| 31 return input; | 45 return input; |
| 32 } else { | 46 } else { |
| 33 output16.resize(output_chars); | 47 output16.resize(output_chars); |
| 34 output_chars = uidna_IDNToUnicode(input16.data(), input.length(), | 48 output_chars = uidna_nameToUnicode(uidna, input16.data(), input.length(), |
| 35 &output16[0], output16.length(), | 49 &output16[0], output16.length(), |
| 36 UIDNA_DEFAULT, NULL, &status); | 50 &idna_info, &status); |
| 37 if (status != U_ZERO_ERROR) | 51 if (U_FAILURE(status) || idna_info.errors != 0) |
| 38 return input; | 52 return input; |
| 39 DCHECK_EQ(static_cast<size_t>(output_chars), output16.length()); | 53 DCHECK_EQ(static_cast<size_t>(output_chars), output16.length()); |
| 40 output16.resize(output_chars); // Just to be safe. | 54 output16.resize(output_chars); // Just to be safe. |
| 41 } | 55 } |
| 42 | 56 |
| 43 if (input16 == output16) | 57 if (input16 == output16) |
| 44 return input; // Input did not contain any encoded data. | 58 return input; // Input did not contain any encoded data. |
| 45 | 59 |
| 46 // Input contained encoded data, return formatted string showing original and | 60 // Input contained encoded data, return formatted string showing original and |
| 47 // decoded forms. | 61 // decoded forms. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 std::string ProcessRawBytes(const unsigned char* data, size_t data_length) { | 96 std::string ProcessRawBytes(const unsigned char* data, size_t data_length) { |
| 83 return ProcessRawBytesWithSeparators(data, data_length, ' ', '\n'); | 97 return ProcessRawBytesWithSeparators(data, data_length, ' ', '\n'); |
| 84 } | 98 } |
| 85 | 99 |
| 86 #if defined(USE_NSS) | 100 #if defined(USE_NSS) |
| 87 std::string ProcessRawBits(const unsigned char* data, size_t data_length) { | 101 std::string ProcessRawBits(const unsigned char* data, size_t data_length) { |
| 88 return ProcessRawBytes(data, (data_length + 7) / 8); | 102 return ProcessRawBytes(data, (data_length + 7) / 8); |
| 89 } | 103 } |
| 90 #endif // USE_NSS | 104 #endif // USE_NSS |
| 91 | 105 |
| 92 } // x509_certificate_model | 106 } // namespace x509_certificate_model |
| 93 | 107 |
| OLD | NEW |