OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/cert/signed_certificate_timestamp.h" | 5 #include "net/cert/signed_certificate_timestamp.h" |
6 | 6 |
| 7 #include "base/pickle.h" |
| 8 |
7 namespace net { | 9 namespace net { |
8 | 10 |
9 namespace ct { | 11 namespace ct { |
10 | 12 |
11 bool SignedCertificateTimestamp::LessThan::operator()( | 13 bool SignedCertificateTimestamp::LessThan::operator()( |
12 const scoped_refptr<SignedCertificateTimestamp>& lhs, | 14 const scoped_refptr<SignedCertificateTimestamp>& lhs, |
13 const scoped_refptr<SignedCertificateTimestamp>& rhs) const { | 15 const scoped_refptr<SignedCertificateTimestamp>& rhs) const { |
14 if (lhs.get() == rhs.get()) | 16 if (lhs.get() == rhs.get()) |
15 return false; | 17 return false; |
16 if (lhs->signature.signature_data != rhs->signature.signature_data) | 18 if (lhs->signature.signature_data != rhs->signature.signature_data) |
17 return lhs->signature.signature_data < rhs->signature.signature_data; | 19 return lhs->signature.signature_data < rhs->signature.signature_data; |
18 if (lhs->log_id != rhs->log_id) | 20 if (lhs->log_id != rhs->log_id) |
19 return lhs->log_id < rhs->log_id; | 21 return lhs->log_id < rhs->log_id; |
20 if (lhs->timestamp != rhs->timestamp) | 22 if (lhs->timestamp != rhs->timestamp) |
21 return lhs->timestamp < rhs->timestamp; | 23 return lhs->timestamp < rhs->timestamp; |
22 if (lhs->extensions != rhs->extensions) | 24 if (lhs->extensions != rhs->extensions) |
23 return lhs->extensions < rhs->extensions; | 25 return lhs->extensions < rhs->extensions; |
24 return lhs->version < rhs->version; | 26 return lhs->version < rhs->version; |
25 } | 27 } |
26 | 28 |
27 SignedCertificateTimestamp::SignedCertificateTimestamp() {} | 29 SignedCertificateTimestamp::SignedCertificateTimestamp() {} |
28 | 30 |
29 SignedCertificateTimestamp::~SignedCertificateTimestamp() {} | 31 SignedCertificateTimestamp::~SignedCertificateTimestamp() {} |
30 | 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 } |
| 42 |
| 43 // static |
| 44 scoped_refptr<SignedCertificateTimestamp> |
| 45 SignedCertificateTimestamp::CreateFromPickle(PickleIterator* iter) { |
| 46 int version; |
| 47 int64 timestamp; |
| 48 int hash_algorithm; |
| 49 int sig_algorithm; |
| 50 scoped_refptr<SignedCertificateTimestamp> sct( |
| 51 new SignedCertificateTimestamp()); |
| 52 // string values are set directly |
| 53 if (!(iter->ReadInt(&version) && |
| 54 iter->ReadString(&sct->log_id) && |
| 55 iter->ReadInt64(×tamp) && |
| 56 iter->ReadString(&sct->extensions) && |
| 57 iter->ReadInt(&hash_algorithm) && |
| 58 iter->ReadInt(&sig_algorithm) && |
| 59 iter->ReadString(&sct->signature.signature_data))) { |
| 60 return NULL; |
| 61 } |
| 62 // Now set the rest of the member variables: |
| 63 sct->version = static_cast<Version>(version); |
| 64 sct->timestamp = base::Time::FromInternalValue(timestamp); |
| 65 sct->signature.hash_algorithm = |
| 66 static_cast<DigitallySigned::HashAlgorithm>(hash_algorithm); |
| 67 sct->signature.signature_algorithm = |
| 68 static_cast<DigitallySigned::SignatureAlgorithm>(sig_algorithm); |
| 69 return sct; |
| 70 } |
| 71 |
31 LogEntry::LogEntry() {} | 72 LogEntry::LogEntry() {} |
32 | 73 |
33 LogEntry::~LogEntry() {} | 74 LogEntry::~LogEntry() {} |
34 | 75 |
35 void LogEntry::Reset() { | 76 void LogEntry::Reset() { |
36 type = LogEntry::LOG_ENTRY_TYPE_X509; | 77 type = LogEntry::LOG_ENTRY_TYPE_X509; |
37 leaf_certificate.clear(); | 78 leaf_certificate.clear(); |
38 tbs_certificate.clear(); | 79 tbs_certificate.clear(); |
39 } | 80 } |
40 | 81 |
41 DigitallySigned::DigitallySigned() {} | 82 DigitallySigned::DigitallySigned() {} |
42 | 83 |
43 DigitallySigned::~DigitallySigned() {} | 84 DigitallySigned::~DigitallySigned() {} |
44 | 85 |
45 } // namespace ct | 86 } // namespace ct |
46 | 87 |
47 } // namespace net | 88 } // namespace net |
OLD | NEW |