| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "net/cert/internal/parse_name.h" | 5 #include "net/cert/internal/parse_name.h" |
| 6 | 6 |
| 7 #include "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversion_utils.h" | 10 #include "base/strings/utf_string_conversion_utils.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/sys_byteorder.h" | 12 #include "base/sys_byteorder.h" |
| 13 #include "base/third_party/icu/icu_utf.h" | 13 #include "base/third_party/icu/icu_utf.h" |
| 14 | 14 |
| 15 #if !defined(OS_NACL) |
| 16 #include "net/base/net_string_util.h" |
| 17 #endif |
| 18 |
| 15 namespace net { | 19 namespace net { |
| 16 | 20 |
| 17 namespace { | 21 namespace { |
| 18 | 22 |
| 19 // Converts a BMPString value in Input |in| to UTF-8. | 23 // Converts a BMPString value in Input |in| to UTF-8. |
| 20 // | 24 // |
| 21 // If the conversion is successful, returns true and stores the result in | 25 // If the conversion is successful, returns true and stores the result in |
| 22 // |out|. Otherwise it returns false and leaves |out| unmodified. | 26 // |out|. Otherwise it returns false and leaves |out| unmodified. |
| 23 bool ConvertBmpStringValue(const der::Input& in, std::string* out) { | 27 bool ConvertBmpStringValue(const der::Input& in, std::string* out) { |
| 24 if (in.Length() % 2 != 0) | 28 if (in.Length() % 2 != 0) |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 der::Input TypeDomainComponentOid() { | 189 der::Input TypeDomainComponentOid() { |
| 186 // dc (domainComponent): 0.9.2342.19200300.100.1.25 (RFC 4519) | 190 // dc (domainComponent): 0.9.2342.19200300.100.1.25 (RFC 4519) |
| 187 static const uint8_t oid[] = {0x09, 0x92, 0x26, 0x89, 0x93, | 191 static const uint8_t oid[] = {0x09, 0x92, 0x26, 0x89, 0x93, |
| 188 0xF2, 0x2C, 0x64, 0x01, 0x19}; | 192 0xF2, 0x2C, 0x64, 0x01, 0x19}; |
| 189 return der::Input(oid); | 193 return der::Input(oid); |
| 190 } | 194 } |
| 191 | 195 |
| 192 bool X509NameAttribute::ValueAsString(std::string* out) const { | 196 bool X509NameAttribute::ValueAsString(std::string* out) const { |
| 193 switch (value_tag) { | 197 switch (value_tag) { |
| 194 case der::kTeletexString: | 198 case der::kTeletexString: |
| 195 for (char c : value.AsStringPiece()) { | 199 #if !defined(OS_NACL) |
| 196 if (c < 32 || c > 126) | 200 return ConvertToUtf8(value.AsString(), kCharsetLatin1, out); |
| 197 return false; | 201 #else |
| 198 } | 202 // For nacl, just fall through to treating like IA5String (ascii). |
| 199 *out = value.AsString(); | 203 // (The nacl build does not include net_string_util and its deps, and a test of |
| 200 return true; | 204 // adding them increased nacl build size by 100KB.) |
| 205 // TODO(mattm): Remove this behavioral difference. |
| 206 #endif |
| 201 case der::kIA5String: | 207 case der::kIA5String: |
| 202 for (char c : value.AsStringPiece()) { | 208 for (char c : value.AsStringPiece()) { |
| 203 if (static_cast<uint8_t>(c) > 127) | 209 if (static_cast<uint8_t>(c) > 127) |
| 204 return false; | 210 return false; |
| 205 } | 211 } |
| 206 *out = value.AsString(); | 212 *out = value.AsString(); |
| 207 return true; | 213 return true; |
| 208 case der::kPrintableString: | 214 case der::kPrintableString: |
| 209 for (char c : value.AsStringPiece()) { | 215 for (char c : value.AsStringPiece()) { |
| 210 if (!(base::IsAsciiAlpha(c) || c == ' ' || (c >= '\'' && c <= ':') || | 216 if (!(base::IsAsciiAlpha(c) || c == ' ' || (c >= '\'' && c <= ':') || |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 if (!rdns_string.empty()) | 384 if (!rdns_string.empty()) |
| 379 rdns_string += ","; | 385 rdns_string += ","; |
| 380 rdns_string += rdn_string; | 386 rdns_string += rdn_string; |
| 381 } | 387 } |
| 382 | 388 |
| 383 *out = rdns_string; | 389 *out = rdns_string; |
| 384 return true; | 390 return true; |
| 385 } | 391 } |
| 386 | 392 |
| 387 } // namespace net | 393 } // namespace net |
| OLD | NEW |