| 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> |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 // This must always be last. | 68 // This must always be last. |
| 69 HASH_VALUE_TAGS_COUNT | 69 HASH_VALUE_TAGS_COUNT |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 class NET_EXPORT HashValue { | 72 class NET_EXPORT HashValue { |
| 73 public: | 73 public: |
| 74 explicit HashValue(HashValueTag tag) : tag(tag) {} | 74 explicit HashValue(HashValueTag tag) : tag(tag) {} |
| 75 HashValue() : tag(HASH_VALUE_SHA1) {} | 75 HashValue() : tag(HASH_VALUE_SHA1) {} |
| 76 | 76 |
| 77 bool Equals(const HashValue& other) const; | 77 bool Equals(const HashValue& other) const; |
| 78 |
| 79 // Parse/write in this format: "sha1/Guzek9lMwR3KeIS8wwS9gBvVtIg=" |
| 80 bool ParseBase64String(const std::string& input); |
| 81 std::string WriteBase64String() const; |
| 82 |
| 78 size_t size() const; | 83 size_t size() const; |
| 79 unsigned char* data(); | 84 unsigned char* data(); |
| 80 const unsigned char* data() const; | 85 const unsigned char* data() const; |
| 81 | 86 |
| 82 HashValueTag tag; | 87 HashValueTag tag; |
| 83 | 88 |
| 84 private: | 89 private: |
| 85 union { | 90 union { |
| 86 SHA1HashValue sha1; | 91 SHA1HashValue sha1; |
| 87 SHA256HashValue sha256; | 92 SHA256HashValue sha256; |
| 88 } fingerprint; | 93 } fingerprint; |
| 89 }; | 94 }; |
| 90 | 95 |
| 91 class NET_EXPORT HashValueLessThan { | 96 class NET_EXPORT HashValuesEqual { |
| 92 public: | 97 public: |
| 93 bool operator()(const HashValue& lhs, | 98 explicit HashValuesEqual(const HashValue& fingerprint) : |
| 94 const HashValue& rhs) const { | 99 fingerprint_(fingerprint) {} |
| 95 size_t lhs_size = lhs.size(); | |
| 96 size_t rhs_size = rhs.size(); | |
| 97 | 100 |
| 98 if (lhs_size != rhs_size) | 101 bool operator()(const HashValue& other) const { |
| 99 return lhs_size < rhs_size; | 102 return fingerprint_.Equals(other); |
| 103 } |
| 100 | 104 |
| 101 return memcmp(lhs.data(), rhs.data(), lhs_size) < 0; | 105 const HashValue& fingerprint_; |
| 102 } | |
| 103 }; | 106 }; |
| 104 | 107 |
| 105 typedef std::vector<HashValue> HashValueVector; | 108 typedef std::vector<HashValue> HashValueVector; |
| 106 | 109 |
| 107 // IsSHA1HashInSortedArray returns true iff |hash| is in |array|, a sorted | 110 // IsSHA1HashInSortedArray returns true iff |hash| is in |array|, a sorted |
| 108 // array of SHA1 hashes. | 111 // array of SHA1 hashes. |
| 109 bool NET_EXPORT IsSHA1HashInSortedArray(const SHA1HashValue& hash, | 112 bool NET_EXPORT IsSHA1HashInSortedArray(const SHA1HashValue& hash, |
| 110 const uint8* array, | 113 const uint8* array, |
| 111 size_t array_byte_len); | 114 size_t array_byte_len); |
| 112 | 115 |
| 116 // Returns true if the intersection of |a| and |b| is not empty. If either |
| 117 // |a| or |b| is empty, returns false. |
| 118 bool NET_EXPORT HashesIntersect(const HashValueVector& a, |
| 119 const HashValueVector& b); |
| 120 |
| 121 // Convert between HashValueVector and comma-separated string format: |
| 122 // "sha1/Guzek9lMwR3KeIS8wwS9gBvVtIg=,sha256/U8Sg... |
| 123 // A correct input string returns true, with hashes populated |
| 124 // An empty input string returns true, with hashes cleared |
| 125 // An incorrect input string returns false, with hashes cleared |
| 126 std::string NET_EXPORT HashesToBase64String(const HashValueVector& hashes); |
| 127 bool NET_EXPORT Base64StringToHashes(const std::string& hashes_str, |
| 128 HashValueVector* hashes); |
| 129 |
| 113 // CertPrincipal represents the issuer or subject field of an X.509 certificate. | 130 // CertPrincipal represents the issuer or subject field of an X.509 certificate. |
| 114 struct NET_EXPORT CertPrincipal { | 131 struct NET_EXPORT CertPrincipal { |
| 115 CertPrincipal(); | 132 CertPrincipal(); |
| 116 explicit CertPrincipal(const std::string& name); | 133 explicit CertPrincipal(const std::string& name); |
| 117 ~CertPrincipal(); | 134 ~CertPrincipal(); |
| 118 | 135 |
| 119 #if (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_WIN) | 136 #if (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_WIN) |
| 120 // Parses a BER-format DistinguishedName. | 137 // Parses a BER-format DistinguishedName. |
| 121 bool ParseDistinguishedName(const void* ber_name_data, size_t length); | 138 bool ParseDistinguishedName(const void* ber_name_data, size_t length); |
| 122 #endif | 139 #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 | 227 // 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 | 228 // |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 | 229 // specified, or if parsing fails, returns false, and |*time| will not be |
| 213 // updated. | 230 // updated. |
| 214 bool ParseCertificateDate(const base::StringPiece& raw_date, | 231 bool ParseCertificateDate(const base::StringPiece& raw_date, |
| 215 CertDateFormat format, | 232 CertDateFormat format, |
| 216 base::Time* time); | 233 base::Time* time); |
| 217 } // namespace net | 234 } // namespace net |
| 218 | 235 |
| 219 #endif // NET_BASE_X509_CERT_TYPES_H_ | 236 #endif // NET_BASE_X509_CERT_TYPES_H_ |
| OLD | NEW |