Revert "Re-land: content: Enable one-copy tile updates on Android."
[chromium-blink-merge.git] / net / cert / signed_certificate_timestamp.cc
blobf5f9c946481ead42932d80b107b4d79445daf856
1 // Copyright 2013 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.
5 #include "net/cert/signed_certificate_timestamp.h"
7 #include "base/pickle.h"
9 namespace net {
11 namespace ct {
13 bool SignedCertificateTimestamp::LessThan::operator()(
14 const scoped_refptr<SignedCertificateTimestamp>& lhs,
15 const scoped_refptr<SignedCertificateTimestamp>& rhs) const {
16 if (lhs.get() == rhs.get())
17 return false;
18 if (lhs->signature.signature_data != rhs->signature.signature_data)
19 return lhs->signature.signature_data < rhs->signature.signature_data;
20 if (lhs->log_id != rhs->log_id)
21 return lhs->log_id < rhs->log_id;
22 if (lhs->timestamp != rhs->timestamp)
23 return lhs->timestamp < rhs->timestamp;
24 if (lhs->extensions != rhs->extensions)
25 return lhs->extensions < rhs->extensions;
26 if (lhs->origin != rhs->origin)
27 return lhs->origin < rhs->origin;
28 return lhs->version < rhs->version;
31 SignedCertificateTimestamp::SignedCertificateTimestamp() {}
33 SignedCertificateTimestamp::~SignedCertificateTimestamp() {}
35 void SignedCertificateTimestamp::Persist(base::Pickle* pickle) {
36 CHECK(pickle->WriteInt(version));
37 CHECK(pickle->WriteString(log_id));
38 CHECK(pickle->WriteInt64(timestamp.ToInternalValue()));
39 CHECK(pickle->WriteString(extensions));
40 CHECK(pickle->WriteInt(signature.hash_algorithm));
41 CHECK(pickle->WriteInt(signature.signature_algorithm));
42 CHECK(pickle->WriteString(signature.signature_data));
43 CHECK(pickle->WriteInt(origin));
44 CHECK(pickle->WriteString(log_description));
47 // static
48 scoped_refptr<SignedCertificateTimestamp>
49 SignedCertificateTimestamp::CreateFromPickle(base::PickleIterator* iter) {
50 int version;
51 int64_t timestamp;
52 int hash_algorithm;
53 int sig_algorithm;
54 scoped_refptr<SignedCertificateTimestamp> sct(
55 new SignedCertificateTimestamp());
56 int origin;
57 // string values are set directly
58 if (!(iter->ReadInt(&version) &&
59 iter->ReadString(&sct->log_id) &&
60 iter->ReadInt64(&timestamp) &&
61 iter->ReadString(&sct->extensions) &&
62 iter->ReadInt(&hash_algorithm) &&
63 iter->ReadInt(&sig_algorithm) &&
64 iter->ReadString(&sct->signature.signature_data) &&
65 iter->ReadInt(&origin) &&
66 iter->ReadString(&sct->log_description))) {
67 return NULL;
69 // Now set the rest of the member variables:
70 sct->version = static_cast<Version>(version);
71 sct->timestamp = base::Time::FromInternalValue(timestamp);
72 sct->signature.hash_algorithm =
73 static_cast<DigitallySigned::HashAlgorithm>(hash_algorithm);
74 sct->signature.signature_algorithm =
75 static_cast<DigitallySigned::SignatureAlgorithm>(sig_algorithm);
76 sct->origin = static_cast<Origin>(origin);
77 return sct;
80 LogEntry::LogEntry() {}
82 LogEntry::~LogEntry() {}
84 void LogEntry::Reset() {
85 type = LogEntry::LOG_ENTRY_TYPE_X509;
86 leaf_certificate.clear();
87 tbs_certificate.clear();
90 DigitallySigned::DigitallySigned() {}
92 DigitallySigned::~DigitallySigned() {}
94 bool DigitallySigned::SignatureParametersMatch(
95 HashAlgorithm other_hash_algorithm,
96 SignatureAlgorithm other_signature_algorithm) const {
97 return (hash_algorithm == other_hash_algorithm) &&
98 (signature_algorithm == other_signature_algorithm);
100 } // namespace ct
102 } // namespace net