| OLD | NEW |
| 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 #ifndef NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_TRIE_TRIE_WRITER_H_ | 5 #ifndef NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_TRIE_TRIE_WRITER_H_ |
| 6 #define NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_TRIE_TRIE_WRITER_H_ | 6 #define NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_TRIE_TRIE_WRITER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/gtest_prod_util.h" |
| 11 #include "net/tools/transport_security_state_generator/bit_writer.h" | 12 #include "net/tools/transport_security_state_generator/bit_writer.h" |
| 12 #include "net/tools/transport_security_state_generator/huffman/huffman_builder.h
" | 13 #include "net/tools/transport_security_state_generator/huffman/huffman_builder.h
" |
| 13 #include "net/tools/transport_security_state_generator/transport_security_state_
entry.h" | 14 #include "net/tools/transport_security_state_generator/transport_security_state_
entry.h" |
| 14 | 15 |
| 15 namespace net { | 16 namespace net { |
| 16 | 17 |
| 17 namespace transport_security_state { | 18 namespace transport_security_state { |
| 18 | 19 |
| 19 struct TransportSecurityStateEntry; | 20 struct TransportSecurityStateEntry; |
| 20 class TrieBitBuffer; | 21 class TrieBitBuffer; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 33 TrieWriter(const HuffmanRepresentationTable& huffman_table, | 34 TrieWriter(const HuffmanRepresentationTable& huffman_table, |
| 34 const NameIDMap& domain_ids_map, | 35 const NameIDMap& domain_ids_map, |
| 35 const NameIDMap& expect_ct_report_uri_map, | 36 const NameIDMap& expect_ct_report_uri_map, |
| 36 const NameIDMap& expect_staple_report_uri_map, | 37 const NameIDMap& expect_staple_report_uri_map, |
| 37 const NameIDMap& pinsets_map, | 38 const NameIDMap& pinsets_map, |
| 38 HuffmanBuilder* huffman_builder); | 39 HuffmanBuilder* huffman_builder); |
| 39 ~TrieWriter(); | 40 ~TrieWriter(); |
| 40 | 41 |
| 41 // Constructs a trie containing all |entries|. The output is written to | 42 // Constructs a trie containing all |entries|. The output is written to |
| 42 // |buffer_|. Returns the position of the trie root. | 43 // |buffer_|. Returns the position of the trie root. |
| 43 uint32_t WriteEntries(const TransportSecurityStateEntries& entries); | 44 bool WriteEntries(const TransportSecurityStateEntries& entries, |
| 45 uint32_t* position); |
| 44 | 46 |
| 45 // Returns the position |buffer_| is currently at. The returned value | 47 // Returns the position |buffer_| is currently at. The returned value |
| 46 // represents the number of bits. | 48 // represents the number of bits. |
| 47 uint32_t position() const; | 49 uint32_t position() const; |
| 48 | 50 |
| 49 // Flushes |buffer_|. | 51 // Flushes |buffer_|. |
| 50 void Flush(); | 52 void Flush(); |
| 51 | 53 |
| 52 // Returns the trie bytes. Call Flush() first to ensure the buffer is | 54 // Returns the trie bytes. Call Flush() first to ensure the buffer is |
| 53 // complete. | 55 // complete. |
| 54 const std::vector<uint8_t>& bytes() const { return buffer_.bytes(); } | 56 const std::vector<uint8_t>& bytes() const { return buffer_.bytes(); } |
| 55 | 57 |
| 56 private: | 58 private: |
| 57 uint32_t WriteDispatchTables(ReversedEntries::iterator start, | 59 friend class TrieWriterTest; |
| 58 ReversedEntries::iterator end); | 60 FRIEND_TEST_ALL_PREFIXES(TrieWriterTest, ReverseName); |
| 61 FRIEND_TEST_ALL_PREFIXES(TrieWriterTest, LongestCommonPrefix); |
| 62 |
| 63 bool WriteDispatchTables(ReversedEntries::iterator start, |
| 64 ReversedEntries::iterator end, |
| 65 uint32_t* position); |
| 59 | 66 |
| 60 // Serializes |*entry| and writes it to |*writer|. | 67 // Serializes |*entry| and writes it to |*writer|. |
| 61 void WriteEntry(const TransportSecurityStateEntry* entry, | 68 bool WriteEntry(const TransportSecurityStateEntry* entry, |
| 62 TrieBitBuffer* writer); | 69 TrieBitBuffer* writer); |
| 63 | 70 |
| 64 // Removes the first |length| characters from all entries between |start| and | 71 // Removes the first |length| characters from all entries between |start| and |
| 65 // |end|. | 72 // |end|. |
| 66 void RemovePrefix(size_t length, | 73 void RemovePrefix(size_t length, |
| 67 ReversedEntries::iterator start, | 74 ReversedEntries::iterator start, |
| 68 ReversedEntries::iterator end); | 75 ReversedEntries::iterator end); |
| 69 | 76 |
| 70 // Searches for the longest common prefix for all entries between |start| and | 77 // Searches for the longest common prefix for all entries between |start| and |
| 71 // |end|. | 78 // |end|. |
| 72 std::vector<uint8_t> LongestCommonPrefix(ReversedEntries::iterator start, | 79 std::vector<uint8_t> LongestCommonPrefix( |
| 73 ReversedEntries::iterator end) const; | 80 ReversedEntries::const_iterator start, |
| 81 ReversedEntries::const_iterator end) const; |
| 74 | 82 |
| 75 // Returns the reversed |hostname| as a vector of bytes. The reversed hostname | 83 // Returns the reversed |hostname| as a vector of bytes. The reversed hostname |
| 76 // will be terminated by |kTerminalValue|. | 84 // will be terminated by |kTerminalValue|. |
| 77 std::vector<uint8_t> ReverseName(const std::string& hostname) const; | 85 std::vector<uint8_t> ReverseName(const std::string& hostname) const; |
| 78 | 86 |
| 79 BitWriter buffer_; | 87 BitWriter buffer_; |
| 80 const HuffmanRepresentationTable& huffman_table_; | 88 const HuffmanRepresentationTable& huffman_table_; |
| 81 const NameIDMap& domain_ids_map_; | 89 const NameIDMap& domain_ids_map_; |
| 82 const NameIDMap& expect_ct_report_uri_map_; | 90 const NameIDMap& expect_ct_report_uri_map_; |
| 83 const NameIDMap& expect_staple_report_uri_map_; | 91 const NameIDMap& expect_staple_report_uri_map_; |
| 84 const NameIDMap& pinsets_map_; | 92 const NameIDMap& pinsets_map_; |
| 85 HuffmanBuilder* huffman_builder_; | 93 HuffmanBuilder* huffman_builder_; |
| 86 }; | 94 }; |
| 87 | 95 |
| 88 } // namespace transport_security_state | 96 } // namespace transport_security_state |
| 89 | 97 |
| 90 } // namespace net | 98 } // namespace net |
| 91 | 99 |
| 92 #endif // NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_TRIE_TRIE_WRITER_H_ | 100 #endif // NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_TRIE_TRIE_WRITER_H_ |
| OLD | NEW |