Chromium Code Reviews| 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 if (!(pickle->WriteInt(version) && | |
| 35 pickle->WriteString(log_id) && | |
| 36 pickle->WriteInt64(timestamp.ToInternalValue()) && | |
| 37 pickle->WriteString(extensions) && | |
| 38 pickle->WriteInt(signature.hash_algorithm) && | |
| 39 pickle->WriteInt(signature.signature_algorithm) && | |
| 40 pickle->WriteString(signature.signature_data))) { | |
| 41 NOTREACHED(); | |
|
Eran M. (Google)
2013/11/26 21:33:22
Nit: use CHECK(all conditions) rather than if?
alcutter
2013/11/26 23:00:05
Done.
| |
| 42 return; | |
|
Eran M. (Google)
2013/11/26 21:33:22
The return statement here seems superfluous.
alcutter
2013/11/26 23:00:05
The style of this was lifted from the cert pickle
| |
| 43 } | |
| 44 } | |
| 45 | |
| 46 // static | |
| 47 SignedCertificateTimestamp* | |
| 48 SignedCertificateTimestamp::CreateFromPickle(PickleIterator* iter) { | |
| 49 int version; | |
| 50 std::string log_id; | |
| 51 int64 timestamp; | |
| 52 std::string extensions; | |
| 53 int hash_algorithm; | |
| 54 int sig_algorithm; | |
| 55 std::string sig_data; | |
| 56 if (!(iter->ReadInt(&version) && | |
| 57 iter->ReadString(&log_id) && | |
| 58 iter->ReadInt64(×tamp) && | |
| 59 iter->ReadString(&extensions) && | |
| 60 iter->ReadInt(&hash_algorithm) && | |
| 61 iter->ReadInt(&sig_algorithm) && | |
| 62 iter->ReadString(&sig_data))) { | |
| 63 return NULL; | |
| 64 } | |
| 65 SignedCertificateTimestamp* sct(new SignedCertificateTimestamp()); | |
| 66 sct->version = static_cast<Version>(version); | |
| 67 sct->log_id = log_id; | |
| 68 sct->timestamp = base::Time::FromInternalValue(timestamp); | |
| 69 sct->extensions = extensions; | |
| 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->signature.signature_data = sig_data; | |
| 75 return sct; | |
| 76 } | |
| 77 | |
| 31 LogEntry::LogEntry() {} | 78 LogEntry::LogEntry() {} |
| 32 | 79 |
| 33 LogEntry::~LogEntry() {} | 80 LogEntry::~LogEntry() {} |
| 34 | 81 |
| 35 void LogEntry::Reset() { | 82 void LogEntry::Reset() { |
| 36 type = LogEntry::LOG_ENTRY_TYPE_X509; | 83 type = LogEntry::LOG_ENTRY_TYPE_X509; |
| 37 leaf_certificate.clear(); | 84 leaf_certificate.clear(); |
| 38 tbs_certificate.clear(); | 85 tbs_certificate.clear(); |
| 39 } | 86 } |
| 40 | 87 |
| 41 DigitallySigned::DigitallySigned() {} | 88 DigitallySigned::DigitallySigned() {} |
| 42 | 89 |
| 43 DigitallySigned::~DigitallySigned() {} | 90 DigitallySigned::~DigitallySigned() {} |
| 44 | 91 |
| 45 } // namespace ct | 92 } // namespace ct |
| 46 | 93 |
| 47 } // namespace net | 94 } // namespace net |
| OLD | NEW |