xref: /aosp_15_r20/external/cronet/net/tools/transport_security_state_generator/pinsets.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2016 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_PINSETS_H_
6 #define NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_PINSETS_H_
7 
8 #include <map>
9 #include <memory>
10 #include <string>
11 #include <string_view>
12 
13 #include "net/tools/transport_security_state_generator/cert_util.h"
14 #include "net/tools/transport_security_state_generator/pinset.h"
15 #include "net/tools/transport_security_state_generator/spki_hash.h"
16 
17 namespace net::transport_security_state {
18 
19 // Contains SPKIHashes and their names. The names are used to reference
20 // the hashes from Pinset's.
21 using SPKIHashMap = std::map<std::string, SPKIHash>;
22 using PinsetMap = std::map<std::string, std::unique_ptr<Pinset>>;
23 
24 class Pinsets {
25  public:
26   Pinsets();
27 
28   Pinsets(const Pinsets&) = delete;
29   Pinsets& operator=(const Pinsets&) = delete;
30 
31   ~Pinsets();
32 
33   void RegisterSPKIHash(std::string_view name, const SPKIHash& hash);
34   void RegisterPinset(std::unique_ptr<Pinset> set);
35 
size()36   size_t size() const { return pinsets_.size(); }
spki_size()37   size_t spki_size() const { return spki_hashes_.size(); }
38 
spki_hashes()39   const SPKIHashMap& spki_hashes() const { return spki_hashes_; }
pinsets()40   const PinsetMap& pinsets() const { return pinsets_; }
41 
42  private:
43   // Contains all SPKI hashes found in the input pins file.
44   SPKIHashMap spki_hashes_;
45 
46   // Contains all pinsets in the input JSON file.
47   PinsetMap pinsets_;
48 };
49 
50 }  // namespace net::transport_security_state
51 
52 #endif  // NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_PINSETS_H_
53