xref: /aosp_15_r20/external/cronet/net/tools/transport_security_state_generator/pinset.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_PINSET_H_
6 #define NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_PINSET_H_
7 
8 #include <string>
9 #include <vector>
10 
11 namespace net::transport_security_state {
12 
13 // A Pinset represents the data a website would send in a HPKP header. A pinset
14 // is given a name so that multiple entries in the preload list can reference
15 // the same pinset.
16 class Pinset {
17  public:
18   Pinset(std::string name, std::string report_uri);
19 
20   Pinset(const Pinset&) = delete;
21   Pinset& operator=(const Pinset&) = delete;
22 
23   ~Pinset();
24 
name()25   const std::string& name() const { return name_; }
report_uri()26   const std::string& report_uri() const { return report_uri_; }
27 
static_spki_hashes()28   const std::vector<std::string>& static_spki_hashes() const {
29     return static_spki_hashes_;
30   }
bad_static_spki_hashes()31   const std::vector<std::string>& bad_static_spki_hashes() const {
32     return bad_static_spki_hashes_;
33   }
34 
35   // Register a good hash for this pinset. Hashes are referenced by a name, not
36   // by the actual hash.
37   void AddStaticSPKIHash(const std::string& hash_name);
38 
39   // Register a bad hash for this pinset. Hashes are referenced by a name, not
40   // by the actual hash.
41   void AddBadStaticSPKIHash(const std::string& hash_name);
42 
43  private:
44   std::string name_;
45   std::string report_uri_;
46 
47   // These vectors contain names rather than actual hashes.
48   std::vector<std::string> static_spki_hashes_;
49   std::vector<std::string> bad_static_spki_hashes_;
50 };
51 
52 }  // namespace net::transport_security_state
53 
54 #endif  // NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_PINSET_H_
55