| Index: net/tools/transport_security_state_generator/preloaded_state_generator.cc
|
| diff --git a/net/tools/transport_security_state_generator/preloaded_state_generator.cc b/net/tools/transport_security_state_generator/preloaded_state_generator.cc
|
| index 64e89890ac76506ff85f910a8bdf7febca645b74..b1bcabbe05fc578e22e8ccd7bceb652a97bd11e8 100644
|
| --- a/net/tools/transport_security_state_generator/preloaded_state_generator.cc
|
| +++ b/net/tools/transport_security_state_generator/preloaded_state_generator.cc
|
| @@ -4,10 +4,9 @@
|
|
|
| #include "net/tools/transport_security_state_generator/preloaded_state_generator.h"
|
|
|
| -#include <iostream>
|
| -
|
| #include <string>
|
|
|
| +#include "base/strings/string_number_conversions.h"
|
| #include "base/strings/string_util.h"
|
| #include "base/strings/stringprintf.h"
|
| #include "net/tools/transport_security_state_generator/cert_util.h"
|
| @@ -133,8 +132,7 @@ std::string PreloadedStateGenerator::Generate(
|
| const std::string& preload_template,
|
| const TransportSecurityStateEntries& entries,
|
| const DomainIDList& domain_ids,
|
| - const Pinsets& pinsets,
|
| - bool verbose) {
|
| + const Pinsets& pinsets) {
|
| std::string output = preload_template;
|
|
|
| NameIDMap domain_ids_map;
|
| @@ -161,32 +159,28 @@ std::string PreloadedStateGenerator::Generate(
|
| TrieWriter writer(table, domain_ids_map, expect_ct_report_uri_map,
|
| expect_staple_report_uri_map, pinsets_map,
|
| &huffman_builder);
|
| - writer.WriteEntries(entries);
|
| - uint32_t initial_length = writer.position();
|
| + uint32_t root_position;
|
| + if (!writer.WriteEntries(entries, &root_position)) {
|
| + return std::string();
|
| + }
|
|
|
| HuffmanRepresentationTable optimal_table = huffman_builder.ToTable();
|
| TrieWriter new_writer(optimal_table, domain_ids_map, expect_ct_report_uri_map,
|
| expect_staple_report_uri_map, pinsets_map, nullptr);
|
|
|
| - uint32_t root_position = new_writer.WriteEntries(entries);
|
| - uint32_t new_length = new_writer.position();
|
| + if (!new_writer.WriteEntries(entries, &root_position)) {
|
| + return std::string();
|
| + }
|
|
|
| + uint32_t new_length = new_writer.position();
|
| std::vector<uint8_t> huffman_tree = huffman_builder.ToVector();
|
| -
|
| new_writer.Flush();
|
|
|
| ReplaceTag("HUFFMAN_TREE", FormatVectorAsArray(huffman_tree), &output);
|
| ReplaceTag("HSTS_TRIE", FormatVectorAsArray(new_writer.bytes()), &output);
|
|
|
| - ReplaceTag("HSTS_TRIE_BITS", std::to_string(new_length), &output);
|
| - ReplaceTag("HSTS_TRIE_ROOT", std::to_string(root_position), &output);
|
| -
|
| - if (verbose) {
|
| - std::cout << "Saved " << std::to_string(initial_length - new_length)
|
| - << " bits by using accurate Huffman counts." << std::endl;
|
| - std::cout << "Bit length " << std::to_string(new_length) << std::endl;
|
| - std::cout << "Root position " << std::to_string(root_position) << std::endl;
|
| - }
|
| + ReplaceTag("HSTS_TRIE_BITS", base::SizeTToString(new_length), &output);
|
| + ReplaceTag("HSTS_TRIE_ROOT", base::SizeTToString(root_position), &output);
|
|
|
| return output;
|
| }
|
| @@ -275,6 +269,11 @@ void PreloadedStateGenerator::ProcessExpectCTURIs(
|
| }
|
| }
|
|
|
| + output.append(kIndent);
|
| + output.append(kIndent);
|
| + output.append("NULL,");
|
| + output.append(kNewLine);
|
| +
|
| output.append("}");
|
| ReplaceTag("EXPECT_CT_REPORT_URIS", output, tpl);
|
| }
|
| @@ -302,6 +301,11 @@ void PreloadedStateGenerator::ProcessExpectStapleURIs(
|
| }
|
| }
|
|
|
| + output.append(kIndent);
|
| + output.append(kIndent);
|
| + output.append("NULL,");
|
| + output.append(kNewLine);
|
| +
|
| output.append("}");
|
| ReplaceTag("EXPECT_STAPLE_REPORT_URIS", output, tpl);
|
| }
|
|
|