1 // Copyright 2013 The Chromium Authors 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::ct { 10 operator ()(const scoped_refptr<SignedCertificateTimestamp> & lhs,const scoped_refptr<SignedCertificateTimestamp> & rhs) const11bool SignedCertificateTimestamp::LessThan::operator()( 12 const scoped_refptr<SignedCertificateTimestamp>& lhs, 13 const scoped_refptr<SignedCertificateTimestamp>& rhs) const { 14 if (lhs.get() == rhs.get()) 15 return false; 16 if (lhs->signature.signature_data != rhs->signature.signature_data) 17 return lhs->signature.signature_data < rhs->signature.signature_data; 18 if (lhs->log_id != rhs->log_id) 19 return lhs->log_id < rhs->log_id; 20 if (lhs->timestamp != rhs->timestamp) 21 return lhs->timestamp < rhs->timestamp; 22 if (lhs->extensions != rhs->extensions) 23 return lhs->extensions < rhs->extensions; 24 if (lhs->origin != rhs->origin) 25 return lhs->origin < rhs->origin; 26 return lhs->version < rhs->version; 27 } 28 29 SignedCertificateTimestamp::SignedCertificateTimestamp() = default; 30 31 SignedCertificateTimestamp::~SignedCertificateTimestamp() = default; 32 Persist(base::Pickle * pickle)33void SignedCertificateTimestamp::Persist(base::Pickle* pickle) { 34 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 pickle->WriteInt(origin); 42 pickle->WriteString(log_description); 43 } 44 45 // static 46 scoped_refptr<SignedCertificateTimestamp> CreateFromPickle(base::PickleIterator * iter)47SignedCertificateTimestamp::CreateFromPickle(base::PickleIterator* iter) { 48 int version; 49 int64_t timestamp; 50 int hash_algorithm; 51 int sig_algorithm; 52 auto sct = base::MakeRefCounted<SignedCertificateTimestamp>(); 53 int origin; 54 // string values are set directly 55 if (!(iter->ReadInt(&version) && 56 iter->ReadString(&sct->log_id) && 57 iter->ReadInt64(×tamp) && 58 iter->ReadString(&sct->extensions) && 59 iter->ReadInt(&hash_algorithm) && 60 iter->ReadInt(&sig_algorithm) && 61 iter->ReadString(&sct->signature.signature_data) && 62 iter->ReadInt(&origin) && 63 iter->ReadString(&sct->log_description))) { 64 return nullptr; 65 } 66 // Now set the rest of the member variables: 67 sct->version = static_cast<Version>(version); 68 sct->timestamp = base::Time::FromInternalValue(timestamp); 69 sct->signature.hash_algorithm = 70 static_cast<DigitallySigned::HashAlgorithm>(hash_algorithm); 71 sct->signature.signature_algorithm = 72 static_cast<DigitallySigned::SignatureAlgorithm>(sig_algorithm); 73 sct->origin = static_cast<Origin>(origin); 74 return sct; 75 } 76 77 SignedEntryData::SignedEntryData() = default; 78 79 SignedEntryData::~SignedEntryData() = default; 80 Reset()81void SignedEntryData::Reset() { 82 type = SignedEntryData::LOG_ENTRY_TYPE_X509; 83 leaf_certificate.clear(); 84 tbs_certificate.clear(); 85 } 86 87 DigitallySigned::DigitallySigned() = default; 88 89 DigitallySigned::~DigitallySigned() = default; 90 SignatureParametersMatch(HashAlgorithm other_hash_algorithm,SignatureAlgorithm other_signature_algorithm) const91bool DigitallySigned::SignatureParametersMatch( 92 HashAlgorithm other_hash_algorithm, 93 SignatureAlgorithm other_signature_algorithm) const { 94 return (hash_algorithm == other_hash_algorithm) && 95 (signature_algorithm == other_signature_algorithm); 96 } 97 } // namespace net::ct 98