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

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

Issue 2551153003: Add static domain security state generator tool. (Closed)
Patch Set: Fix iOS? 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/spki_hash.h
diff --git a/net/tools/domain_security_preload_generator/spki_hash.h b/net/tools/domain_security_preload_generator/spki_hash.h
new file mode 100644
index 0000000000000000000000000000000000000000..ca07d0a5c832cd174947d89f133a319aa9f37211
--- /dev/null
+++ b/net/tools/domain_security_preload_generator/spki_hash.h
@@ -0,0 +1,49 @@
+// 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_SPKI_HASH_H_
+#define NET_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_SPKI_HASH_H_
+
+#include <stdint.h>
+#include <string>
+#include <vector>
+
+namespace net {
+
+namespace transport_security_state {
+
+class SPKIHash {
+ public:
+ enum : size_t { kLength = 32 };
+
+ SPKIHash();
+ ~SPKIHash();
+
+ // Initalizes a hash from the form sha256/<base64-hash-value>. The preloaded
+ // SPKI hashes are SHA256. Other algorithms are not supported. Returns true
+ // on success and copies the decoded bytes to |data_|. Returns false on
+ // failure.
+ bool FromString(const std::string& hash_string);
+
+ // Calculates the SHA256 digest over |*input| and copies the result to
+ // |data_|.
+ void CalculateFromBytes(const uint8_t* input, size_t input_length);
+
+ // Returns the size of the hash in bytes. Harcoded to 32 which is the length
+ // of a SHA256 hash.
+ size_t size() const { return kLength; }
+
+ uint8_t* data() { return data_; }
+ const uint8_t* data() const { return data_; };
+
+ private:
+ // The bytes of the hash. Current hashes are SHA256 and thus 32 bytes long.
+ uint8_t data_[kLength];
+};
+
+} // namespace transport_security_state
+
+} // namespace net
+
+#endif // NET_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_SPKI_HASH_H_

Powered by Google App Engine
This is Rietveld 408576698