Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(937)

Unified Diff: net/cert/ct_trans_item.cc

Issue 1576513002: Serialisation code for Certificate Transparency data (Closed) Base URL: ssh://caladan.lon.corp.google.com/usr/local/google/eranm/opensource_clients/chrome/src@sth_consistency_validation_2
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/cert/ct_trans_item.cc
diff --git a/net/cert/ct_trans_item.cc b/net/cert/ct_trans_item.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d31ff274ba22293eb7c0439dd85af9bb409e99fd
--- /dev/null
+++ b/net/cert/ct_trans_item.cc
@@ -0,0 +1,160 @@
+// Copyright 2015 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/ct_trans_item.h"
+
+#include "net/cert/merkle_consistency_proof.h"
+#include "net/cert/signed_certificate_timestamp.h"
+#include "net/cert/signed_tree_head.h"
+
+namespace net {
+namespace ct {
+
+std::ostream& operator<<(std::ostream& stream, const TransType& type) {
+ switch (type) {
+ case TransType::X509_SCT:
+ return stream << "X509_SCT";
+ case TransType::SIGNED_TREE_HEAD:
+ return stream << "SIGNED_TREE_HEAD";
+ case TransType::CONSISTENCY_PROOF:
+ return stream << "CONSISTENCY_PROOF";
+ }
+
+ return stream << static_cast<uint16_t>(type);
+}
+
+TransItemV1::TransItemV1() {}
+
+TransItemV1::~TransItemV1() {}
+
+TransType TransItemV1::type() const {
+ CHECK(type_);
+ return *type_;
+}
+
+scoped_refptr<SignedCertificateTimestamp> TransItemV1::x509_sct() const {
+ CHECK_EQ(TransType::X509_SCT, type());
+ return x509_sct_;
+}
+
+const SignedTreeHead& TransItemV1::signed_tree_head() const {
+ CHECK_EQ(TransType::SIGNED_TREE_HEAD, type());
+ return *signed_tree_head_;
+}
+
+const MerkleConsistencyProof& TransItemV1::consistency_proof() const {
+ CHECK_EQ(TransType::CONSISTENCY_PROOF, type());
+ return *consistency_proof_;
+}
+
+void TransItemV1::SetX509Sct(scoped_refptr<SignedCertificateTimestamp> sct) {
+ Clear();
+ x509_sct_ = sct;
+ type_.reset(new TransType(TransType::X509_SCT));
+}
+
+void TransItemV1::SetSignedTreeHead(const SignedTreeHead& sth) {
+ Clear();
+ signed_tree_head_.reset(new SignedTreeHead(sth));
+ type_.reset(new TransType(TransType::SIGNED_TREE_HEAD));
+}
+
+void TransItemV1::SetConsistencyProof(const MerkleConsistencyProof& proof) {
+ Clear();
+ consistency_proof_.reset(new MerkleConsistencyProof(proof));
+ type_.reset(new TransType(TransType::CONSISTENCY_PROOF));
+}
+
+void TransItemV1::Clear() {
+ if (type_ == nullptr) {
+ return;
+ }
+
+ switch (*type_) {
+ case TransType::X509_SCT:
+ x509_sct_ = nullptr;
+ break;
+ case TransType::SIGNED_TREE_HEAD:
+ signed_tree_head_.reset(nullptr);
+ break;
+ case TransType::CONSISTENCY_PROOF:
+ consistency_proof_.reset(nullptr);
+ break;
+ }
+
+ type_.reset(nullptr);
+}
+
+std::ostream& operator<<(std::ostream& stream, const TransItemV1& item) {
+ if (!item.IsTypeSet()) {
+ return stream << "TransItemV1";
+ }
+
+ return stream << "TransItemV1(" << item.type() << ")";
+}
+
+TransItem::TransItem() {}
+
+TransItem::TransItem(scoped_ptr<TransItemV1> item) {
+ Set(std::move(item));
+}
+
+TransItem::~TransItem() {}
+
+TransItem::Version TransItem::version() const {
+ CHECK(version_);
+ return *version_;
+}
+
+const TransItemV1& TransItem::v1() const {
+ CHECK_EQ(Version::V1, version());
+ return *v1_;
+}
+
+void TransItem::Set(scoped_ptr<TransItemV1> item) {
+ Clear();
+ v1_.swap(item);
+ version_.reset(new Version(Version::V1));
+}
+
+void TransItem::Clear() {
+ if (version_ == nullptr) {
+ return;
+ }
+
+ switch (*version_) {
+ case Version::V1:
+ v1_.reset(nullptr);
+ break;
+ }
+
+ version_.reset(nullptr);
+}
+
+std::ostream& operator<<(std::ostream& stream,
+ const TransItem::Version& version) {
+ switch (version) {
+ case TransItem::Version::V1:
+ return stream << "v1";
+ }
+
+ return stream << "v" << (static_cast<unsigned>(version) + 1);
+}
+
+std::ostream& operator<<(std::ostream& stream, const TransItem& item) {
+ if (!item.IsVersionSet()) {
+ return stream << "TransItem";
+ }
+
+ switch (item.version()) {
+ case TransItem::Version::V1:
+ return stream << "TransItem(" << item.version() << ", "
+ << item.v1().type() << ")";
+ }
+
+ return stream << "TransItem(" << item.version();
+}
+
+} // namespace ct
+} // namespace net

Powered by Google App Engine
This is Rietveld 408576698