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