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

Unified Diff: net/tools/domain_security_preload_generator/preloaded_state_generator.h

Issue 2551153003: Add static domain security state generator tool. (Closed)
Patch Set: fix base64 issue and accidental replace. 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 side-by-side diff with in-line comments
Download patch
Index: net/tools/domain_security_preload_generator/preloaded_state_generator.h
diff --git a/net/tools/domain_security_preload_generator/preloaded_state_generator.h b/net/tools/domain_security_preload_generator/preloaded_state_generator.h
new file mode 100644
index 0000000000000000000000000000000000000000..c6a71ad8dc0a2ce52e0d9625e62a1faa392b9e5a
--- /dev/null
+++ b/net/tools/domain_security_preload_generator/preloaded_state_generator.h
@@ -0,0 +1,73 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_PRELOADED_STATE_GENERATOR_H_
+#define NET_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_PRELOADED_STATE_GENERATOR_H_
+
+#include <stdint.h>
+
+#include <map>
+#include <memory>
+#include <string>
+
+#include "net/tools/domain_security_preload_generator/domain_security_entry.h"
+#include "net/tools/domain_security_preload_generator/pinset.h"
+#include "net/tools/domain_security_preload_generator/pinsets.h"
+#include "net/tools/domain_security_preload_generator/trie/trie_writer.h"
+
+namespace net {
+
+namespace {
+
+class Template {
+ public:
+ Template(const std::string& tpl) : template_(tpl) {}
+ ~Template() {}
+
+ bool ReplaceTag(const std::string& name, const std::string& value) {
+ std::string tag = "[[" + name + "]]";
+
+ size_t start_pos = template_.find(tag);
+ if (start_pos == std::string::npos) {
+ return false;
+ }
+
+ template_.replace(start_pos, tag.length(), value);
+ return true;
+ }
+
+ const std::string& GetOutput() const { return template_; }
+
+ private:
+ std::string template_;
+};
+
+} // namespace
+
+class PreloadedStateGenerator {
+ public:
+ PreloadedStateGenerator();
+ ~PreloadedStateGenerator();
+
+ std::string Generate(const std::string& preload_template,
+ const DomainSecurityEntries& entries,
+ const DomainIDList& domain_ids,
+ const Pinsets& pinsets,
+ bool verbose);
+
+ private:
+ void ProcessDomainIds(const DomainIDList& domain_ids, NameIDMap* map);
+ void ProcessSPKIHashes(const Pinsets& pinset);
+ void ProcessExpectCTURIs(const DomainSecurityEntries& entries,
+ NameIDMap* expect_ct_report_uri_map);
+ void ProcessExpectStapleURIs(const DomainSecurityEntries& entries,
+ NameIDMap* expect_staple_report_uri_map);
+ void ProcessPinsets(const Pinsets& pinset, NameIDMap* pinset_map);
+
+ std::unique_ptr<Template> template_;
+};
+
+} // namespace net
+
+#endif // NET_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_PRELOADED_STATE_GENERATOR_H_

Powered by Google App Engine
This is Rietveld 408576698