 Chromium Code Reviews
 Chromium Code Reviews Issue 2551153003:
  Add static domain security state generator tool.  (Closed)
    
  
    Issue 2551153003:
  Add static domain security state generator tool.  (Closed) 
  | OLD | NEW | 
|---|---|
| (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 { | |
| 15 // Hashes are always SHA256. | |
| 16 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.
 | |
| 17 } // namespace | |
| 18 | |
| 19 class SPKIHash { | |
| 20 public: | |
| 21 SPKIHash(); | |
| 22 ~SPKIHash(); | |
| 23 | |
| 24 // Initalizes a hash from the form sha256/<base64-hash-value>. The preloaded | |
| 25 // SPKI hashes are SHA256. Other algorithms are not supported. Returns true | |
| 26 // on success and copies the decoded bytes to |data_|. Returns false in case | |
| 27 // of an error. | |
| 28 bool FromString(const std::string& hash_string); | |
| 29 | |
| 30 // Calculates the SHA256 digest over |*input|. Returns true on success and | |
| 31 // copies the bytes to |data_|. Returns false in case of an error. | |
| 32 bool CalculateFromBytes(const uint8_t* input, size_t input_length); | |
| 33 | |
| 34 // Returns the size of the hash in bytes. Harcoded to 32 which is the length | |
| 35 // of a SHA256 hash. | |
| 36 size_t size() const { return kSPKIHashLength; } | |
| 37 | |
| 38 uint8_t* data() { return data_; } | |
| 39 const uint8_t* data() const { return data_; }; | |
| 40 | |
| 41 private: | |
| 42 // The bytes of the hash. Current hashes are SHA256 and thus 32 bytes long. | |
| 43 uint8_t data_[kSPKIHashLength]; | |
| 44 }; | |
| 45 | |
| 46 } // namespace net | |
| 47 | |
| 48 #endif // NET_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_SPKI_HASH_H_ | |
| OLD | NEW |