Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(197)

Side by Side Diff: net/base/x509_cert_types.h

Issue 11274032: Separate http_security_headers from transport_security_state (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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;
Ryan Sleevi 2012/10/25 01:59:09 I feel this is not coupled to the "HashValue" conc
unsafe 2012/10/25 06:59:54 Note that the type/base64 format is *not* the HPKP
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 HashValueLessThan {
92 public: 97 public:
93 bool operator()(const HashValue& lhs, 98 bool operator()(const HashValue& lhs,
94 const HashValue& rhs) const { 99 const HashValue& rhs) const {
95 size_t lhs_size = lhs.size(); 100 size_t lhs_size = lhs.size();
96 size_t rhs_size = rhs.size(); 101 size_t rhs_size = rhs.size();
97 102
98 if (lhs_size != rhs_size) 103 if (lhs_size != rhs_size)
99 return lhs_size < rhs_size; 104 return lhs_size < rhs_size;
100 105
101 return memcmp(lhs.data(), rhs.data(), lhs_size) < 0; 106 return memcmp(lhs.data(), rhs.data(), lhs_size) < 0;
102 } 107 }
103 }; 108 };
104 109
110 class NET_EXPORT HashValuesEqualPredicate {
Ryan Sleevi 2012/10/25 01:59:09 naming nit: HashValueEquals design nit: Is this so
unsafe 2012/10/25 06:59:54 Deleted HashValueLessThan. HashValueEqualsPredica
111 public:
112 explicit HashValuesEqualPredicate(const HashValue& fingerprint) :
113 fingerprint_(fingerprint) {}
114
115 bool operator()(const HashValue& other) const {
116 return fingerprint_.Equals(other);
117 }
118
119 const HashValue& fingerprint_;
120 };
121
105 typedef std::vector<HashValue> HashValueVector; 122 typedef std::vector<HashValue> HashValueVector;
106 123
107 // IsSHA1HashInSortedArray returns true iff |hash| is in |array|, a sorted 124 // IsSHA1HashInSortedArray returns true iff |hash| is in |array|, a sorted
108 // array of SHA1 hashes. 125 // array of SHA1 hashes.
109 bool NET_EXPORT IsSHA1HashInSortedArray(const SHA1HashValue& hash, 126 bool NET_EXPORT IsSHA1HashInSortedArray(const SHA1HashValue& hash,
110 const uint8* array, 127 const uint8* array,
111 size_t array_byte_len); 128 size_t array_byte_len);
112 129
130 // Returns true if the intersection of |a| and |b| is not empty. If either
131 // |a| or |b| is empty, returns false.
132 bool NET_EXPORT HashesIntersect(const HashValueVector& a,
133 const HashValueVector& b);
134
135 // Convert between HashValueVector and comma-separated string format:
136 // "sha1/Guzek9lMwR3KeIS8wwS9gBvVtIg=,sha256/U8Sg...
137 std::string NET_EXPORT HashesToBase64String(const HashValueVector& hashes);
138 bool Base64StringToHashes(const std::string& hashes_str,
139 HashValueVector* hashes);
Ryan Sleevi 2012/10/25 01:59:09 BUG?: You don't NET_EXPORT Base64StringToHashes, t
unsafe 2012/10/25 06:59:54 Fixed.
140
113 // CertPrincipal represents the issuer or subject field of an X.509 certificate. 141 // CertPrincipal represents the issuer or subject field of an X.509 certificate.
114 struct NET_EXPORT CertPrincipal { 142 struct NET_EXPORT CertPrincipal {
115 CertPrincipal(); 143 CertPrincipal();
116 explicit CertPrincipal(const std::string& name); 144 explicit CertPrincipal(const std::string& name);
117 ~CertPrincipal(); 145 ~CertPrincipal();
118 146
119 #if (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_WIN) 147 #if (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_WIN)
120 // Parses a BER-format DistinguishedName. 148 // Parses a BER-format DistinguishedName.
121 bool ParseDistinguishedName(const void* ber_name_data, size_t length); 149 bool ParseDistinguishedName(const void* ber_name_data, size_t length);
122 #endif 150 #endif
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 // Attempts to parse |raw_date|, an ASN.1 date/time string encoded as 238 // 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 239 // |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 240 // specified, or if parsing fails, returns false, and |*time| will not be
213 // updated. 241 // updated.
214 bool ParseCertificateDate(const base::StringPiece& raw_date, 242 bool ParseCertificateDate(const base::StringPiece& raw_date,
215 CertDateFormat format, 243 CertDateFormat format,
216 base::Time* time); 244 base::Time* time);
217 } // namespace net 245 } // namespace net
218 246
219 #endif // NET_BASE_X509_CERT_TYPES_H_ 247 #endif // NET_BASE_X509_CERT_TYPES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698