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

Unified Diff: net/tools/domain_security_preload_generator/spki_hash.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/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..e07eb05e711a50d7d29f6eb502a689bdca7e153b
--- /dev/null
+++ b/net/tools/domain_security_preload_generator/spki_hash.h
@@ -0,0 +1,48 @@
+// 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 {
+// Hashes are always SHA256.
+enum : size_t { kSPKIHashLength = 32 };
agl 2016/12/06 18:51:36 put this in the SPKIHash class and just call it kL
martijnc 2016/12/07 22:37:54 Done.
+} // namespace
+
+class SPKIHash {
+ public:
+ 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 in case
+ // of an error.
+ bool FromString(const std::string& hash_string);
+
+ // Calculates the SHA256 digest over |*input|. Returns true on success and
+ // copies the bytes to |data_|. Returns false in case of an error.
+ bool 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 kSPKIHashLength; }
+
+ 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_[kSPKIHashLength];
+};
+
+} // namespace net
+
+#endif // NET_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_SPKI_HASH_H_

Powered by Google App Engine
This is Rietveld 408576698