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

Side by Side Diff: net/tools/transport_security_state_generator/trie/trie_writer.cc

Issue 2906483003: Experiment with a compact mode for simple preloaded entries. (Closed)
Patch Set: Initialize all struct members. Created 3 years, 3 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
« no previous file with comments | « net/http/transport_security_state_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/trie/trie_writer.h" 5 #include "net/tools/transport_security_state_generator/trie/trie_writer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "net/tools/transport_security_state_generator/trie/trie_bit_buffer.h" 10 #include "net/tools/transport_security_state_generator/trie/trie_bit_buffer.h"
11 11
12 namespace net { 12 namespace net {
13 13
14 namespace transport_security_state { 14 namespace transport_security_state {
15 15
16 namespace { 16 namespace {
17 17
18 bool CompareReversedEntries(const std::unique_ptr<ReversedEntry>& lhs, 18 bool CompareReversedEntries(const std::unique_ptr<ReversedEntry>& lhs,
19 const std::unique_ptr<ReversedEntry>& rhs) { 19 const std::unique_ptr<ReversedEntry>& rhs) {
20 return lhs->reversed_name < rhs->reversed_name; 20 return lhs->reversed_name < rhs->reversed_name;
21 } 21 }
22 22
23 // Returns true if the entry only configures HSTS with includeSubdomains.
24 // Such entries, when written, can be represented more compactly, and thus
25 // reduce the overall size of the trie.
26 bool IsSimpleEntry(const TransportSecurityStateEntry* entry) {
27 return entry->force_https && entry->include_subdomains &&
28 entry->pinset.empty() && !entry->expect_ct && !entry->expect_staple;
29 }
30
23 } // namespace 31 } // namespace
24 32
25 ReversedEntry::ReversedEntry(std::vector<uint8_t> reversed_name, 33 ReversedEntry::ReversedEntry(std::vector<uint8_t> reversed_name,
26 const TransportSecurityStateEntry* entry) 34 const TransportSecurityStateEntry* entry)
27 : reversed_name(reversed_name), entry(entry) {} 35 : reversed_name(reversed_name), entry(entry) {}
28 36
29 ReversedEntry::~ReversedEntry() {} 37 ReversedEntry::~ReversedEntry() {}
30 38
31 TrieWriter::TrieWriter(const HuffmanRepresentationTable& huffman_table, 39 TrieWriter::TrieWriter(const HuffmanRepresentationTable& huffman_table,
32 const NameIDMap& expect_ct_report_uri_map, 40 const NameIDMap& expect_ct_report_uri_map,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 writer.WriteChar(kEndOfTableValue, huffman_table_, huffman_builder_); 125 writer.WriteChar(kEndOfTableValue, huffman_table_, huffman_builder_);
118 126
119 *position = buffer_.position(); 127 *position = buffer_.position();
120 writer.Flush(); 128 writer.Flush();
121 writer.WriteToBitWriter(&buffer_); 129 writer.WriteToBitWriter(&buffer_);
122 return true; 130 return true;
123 } 131 }
124 132
125 bool TrieWriter::WriteEntry(const TransportSecurityStateEntry* entry, 133 bool TrieWriter::WriteEntry(const TransportSecurityStateEntry* entry,
126 TrieBitBuffer* writer) { 134 TrieBitBuffer* writer) {
135 if (IsSimpleEntry(entry)) {
136 writer->WriteBit(1);
137 return true;
138 } else {
139 writer->WriteBit(0);
140 }
141
127 uint8_t include_subdomains = 0; 142 uint8_t include_subdomains = 0;
128 if (entry->include_subdomains) { 143 if (entry->include_subdomains) {
129 include_subdomains = 1; 144 include_subdomains = 1;
130 } 145 }
131 writer->WriteBit(include_subdomains); 146 writer->WriteBit(include_subdomains);
132 147
133 uint8_t force_https = 0; 148 uint8_t force_https = 0;
134 if (entry->force_https) { 149 if (entry->force_https) {
135 force_https = 1; 150 force_https = 1;
136 } 151 }
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 return buffer_.position(); 287 return buffer_.position();
273 } 288 }
274 289
275 void TrieWriter::Flush() { 290 void TrieWriter::Flush() {
276 buffer_.Flush(); 291 buffer_.Flush();
277 } 292 }
278 293
279 } // namespace transport_security_state 294 } // namespace transport_security_state
280 295
281 } // namespace net 296 } // namespace net
OLDNEW
« no previous file with comments | « net/http/transport_security_state_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698