Chromium Code Reviews| Index: components/certificate_transparency/observed_leaf.cc |
| diff --git a/components/certificate_transparency/observed_leaf.cc b/components/certificate_transparency/observed_leaf.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ee010b6c2ad62cced99adace83062b25de4db79b |
| --- /dev/null |
| +++ b/components/certificate_transparency/observed_leaf.cc |
| @@ -0,0 +1,43 @@ |
| +// 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 "components/certificate_transparency/observed_leaf.h" |
| + |
| +#include "base/time/time.h" |
| + |
| +using net::ct::MerkleTreeLeaf; |
| + |
| +ObservedLeaf::ObservedLeaf(MerkleTreeLeaf&& leaf, const base::Time& observed_at) |
| + : leaf_(leaf), observed_at_(observed_at) {} |
| + |
| +ObservedLeaf::ObservedLeaf(const ObservedLeaf& other) = default; |
| + |
| +ObservedLeaf::ObservedLeaf(ObservedLeaf&&) = default; |
| + |
| +ObservedLeaf::~ObservedLeaf() = default; |
| + |
| +void ObservedLeaf::SetLeafIndex(uint64_t index) { |
| + // The leaf index may be set only once. Doing so more than once indicates |
| + // a programming error where the index is fetched more than once for a given |
| + // leaf. |
| + CHECK(!leaf_index_); |
|
Ryan Sleevi
2016/06/30 22:48:18
Then programming errors should be met with DCHECK,
Eran Messeri
2016/07/01 13:24:00
Done.
|
| + leaf_index_ = index; |
| +} |
| + |
| +bool ObservedLeaf::HasLeafIndex() const { |
| + return bool(leaf_index_); |
| +} |
| + |
| +uint64_t ObservedLeaf::GetLeafIndex() const { |
| + CHECK(leaf_index_); |
| + return leaf_index_.value(); |
| +} |
| + |
| +const MerkleTreeLeaf& ObservedLeaf::GetLeaf() const { |
| + return leaf_; |
| +} |
| + |
| +const base::Time& ObservedLeaf::ObservedAt() const { |
| + return observed_at_; |
| +} |