OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser/net/packed_ct_ev_whitelist.h" | 5 #include "chrome/browser/net/packed_ct_ev_whitelist.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 curr_hash += curr_diff; | 100 curr_hash += curr_diff; |
101 | 101 |
102 result.push_back(curr_hash); | 102 result.push_back(curr_hash); |
103 } | 103 } |
104 | 104 |
105 uncompressed_list->swap(result); | 105 uncompressed_list->swap(result); |
106 return true; | 106 return true; |
107 } | 107 } |
108 | 108 |
109 PackedEVCertsWhitelist::PackedEVCertsWhitelist( | 109 PackedEVCertsWhitelist::PackedEVCertsWhitelist( |
110 const std::string& compressed_whitelist) | 110 const std::string& compressed_whitelist) { |
111 : is_whitelist_valid_(false) { | |
112 if (!UncompressEVWhitelist(compressed_whitelist, &whitelist_)) { | 111 if (!UncompressEVWhitelist(compressed_whitelist, &whitelist_)) { |
113 whitelist_.clear(); | 112 whitelist_.clear(); |
114 return; | 113 return; |
115 } | 114 } |
116 | |
117 is_whitelist_valid_ = true; | |
118 } | 115 } |
119 | 116 |
120 PackedEVCertsWhitelist::~PackedEVCertsWhitelist() { | 117 PackedEVCertsWhitelist::~PackedEVCertsWhitelist() { |
121 } | 118 } |
122 | 119 |
123 bool PackedEVCertsWhitelist::ContainsCertificateHash( | 120 bool PackedEVCertsWhitelist::ContainsCertificateHash( |
124 const std::string& certificate_hash) const { | 121 const std::string& certificate_hash) const { |
125 DCHECK(!whitelist_.empty()); | 122 DCHECK(!whitelist_.empty()); |
126 uint64_t hash_to_lookup; | 123 uint64_t hash_to_lookup; |
127 | 124 |
128 base::ReadBigEndian(certificate_hash.data(), &hash_to_lookup); | 125 base::ReadBigEndian(certificate_hash.data(), &hash_to_lookup); |
129 return bsearch(&hash_to_lookup, | 126 return bsearch(&hash_to_lookup, |
130 &whitelist_[0], | 127 &whitelist_[0], |
131 whitelist_.size(), | 128 whitelist_.size(), |
132 kCertHashLength, | 129 kCertHashLength, |
133 TruncatedHashesComparator) != NULL; | 130 TruncatedHashesComparator) != NULL; |
134 } | 131 } |
135 | 132 |
136 bool PackedEVCertsWhitelist::IsValid() const { | 133 bool PackedEVCertsWhitelist::IsValid() const { |
137 return is_whitelist_valid_; | 134 return whitelist_.size() > 0; |
138 } | 135 } |
OLD | NEW |