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

Side by Side Diff: net/tools/transport_security_state_generator/pinsets.cc

Issue 2901393005: Experiment with HSTS preload list filtering. (Closed)
Patch Set: play.google.com is required too. Created 3 years, 6 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) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 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 "net/tools/transport_security_state_generator/pinsets.h" 5 #include "net/tools/transport_security_state_generator/pinsets.h"
6 6
7 #include "base/stl_util.h"
7 #include "net/tools/transport_security_state_generator/spki_hash.h" 8 #include "net/tools/transport_security_state_generator/spki_hash.h"
8 9
9 namespace net { 10 namespace net {
10 11
11 namespace transport_security_state { 12 namespace transport_security_state {
12 13
13 Pinsets::Pinsets() {} 14 Pinsets::Pinsets() {}
14 15
15 Pinsets::~Pinsets() {} 16 Pinsets::~Pinsets() {}
16 17
17 void Pinsets::RegisterSPKIHash(base::StringPiece name, const SPKIHash& hash) { 18 void Pinsets::RegisterSPKIHash(base::StringPiece name, const SPKIHash& hash) {
18 spki_hashes_.insert(std::pair<std::string, SPKIHash>(name.as_string(), hash)); 19 spki_hashes_.insert(std::pair<std::string, SPKIHash>(name.as_string(), hash));
19 } 20 }
20 21
21 void Pinsets::RegisterPinset(std::unique_ptr<Pinset> pinset) { 22 void Pinsets::RegisterPinset(std::unique_ptr<Pinset> pinset) {
22 pinsets_.insert(std::pair<std::string, std::unique_ptr<Pinset>>( 23 pinsets_.insert(std::pair<std::string, std::unique_ptr<Pinset>>(
23 pinset->name(), std::move(pinset))); 24 pinset->name(), std::move(pinset)));
24 } 25 }
25 26
27 void Pinsets::FilterPinsets(const std::set<std::string>& except_these) {
28 base::EraseIf(
29 pinsets_,
30 [except_these](
31 const std::pair<const std::string, std::unique_ptr<Pinset>>& pinset) {
32 return except_these.find(pinset.first) == except_these.cend();
33 });
34
35 // Assemble the list of SPKI hashes that are still required.
36 std::set<std::string> required_spki_hashes;
37 for (const auto& pinset : pinsets_) {
38 for (const auto& spki_hash : pinset.second->static_spki_hashes()) {
39 required_spki_hashes.insert(spki_hash);
40 }
41
42 for (const auto& spki_hash : pinset.second->bad_static_spki_hashes()) {
43 required_spki_hashes.insert(spki_hash);
44 }
45 }
46
47 base::EraseIf(spki_hashes_,
48 [required_spki_hashes](
49 const std::pair<std::string, SPKIHash>& spki_hash) {
50 return required_spki_hashes.find(spki_hash.first) ==
51 required_spki_hashes.cend();
52 });
53 }
54
26 } // namespace transport_security_state 55 } // namespace transport_security_state
27 56
28 } // namespace net 57 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698