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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016 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_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_SPKI_HASH_H_
6 #define NET_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_SPKI_HASH_H_
7
8 #include <stdint.h>
9 #include <string>
10 #include <vector>
11
12 namespace net {
13
14 namespace transport_security_state {
15
16 class SPKIHash {
17 public:
18 enum : size_t { kLength = 32 };
19
20 SPKIHash();
21 ~SPKIHash();
22
23 // Initalizes a hash from the form sha256/<base64-hash-value>. The preloaded
24 // SPKI hashes are SHA256. Other algorithms are not supported. Returns true
25 // on success and copies the decoded bytes to |data_|. Returns false on
26 // failure.
27 bool FromString(const std::string& hash_string);
28
29 // Calculates the SHA256 digest over |*input| and copies the result to
30 // |data_|.
31 void CalculateFromBytes(const uint8_t* input, size_t input_length);
32
33 // Returns the size of the hash in bytes. Harcoded to 32 which is the length
34 // of a SHA256 hash.
35 size_t size() const { return kLength; }
36
37 uint8_t* data() { return data_; }
38 const uint8_t* data() const { return data_; };
39
40 private:
41 // The bytes of the hash. Current hashes are SHA256 and thus 32 bytes long.
42 uint8_t data_[kLength];
43 };
44
45 } // namespace transport_security_state
46
47 } // namespace net
48
49 #endif // NET_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_SPKI_HASH_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698