diff options
Diffstat (limited to 'net/cert')
-rw-r--r-- | net/cert/signed_tree_head.cc | 46 | ||||
-rw-r--r-- | net/cert/signed_tree_head.h | 17 |
2 files changed, 63 insertions, 0 deletions
diff --git a/net/cert/signed_tree_head.cc b/net/cert/signed_tree_head.cc new file mode 100644 index 0000000..ef1ab70 --- /dev/null +++ b/net/cert/signed_tree_head.cc @@ -0,0 +1,46 @@ +// Copyright 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. + +#include "net/cert/signed_tree_head.h" + +#include <string.h> + +#include "base/strings/string_number_conversions.h" + +namespace net { +namespace ct { + +SignedTreeHead::SignedTreeHead() {} + +SignedTreeHead::SignedTreeHead(Version version, + const base::Time& timestamp, + uint64_t tree_size, + const char sha256_root_hash[kSthRootHashLength], + const DigitallySigned& signature, + const std::string& log_id) + : version(version), + timestamp(timestamp), + tree_size(tree_size), + signature(signature), + log_id(log_id) { + memcpy(this->sha256_root_hash, sha256_root_hash, kSthRootHashLength); +} + +SignedTreeHead::~SignedTreeHead() {} + +std::ostream& operator<<(std::ostream& stream, const SignedTreeHead& sth) { + return stream << "{\n" + << "\t\"version\": " << sth.version << ",\n" + << "\t\"timestamp\": " << sth.timestamp << ",\n" + << "\t\"tree_size\": " << sth.tree_size << ",\n" + << "\t\"sha256_root_hash\": \"" + << base::HexEncode(sth.sha256_root_hash, kSthRootHashLength) + << "\",\n\t\"log_id\": \"" + << base::HexEncode(sth.log_id.data(), sth.log_id.size()) + << "\"\n" + << "}"; +} + +} // namespace ct +} // namespace net diff --git a/net/cert/signed_tree_head.h b/net/cert/signed_tree_head.h index 1613736..6ff93b0 100644 --- a/net/cert/signed_tree_head.h +++ b/net/cert/signed_tree_head.h @@ -7,6 +7,7 @@ #include <stdint.h> +#include <iosfwd> #include <string> #include <vector> @@ -28,13 +29,29 @@ struct NET_EXPORT SignedTreeHead { // RFC6962-bis to use separate versions, so using a separate scheme here. enum Version { V1 = 0, }; + SignedTreeHead(); + SignedTreeHead(Version version, + const base::Time& timestamp, + uint64_t tree_size, + const char sha256_root_hash[kSthRootHashLength], + const DigitallySigned& signature, + const std::string& log_id); + ~SignedTreeHead(); + Version version; base::Time timestamp; uint64_t tree_size; char sha256_root_hash[kSthRootHashLength]; DigitallySigned signature; + + // Added in RFC6962-bis, Appendix A. Needed to identify which log + // this STH belongs to. + std::string log_id; }; +NET_EXPORT std::ostream& operator<<(std::ostream& stream, + const SignedTreeHead& sth); + } // namespace ct } // namespace net |