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"
13 bool SignedCertificateTimestamp::LessThan::operator()(
14 const scoped_refptr
<SignedCertificateTimestamp
>& lhs
,
15 const scoped_refptr
<SignedCertificateTimestamp
>& rhs
) const {
16 if (lhs
.get() == rhs
.get())
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
;
29 SignedCertificateTimestamp::SignedCertificateTimestamp() {}
31 SignedCertificateTimestamp::~SignedCertificateTimestamp() {}
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
));
46 scoped_refptr
<SignedCertificateTimestamp
>
47 SignedCertificateTimestamp::CreateFromPickle(PickleIterator
* iter
) {
52 scoped_refptr
<SignedCertificateTimestamp
> sct(
53 new SignedCertificateTimestamp());
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
))) {
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
);
78 LogEntry::LogEntry() {}
80 LogEntry::~LogEntry() {}
82 void LogEntry::Reset() {
83 type
= LogEntry::LOG_ENTRY_TYPE_X509
;
84 leaf_certificate
.clear();
85 tbs_certificate
.clear();
88 DigitallySigned::DigitallySigned() {}
90 DigitallySigned::~DigitallySigned() {}
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
);