Chromium Code Reviews| Index: net/tools/domain_security_preload_generator/spki_hash.h |
| diff --git a/net/tools/domain_security_preload_generator/spki_hash.h b/net/tools/domain_security_preload_generator/spki_hash.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e07eb05e711a50d7d29f6eb502a689bdca7e153b |
| --- /dev/null |
| +++ b/net/tools/domain_security_preload_generator/spki_hash.h |
| @@ -0,0 +1,48 @@ |
| +// Copyright (c) 2016 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_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_SPKI_HASH_H_ |
| +#define NET_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_SPKI_HASH_H_ |
| + |
| +#include <stdint.h> |
| +#include <string> |
| +#include <vector> |
| + |
| +namespace net { |
| + |
| +namespace { |
| +// Hashes are always SHA256. |
| +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.
|
| +} // namespace |
| + |
| +class SPKIHash { |
| + public: |
| + SPKIHash(); |
| + ~SPKIHash(); |
| + |
| + // Initalizes a hash from the form sha256/<base64-hash-value>. The preloaded |
| + // SPKI hashes are SHA256. Other algorithms are not supported. Returns true |
| + // on success and copies the decoded bytes to |data_|. Returns false in case |
| + // of an error. |
| + bool FromString(const std::string& hash_string); |
| + |
| + // Calculates the SHA256 digest over |*input|. Returns true on success and |
| + // copies the bytes to |data_|. Returns false in case of an error. |
| + bool CalculateFromBytes(const uint8_t* input, size_t input_length); |
| + |
| + // Returns the size of the hash in bytes. Harcoded to 32 which is the length |
| + // of a SHA256 hash. |
| + size_t size() const { return kSPKIHashLength; } |
| + |
| + uint8_t* data() { return data_; } |
| + const uint8_t* data() const { return data_; }; |
| + |
| + private: |
| + // The bytes of the hash. Current hashes are SHA256 and thus 32 bytes long. |
| + uint8_t data_[kSPKIHashLength]; |
| +}; |
| + |
| +} // namespace net |
| + |
| +#endif // NET_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_SPKI_HASH_H_ |