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

Side by Side Diff: net/tools/transport_security_state_generator/spki_hash.h

Issue 2793823002: Add unittests for certificate and file parsing. (Closed)
Patch Set: comments davidben Created 3 years, 8 months 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
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_SPKI_HASH_H_ 5 #ifndef NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_SPKI_HASH_H_
6 #define NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_SPKI_HASH_H_ 6 #define NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_SPKI_HASH_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/strings/string_piece.h"
13
12 namespace net { 14 namespace net {
13 15
14 namespace transport_security_state { 16 namespace transport_security_state {
15 17
16 class SPKIHash { 18 class SPKIHash {
17 public: 19 public:
18 enum : size_t { kLength = 32 }; 20 enum : size_t { kLength = 32 };
19 21
20 SPKIHash(); 22 SPKIHash();
21 ~SPKIHash(); 23 ~SPKIHash();
22 24
23 // Initalizes a hash from the form sha256/<base64-hash-value>. The preloaded 25 // Initalizes a hash from the form sha256/<base64-hash-value>. The preloaded
24 // SPKI hashes are SHA256. Other algorithms are not supported. Returns true 26 // SPKI hashes are SHA256. Other algorithms are not supported. Returns true
25 // on success and copies the decoded bytes to |data_|. Returns false on 27 // on success and copies the decoded bytes to |data_|. Returns false on
26 // failure. 28 // failure.
27 bool FromString(const std::string& hash_string); 29 bool FromString(base::StringPiece hash_string);
28 30
29 // Calculates the SHA256 digest over |*input| and copies the result to 31 // Calculates the SHA256 digest over |*input| and copies the result to
30 // |data_|. 32 // |data_|.
31 void CalculateFromBytes(const uint8_t* input, size_t input_length); 33 void CalculateFromBytes(const uint8_t* input, size_t input_length);
32 34
33 // Returns the size of the hash in bytes. Harcoded to 32 which is the length 35 // Returns the size of the hash in bytes. Harcoded to 32 which is the length
34 // of a SHA256 hash. 36 // of a SHA256 hash.
35 size_t size() const { return kLength; } 37 size_t size() const { return kLength; }
36 38
37 uint8_t* data() { return data_; } 39 uint8_t* data() { return data_; }
38 const uint8_t* data() const { return data_; }; 40 const uint8_t* data() const { return data_; };
39 41
40 private: 42 private:
41 // The bytes of the hash. Current hashes are SHA256 and thus 32 bytes long. 43 // The bytes of the hash. Current hashes are SHA256 and thus 32 bytes long.
42 uint8_t data_[kLength]; 44 uint8_t data_[kLength];
43 }; 45 };
44 46
45 } // namespace transport_security_state 47 } // namespace transport_security_state
46 48
47 } // namespace net 49 } // namespace net
48 50
49 #endif // NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_SPKI_HASH_H_ 51 #endif // NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_SPKI_HASH_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698