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

Unified Diff: net/base/hash_value.h

Issue 11274032: Separate http_security_headers from transport_security_state (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 1 month 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/base/hash_value.h
===================================================================
--- net/base/hash_value.h (revision 0)
+++ net/base/hash_value.h (revision 0)
@@ -0,0 +1,113 @@
+// Copyright (c) 2012 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_BASE_HASH_VALUE_H_
+#define NET_BASE_HASH_VALUE_H_
+
+#include <string.h>
+
+#include <string>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "build/build_config.h"
+#include "net/base/net_export.h"
+
+namespace net {
+
+// Types (SHA1HashValue, SHA256HashValue, HashValue, HashValueVector)
Ryan Sleevi 2012/11/13 19:02:32 Drop this comment (and the other 'sectional' notat
unsafe 2012/11/13 23:20:18 Done.
+
+struct NET_EXPORT SHA1HashValue {
+ bool Equals(const SHA1HashValue& other) const {
+ return memcmp(data, other.data, sizeof(data)) == 0;
+ }
+
+ unsigned char data[20];
+};
+
+struct NET_EXPORT SHA256HashValue {
+ bool Equals(const SHA256HashValue& other) const {
+ return memcmp(data, other.data, sizeof(data)) == 0;
+ }
+
+ unsigned char data[32];
+};
+
+enum HashValueTag {
+ HASH_VALUE_SHA1,
+ HASH_VALUE_SHA256,
+
+ // This must always be last.
+ HASH_VALUE_TAGS_COUNT
+};
+
+class NET_EXPORT HashValue {
+ public:
+ explicit HashValue(HashValueTag tag) : tag(tag) {}
+ HashValue() : tag(HASH_VALUE_SHA1) {}
+
+ bool Equals(const HashValue& other) const;
+
+ // Parse/write in this format: "sha1/Guzek9lMwR3KeIS8wwS9gBvVtIg="
Ryan Sleevi 2012/11/13 19:02:32 nit: Can you expand on the comments for these meth
unsafe 2012/11/13 23:20:18 Done.
+ bool FromString(const std::string& input);
Ryan Sleevi 2012/11/13 19:02:32 API: suggestion: Use (const base::StringPiece& inp
unsafe 2012/11/13 23:20:18 I don't know what the conventions are around std::
+ std::string ToString() const;
+
+ size_t size() const;
+ unsigned char* data();
+ const unsigned char* data() const;
+
+ HashValueTag tag;
+
+ private:
+ union {
+ SHA1HashValue sha1;
+ SHA256HashValue sha256;
+ } fingerprint;
+};
+
+typedef std::vector<HashValue> HashValueVector;
+
+
+// Predicates for types
+
+class NET_EXPORT SHA1HashValueLessThan {
Ryan Sleevi 2012/11/13 19:02:32 As far as NET_EXPORT goes, I don't believe any of
unsafe 2012/11/13 23:20:18 I removed NET_EXPORT from this whole file, apparen
Ryan Sleevi 2012/11/13 23:32:05 I'm not sure that's true, or you may not be buildi
+ public:
+ bool operator()(const SHA1HashValue& lhs,
+ const SHA1HashValue& rhs) const {
+ return memcmp(lhs.data, rhs.data, sizeof(lhs.data)) < 0;
+ }
+};
+
+class NET_EXPORT SHA256HashValueLessThan {
+ public:
+ bool operator()(const SHA256HashValue& lhs,
+ const SHA256HashValue& rhs) const {
+ return memcmp(lhs.data, rhs.data, sizeof(lhs.data)) < 0;
+ }
+};
+
+class NET_EXPORT HashValuesEqual {
+ public:
+ explicit HashValuesEqual(const HashValue& fingerprint) :
+ fingerprint_(fingerprint) {}
+
+ bool operator()(const HashValue& other) const {
+ return fingerprint_.Equals(other);
+ }
+
+ const HashValue& fingerprint_;
+};
+
+
+// Misc hash-related funcs
palmer 2012/11/13 19:35:04 NIT: s/funcs/functions./
unsafe 2012/11/13 23:20:18 Removed entire (sectional) comment.
+
+// IsSHA1HashInSortedArray returns true iff |hash| is in |array|, a sorted
+// array of SHA1 hashes.
+bool NET_EXPORT IsSHA1HashInSortedArray(const SHA1HashValue& hash,
+ const uint8* array,
+ size_t array_byte_len);
+
+} // namespace net
+
+#endif // NET_BASE_HASH_VALUE_H_

Powered by Google App Engine
This is Rietveld 408576698