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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef NET_BASE_HASH_VALUE_H_
6 #define NET_BASE_HASH_VALUE_H_
7
8 #include <string.h>
9
10 #include <string>
11 #include <vector>
12
13 #include "base/basictypes.h"
14 #include "build/build_config.h"
15 #include "net/base/net_export.h"
16
17 namespace net {
18
19 // 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.
20
21 struct NET_EXPORT SHA1HashValue {
22 bool Equals(const SHA1HashValue& other) const {
23 return memcmp(data, other.data, sizeof(data)) == 0;
24 }
25
26 unsigned char data[20];
27 };
28
29 struct NET_EXPORT SHA256HashValue {
30 bool Equals(const SHA256HashValue& other) const {
31 return memcmp(data, other.data, sizeof(data)) == 0;
32 }
33
34 unsigned char data[32];
35 };
36
37 enum HashValueTag {
38 HASH_VALUE_SHA1,
39 HASH_VALUE_SHA256,
40
41 // This must always be last.
42 HASH_VALUE_TAGS_COUNT
43 };
44
45 class NET_EXPORT HashValue {
46 public:
47 explicit HashValue(HashValueTag tag) : tag(tag) {}
48 HashValue() : tag(HASH_VALUE_SHA1) {}
49
50 bool Equals(const HashValue& other) const;
51
52 // 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.
53 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::
54 std::string ToString() const;
55
56 size_t size() const;
57 unsigned char* data();
58 const unsigned char* data() const;
59
60 HashValueTag tag;
61
62 private:
63 union {
64 SHA1HashValue sha1;
65 SHA256HashValue sha256;
66 } fingerprint;
67 };
68
69 typedef std::vector<HashValue> HashValueVector;
70
71
72 // Predicates for types
73
74 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
75 public:
76 bool operator()(const SHA1HashValue& lhs,
77 const SHA1HashValue& rhs) const {
78 return memcmp(lhs.data, rhs.data, sizeof(lhs.data)) < 0;
79 }
80 };
81
82 class NET_EXPORT SHA256HashValueLessThan {
83 public:
84 bool operator()(const SHA256HashValue& lhs,
85 const SHA256HashValue& rhs) const {
86 return memcmp(lhs.data, rhs.data, sizeof(lhs.data)) < 0;
87 }
88 };
89
90 class NET_EXPORT HashValuesEqual {
91 public:
92 explicit HashValuesEqual(const HashValue& fingerprint) :
93 fingerprint_(fingerprint) {}
94
95 bool operator()(const HashValue& other) const {
96 return fingerprint_.Equals(other);
97 }
98
99 const HashValue& fingerprint_;
100 };
101
102
103 // 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.
104
105 // IsSHA1HashInSortedArray returns true iff |hash| is in |array|, a sorted
106 // array of SHA1 hashes.
107 bool NET_EXPORT IsSHA1HashInSortedArray(const SHA1HashValue& hash,
108 const uint8* array,
109 size_t array_byte_len);
110
111 } // namespace net
112
113 #endif // NET_BASE_HASH_VALUE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698