OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/common/net/x509_certificate_model.h" |
| 6 |
| 7 #include <unicode/uidna.h> |
| 8 |
| 9 #include "app/l10n_util.h" |
| 10 #include "base/utf_string_conversions.h" |
| 11 #include "grit/generated_resources.h" |
| 12 |
| 13 namespace x509_certificate_model { |
| 14 |
| 15 std::string ProcessIDN(const std::string& input) { |
| 16 // Convert the ASCII input to a string16 for ICU. |
| 17 string16 input16; |
| 18 input16.reserve(input.length()); |
| 19 std::copy(input.begin(), input.end(), std::back_inserter(input16)); |
| 20 |
| 21 string16 output16; |
| 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) |
| 44 return input; // Input did not contain any encoded data. |
| 45 |
| 46 // Input contained encoded data, return formatted string showing original and |
| 47 // decoded forms. |
| 48 return l10n_util::GetStringFUTF8(IDS_CERT_INFO_IDN_VALUE_FORMAT, |
| 49 input16, output16); |
| 50 } |
| 51 |
| 52 } // x509_certificate_model |
| 53 |
OLD | NEW |