1// Copyright 2014 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_CERT_SIGNED_TREE_HEAD_H_
6#define NET_CERT_SIGNED_TREE_HEAD_H_
7
8#include <stdint.h>
9
10#include <iosfwd>
11#include <string>
12#include <vector>
13
14#include "base/time/time.h"
15#include "net/base/hash_value.h"
16#include "net/base/net_export.h"
17#include "net/cert/signed_certificate_timestamp.h"
18
19namespace net {
20
21namespace ct {
22
23static const uint8_t kSthRootHashLength = 32;
24
25// Signed Tree Head as defined in section 3.5. of RFC6962
26struct NET_EXPORT SignedTreeHead {
27 // Version enum in RFC 6962, Section 3.2. Note that while in the current
28 // RFC the STH and SCT share the versioning scheme, there are plans in
29 // RFC6962-bis to use separate versions, so using a separate scheme here.
30 enum Version { V1 = 0, };
31
32 SignedTreeHead();
33 SignedTreeHead(Version version,
34 const base::Time& timestamp,
35 uint64_t tree_size,
36 const char sha256_root_hash[kSthRootHashLength],
37 const DigitallySigned& signature,
38 const std::string& log_id);
39 SignedTreeHead(const SignedTreeHead& other);
40 ~SignedTreeHead();
41
42 Version version;
43 base::Time timestamp;
44 uint64_t tree_size;
45 char sha256_root_hash[kSthRootHashLength];
46 DigitallySigned signature;
47
48 // Added in RFC6962-bis, Appendix A. Needed to identify which log
49 // this STH belongs to.
50 std::string log_id;
51};
52
53NET_EXPORT void PrintTo(const SignedTreeHead& sth, std::ostream* os);
54
55NET_EXPORT bool operator==(const SignedTreeHead& lhs,
56 const SignedTreeHead& rhs);
57NET_EXPORT bool operator!=(const SignedTreeHead& lhs,
58 const SignedTreeHead& rhs);
59
60} // namespace ct
61
62} // namespace net
63
64#endif // NET_CERT_SIGNED_TREE_HEAD_H_
65