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

Side by Side Diff: net/tools/domain_security_preload_generator/trie/trie_writer.h

Issue 2551153003: Add static domain security state generator tool. (Closed)
Patch Set: Fix iOS? Created 4 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef NET_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_TRIE_TRIE_WRITER_H_
6 #define NET_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_TRIE_TRIE_WRITER_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "net/tools/domain_security_preload_generator/bit_writer.h"
12 #include "net/tools/domain_security_preload_generator/domain_security_entry.h"
13 #include "net/tools/domain_security_preload_generator/huffman/huffman_frequency_ tracker.h"
14
15 namespace net {
16
17 namespace transport_security_state {
18
19 struct DomainSecurityEntry;
20 class TrieBitBuffer;
21
22 // Maps a name to an index. This is used to track the index of several values
23 // in the C++ code. The trie refers to the array index of the values. For
24 // example; the pinsets are outputted as a C++ array and the index for the
25 // pinset in that array is placed in the trie.
26 using NameIDMap = std::map<std::string, uint32_t>;
27 using NameIDPair = std::pair<std::string, uint32_t>;
28
29 class TrieWriter {
30 public:
31 enum : uint8_t { kTerminalValue = 0, kEndOfTableValue = 127 };
32
33 TrieWriter(const HuffmanRepresentationTable& huffman_table,
34 const NameIDMap& domain_ids_map,
35 const NameIDMap& expect_ct_report_uri_map,
36 const NameIDMap& expect_staple_report_uri_map,
37 const NameIDMap& pinsets_map,
38 HuffmanFrequencyTracker* frequency_tracker);
39 ~TrieWriter();
40
41 // Constructs a trie containing all |entries|. The output is written to
42 // |buffer_|. Returns the position of the trie root.
43 uint32_t WriteEntries(const DomainSecurityEntries& entries);
44
45 // Returns the position |buffer_| is currently at. The returned value
46 // represents the number of bits.
47 uint32_t position() const;
48
49 // Flushes |buffer_|.
50 void Flush();
51
52 // Returns the trie bytes. Call Flush() first to ensure the buffer is
53 // complete.
54 const std::vector<uint8_t>& bytes() const { return buffer_.bytes(); }
55
56 private:
57 uint32_t WriteDispatchTables(ReversedEntries::iterator start,
58 ReversedEntries::iterator end);
59
60 // Serializes |*entry| and writes it to |*writer|.
61 void WriteSecurityEntry(const DomainSecurityEntry* entry,
62 TrieBitBuffer* writer);
63
64 // Removes the first |length| characters from all entries between |start| and
65 // |end|.
66 void RemovePrefix(size_t length,
67 ReversedEntries::iterator start,
68 ReversedEntries::iterator end);
69
70 // Searches for the longest common prefix for all entries between |start| and
71 // |end|.
72 std::vector<uint8_t> LongestCommonPrefix(ReversedEntries::iterator start,
73 ReversedEntries::iterator end) const;
74
75 // Returns the reversed |hostname| as a vector of bytes. The reversed hostname
76 // will be terminated by |kTerminalValue|.
77 std::vector<uint8_t> ReverseName(const std::string& hostname) const;
78
79 BitWriter buffer_;
80 const HuffmanRepresentationTable& huffman_table_;
81 const NameIDMap& domain_ids_map_;
82 const NameIDMap& expect_ct_report_uri_map_;
83 const NameIDMap& expect_staple_report_uri_map_;
84 const NameIDMap& pinsets_map_;
85 HuffmanFrequencyTracker* frequency_tracker_;
86 };
87
88 } // namespace transport_security_state
89
90 } // namespace net
91
92 #endif // NET_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_TRIE_TRIE_WRITER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698