| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef NET_BASE_X509_CERT_TYPES_H_ | 5 #ifndef NET_BASE_X509_CERT_TYPES_H_ |
| 6 #define NET_BASE_X509_CERT_TYPES_H_ | 6 #define NET_BASE_X509_CERT_TYPES_H_ |
| 7 | 7 |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/string_piece.h" | 15 #include "base/string_piece.h" |
| 16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 #include "net/base/hash_value.h" |
| 17 #include "net/base/net_export.h" | 18 #include "net/base/net_export.h" |
| 18 | 19 |
| 19 #if defined(OS_MACOSX) && !defined(OS_IOS) | 20 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 20 #include <Security/x509defs.h> | 21 #include <Security/x509defs.h> |
| 21 #endif | 22 #endif |
| 22 | 23 |
| 23 namespace base { | 24 namespace base { |
| 24 class Time; | 25 class Time; |
| 25 } // namespace base | 26 } // namespace base |
| 26 | 27 |
| 27 namespace net { | 28 namespace net { |
| 28 | 29 |
| 29 class X509Certificate; | 30 class X509Certificate; |
| 30 | 31 |
| 31 // SHA-1 fingerprint (160 bits) of a certificate. | |
| 32 struct NET_EXPORT SHA1HashValue { | |
| 33 bool Equals(const SHA1HashValue& other) const { | |
| 34 return memcmp(data, other.data, sizeof(data)) == 0; | |
| 35 } | |
| 36 | |
| 37 unsigned char data[20]; | |
| 38 }; | |
| 39 | |
| 40 class NET_EXPORT SHA1HashValueLessThan { | |
| 41 public: | |
| 42 bool operator()(const SHA1HashValue& lhs, | |
| 43 const SHA1HashValue& rhs) const { | |
| 44 return memcmp(lhs.data, rhs.data, sizeof(lhs.data)) < 0; | |
| 45 } | |
| 46 }; | |
| 47 | |
| 48 struct NET_EXPORT SHA256HashValue { | |
| 49 bool Equals(const SHA256HashValue& other) const { | |
| 50 return memcmp(data, other.data, sizeof(data)) == 0; | |
| 51 } | |
| 52 | |
| 53 unsigned char data[32]; | |
| 54 }; | |
| 55 | |
| 56 class NET_EXPORT SHA256HashValueLessThan { | |
| 57 public: | |
| 58 bool operator()(const SHA256HashValue& lhs, | |
| 59 const SHA256HashValue& rhs) const { | |
| 60 return memcmp(lhs.data, rhs.data, sizeof(lhs.data)) < 0; | |
| 61 } | |
| 62 }; | |
| 63 | |
| 64 enum HashValueTag { | |
| 65 HASH_VALUE_SHA1, | |
| 66 HASH_VALUE_SHA256, | |
| 67 | |
| 68 // This must always be last. | |
| 69 HASH_VALUE_TAGS_COUNT | |
| 70 }; | |
| 71 | |
| 72 class NET_EXPORT HashValue { | |
| 73 public: | |
| 74 explicit HashValue(HashValueTag tag) : tag(tag) {} | |
| 75 HashValue() : tag(HASH_VALUE_SHA1) {} | |
| 76 | |
| 77 bool Equals(const HashValue& other) const; | |
| 78 size_t size() const; | |
| 79 unsigned char* data(); | |
| 80 const unsigned char* data() const; | |
| 81 | |
| 82 HashValueTag tag; | |
| 83 | |
| 84 private: | |
| 85 union { | |
| 86 SHA1HashValue sha1; | |
| 87 SHA256HashValue sha256; | |
| 88 } fingerprint; | |
| 89 }; | |
| 90 | |
| 91 class NET_EXPORT HashValueLessThan { | |
| 92 public: | |
| 93 bool operator()(const HashValue& lhs, | |
| 94 const HashValue& rhs) const { | |
| 95 size_t lhs_size = lhs.size(); | |
| 96 size_t rhs_size = rhs.size(); | |
| 97 | |
| 98 if (lhs_size != rhs_size) | |
| 99 return lhs_size < rhs_size; | |
| 100 | |
| 101 return memcmp(lhs.data(), rhs.data(), lhs_size) < 0; | |
| 102 } | |
| 103 }; | |
| 104 | |
| 105 typedef std::vector<HashValue> HashValueVector; | |
| 106 | |
| 107 // IsSHA1HashInSortedArray returns true iff |hash| is in |array|, a sorted | |
| 108 // array of SHA1 hashes. | |
| 109 bool NET_EXPORT IsSHA1HashInSortedArray(const SHA1HashValue& hash, | |
| 110 const uint8* array, | |
| 111 size_t array_byte_len); | |
| 112 | |
| 113 // CertPrincipal represents the issuer or subject field of an X.509 certificate. | 32 // CertPrincipal represents the issuer or subject field of an X.509 certificate. |
| 114 struct NET_EXPORT CertPrincipal { | 33 struct NET_EXPORT CertPrincipal { |
| 115 CertPrincipal(); | 34 CertPrincipal(); |
| 116 explicit CertPrincipal(const std::string& name); | 35 explicit CertPrincipal(const std::string& name); |
| 117 ~CertPrincipal(); | 36 ~CertPrincipal(); |
| 118 | 37 |
| 119 #if (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_WIN) | 38 #if (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_WIN) |
| 120 // Parses a BER-format DistinguishedName. | 39 // Parses a BER-format DistinguishedName. |
| 121 bool ParseDistinguishedName(const void* ber_name_data, size_t length); | 40 bool ParseDistinguishedName(const void* ber_name_data, size_t length); |
| 122 #endif | 41 #endif |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 // Attempts to parse |raw_date|, an ASN.1 date/time string encoded as | 129 // Attempts to parse |raw_date|, an ASN.1 date/time string encoded as |
| 211 // |format|, and writes the result into |*time|. If an invalid date is | 130 // |format|, and writes the result into |*time|. If an invalid date is |
| 212 // specified, or if parsing fails, returns false, and |*time| will not be | 131 // specified, or if parsing fails, returns false, and |*time| will not be |
| 213 // updated. | 132 // updated. |
| 214 bool ParseCertificateDate(const base::StringPiece& raw_date, | 133 bool ParseCertificateDate(const base::StringPiece& raw_date, |
| 215 CertDateFormat format, | 134 CertDateFormat format, |
| 216 base::Time* time); | 135 base::Time* time); |
| 217 } // namespace net | 136 } // namespace net |
| 218 | 137 |
| 219 #endif // NET_BASE_X509_CERT_TYPES_H_ | 138 #endif // NET_BASE_X509_CERT_TYPES_H_ |
| OLD | NEW |