| 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/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "grit/generated_resources.h" | 10 #include "grit/generated_resources.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 char hex_separator, | 54 char hex_separator, |
| 55 char line_separator) { | 55 char line_separator) { |
| 56 static const char kHexChars[] = "0123456789ABCDEF"; | 56 static const char kHexChars[] = "0123456789ABCDEF"; |
| 57 | 57 |
| 58 // Each input byte creates two output hex characters + a space or newline, | 58 // Each input byte creates two output hex characters + a space or newline, |
| 59 // except for the last byte. | 59 // except for the last byte. |
| 60 std::string ret; | 60 std::string ret; |
| 61 size_t kMin = 0U; | 61 size_t kMin = 0U; |
| 62 | 62 |
| 63 if (!data_length) | 63 if (!data_length) |
| 64 return ""; | 64 return std::string(); |
| 65 | 65 |
| 66 ret.reserve(std::max(kMin, data_length * 3 - 1)); | 66 ret.reserve(std::max(kMin, data_length * 3 - 1)); |
| 67 | 67 |
| 68 for (size_t i = 0; i < data_length; ++i) { | 68 for (size_t i = 0; i < data_length; ++i) { |
| 69 unsigned char b = data[i]; | 69 unsigned char b = data[i]; |
| 70 ret.push_back(kHexChars[(b >> 4) & 0xf]); | 70 ret.push_back(kHexChars[(b >> 4) & 0xf]); |
| 71 ret.push_back(kHexChars[b & 0xf]); | 71 ret.push_back(kHexChars[b & 0xf]); |
| 72 if (i + 1 < data_length) { | 72 if (i + 1 < data_length) { |
| 73 if ((i + 1) % 16 == 0) | 73 if ((i + 1) % 16 == 0) |
| 74 ret.push_back(line_separator); | 74 ret.push_back(line_separator); |
| 75 else | 75 else |
| 76 ret.push_back(hex_separator); | 76 ret.push_back(hex_separator); |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 return ret; | 79 return ret; |
| 80 } | 80 } |
| 81 | 81 |
| 82 std::string ProcessRawBytes(const unsigned char* data, size_t data_length) { | 82 std::string ProcessRawBytes(const unsigned char* data, size_t data_length) { |
| 83 return ProcessRawBytesWithSeparators(data, data_length, ' ', '\n'); | 83 return ProcessRawBytesWithSeparators(data, data_length, ' ', '\n'); |
| 84 } | 84 } |
| 85 | 85 |
| 86 #if defined(USE_NSS) | 86 #if defined(USE_NSS) |
| 87 std::string ProcessRawBits(const unsigned char* data, size_t data_length) { | 87 std::string ProcessRawBits(const unsigned char* data, size_t data_length) { |
| 88 return ProcessRawBytes(data, (data_length + 7) / 8); | 88 return ProcessRawBytes(data, (data_length + 7) / 8); |
| 89 } | 89 } |
| 90 #endif // USE_NSS | 90 #endif // USE_NSS |
| 91 | 91 |
| 92 } // x509_certificate_model | 92 } // x509_certificate_model |
| 93 | 93 |
| OLD | NEW |