Chromium Code Reviews| 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..2c762fb9258b7f4440d34b9cd0f6889450a3e727 100644 |
| --- a/net/tools/transport_security_state_generator/preloaded_state_generator.cc |
| +++ b/net/tools/transport_security_state_generator/preloaded_state_generator.cc |
| @@ -4,8 +4,6 @@ |
| #include "net/tools/transport_security_state_generator/preloaded_state_generator.h" |
| -#include <iostream> |
| - |
| #include <string> |
| #include "base/strings/string_util.h" |
| @@ -129,27 +127,28 @@ PreloadedStateGenerator::PreloadedStateGenerator() {} |
| PreloadedStateGenerator::~PreloadedStateGenerator() {} |
| -std::string PreloadedStateGenerator::Generate( |
| +bool PreloadedStateGenerator::Generate( |
| const std::string& preload_template, |
| const TransportSecurityStateEntries& entries, |
| const DomainIDList& domain_ids, |
| const Pinsets& pinsets, |
| - bool verbose) { |
| - std::string output = preload_template; |
| + std::string* output) { |
| + DCHECK(output); |
| + *output = preload_template; |
| NameIDMap domain_ids_map; |
| - ProcessDomainIds(domain_ids, &domain_ids_map, &output); |
| + ProcessDomainIds(domain_ids, &domain_ids_map, output); |
| - ProcessSPKIHashes(pinsets, &output); |
| + ProcessSPKIHashes(pinsets, output); |
| NameIDMap expect_ct_report_uri_map; |
| - ProcessExpectCTURIs(entries, &expect_ct_report_uri_map, &output); |
| + ProcessExpectCTURIs(entries, &expect_ct_report_uri_map, output); |
| NameIDMap expect_staple_report_uri_map; |
| - ProcessExpectStapleURIs(entries, &expect_staple_report_uri_map, &output); |
| + ProcessExpectStapleURIs(entries, &expect_staple_report_uri_map, output); |
| NameIDMap pinsets_map; |
| - ProcessPinsets(pinsets, &pinsets_map, &output); |
| + ProcessPinsets(pinsets, &pinsets_map, output); |
| // The trie generation process is ran twice, the first time using an |
| // approximate Huffman table. During this first run, the correct character |
| @@ -161,34 +160,27 @@ 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; |
| + bool success = writer.WriteEntries(entries, &root_position); |
| 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); |
| + success = success && new_writer.WriteEntries(entries, &root_position); |
| 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); |
| + ReplaceTag("HUFFMAN_TREE", FormatVectorAsArray(huffman_tree), output); |
| + ReplaceTag("HSTS_TRIE", FormatVectorAsArray(new_writer.bytes()), 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", std::to_string(new_length), output); |
| + ReplaceTag("HSTS_TRIE_ROOT", std::to_string(root_position), output); |
| - return output; |
| + return success; |
| } |
| void PreloadedStateGenerator::ProcessDomainIds(const DomainIDList& domain_ids, |
| @@ -275,6 +267,11 @@ void PreloadedStateGenerator::ProcessExpectCTURIs( |
| } |
| } |
| + output.append(kIndent); |
|
martijnc
2017/02/08 20:58:21
There are tests without Expect-CT and Expect-Stapl
|
| + output.append(kIndent); |
| + output.append("NULL,"); |
| + output.append(kNewLine); |
| + |
| output.append("}"); |
| ReplaceTag("EXPECT_CT_REPORT_URIS", output, tpl); |
| } |
| @@ -302,6 +299,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); |
| } |