OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "net/cert/signed_certificate_timestamp.h" | |
6 | |
7 #include "base/pickle.h" | |
8 | |
9 namespace net { | |
10 | |
11 namespace ct { | |
12 | |
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 return lhs->version < rhs->version; | |
27 } | |
28 | |
29 SignedCertificateTimestamp::SignedCertificateTimestamp() {} | |
30 | |
31 SignedCertificateTimestamp::~SignedCertificateTimestamp() {} | |
32 | |
33 void SignedCertificateTimestamp::Persist(Pickle* pickle) { | |
34 CHECK(pickle->WriteInt(version)); | |
35 CHECK(pickle->WriteString(log_id)); | |
36 CHECK(pickle->WriteInt64(timestamp.ToInternalValue())); | |
37 CHECK(pickle->WriteString(extensions)); | |
38 CHECK(pickle->WriteInt(signature.hash_algorithm)); | |
39 CHECK(pickle->WriteInt(signature.signature_algorithm)); | |
40 CHECK(pickle->WriteString(signature.signature_data)); | |
41 CHECK(pickle->WriteInt(origin)); | |
42 CHECK(pickle->WriteString(log_description)); | |
43 } | |
44 | |
45 // static | |
46 scoped_refptr<SignedCertificateTimestamp> | |
47 SignedCertificateTimestamp::CreateFromPickle(PickleIterator* iter) { | |
48 int version; | |
49 int64 timestamp; | |
50 int hash_algorithm; | |
51 int sig_algorithm; | |
52 scoped_refptr<SignedCertificateTimestamp> sct( | |
53 new SignedCertificateTimestamp()); | |
54 int origin; | |
55 // string values are set directly | |
56 if (!(iter->ReadInt(&version) && | |
57 iter->ReadString(&sct->log_id) && | |
58 iter->ReadInt64(×tamp) && | |
59 iter->ReadString(&sct->extensions) && | |
60 iter->ReadInt(&hash_algorithm) && | |
61 iter->ReadInt(&sig_algorithm) && | |
62 iter->ReadString(&sct->signature.signature_data) && | |
63 iter->ReadInt(&origin) && | |
64 iter->ReadString(&sct->log_description))) { | |
65 return NULL; | |
66 } | |
67 // Now set the rest of the member variables: | |
68 sct->version = static_cast<Version>(version); | |
69 sct->timestamp = base::Time::FromInternalValue(timestamp); | |
70 sct->signature.hash_algorithm = | |
71 static_cast<DigitallySigned::HashAlgorithm>(hash_algorithm); | |
72 sct->signature.signature_algorithm = | |
73 static_cast<DigitallySigned::SignatureAlgorithm>(sig_algorithm); | |
74 sct->origin = static_cast<Origin>(origin); | |
75 return sct; | |
76 } | |
77 | |
78 LogEntry::LogEntry() {} | |
79 | |
80 LogEntry::~LogEntry() {} | |
81 | |
82 void LogEntry::Reset() { | |
83 type = LogEntry::LOG_ENTRY_TYPE_X509; | |
84 leaf_certificate.clear(); | |
85 tbs_certificate.clear(); | |
86 } | |
87 | |
88 DigitallySigned::DigitallySigned() {} | |
89 | |
90 DigitallySigned::~DigitallySigned() {} | |
91 | |
92 bool DigitallySigned::SignatureParametersMatch( | |
93 HashAlgorithm other_hash_algorithm, | |
94 SignatureAlgorithm other_signature_algorithm) const { | |
95 return (hash_algorithm == other_hash_algorithm) && | |
96 (signature_algorithm == other_signature_algorithm); | |
97 } | |
98 } // namespace ct | |
99 | |
100 } // namespace net | |
OLD | NEW |