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 operator ()(const scoped_refptr<SignedCertificateTimestamp> & lhs,const scoped_refptr<SignedCertificateTimestamp> & rhs) const13bool 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 SignedCertificateTimestamp()29SignedCertificateTimestamp::SignedCertificateTimestamp() {} 30 ~SignedCertificateTimestamp()31SignedCertificateTimestamp::~SignedCertificateTimestamp() {} 32 Persist(Pickle * pickle)33void 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> CreateFromPickle(PickleIterator * iter)47SignedCertificateTimestamp::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 LogEntry()78LogEntry::LogEntry() {} 79 ~LogEntry()80LogEntry::~LogEntry() {} 81 Reset()82void LogEntry::Reset() { 83 type = LogEntry::LOG_ENTRY_TYPE_X509; 84 leaf_certificate.clear(); 85 tbs_certificate.clear(); 86 } 87 DigitallySigned()88DigitallySigned::DigitallySigned() {} 89 ~DigitallySigned()90DigitallySigned::~DigitallySigned() {} 91 SignatureParametersMatch(HashAlgorithm other_hash_algorithm,SignatureAlgorithm other_signature_algorithm) const92bool 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 101