Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: net/cert/signed_certificate_timestamp.cc

Issue 88643002: SignedCertificateTimestamp storing & serialization code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@erans_patches
Patch Set: remove a spurious content:: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 std::string log_id;
48 int64 timestamp;
49 std::string extensions;
50 int hash_algorithm;
51 int sig_algorithm;
52 std::string sig_data;
wtc 2013/11/28 01:28:02 Remove the local variables log_id, extensions, sig
alcutter 2013/11/28 12:08:19 Sorry, done.
53 scoped_refptr<SignedCertificateTimestamp> sct;
54 // string values are set directly
55 if (!(iter->ReadInt(&version) &&
56 iter->ReadString(&sct->log_id) &&
57 iter->ReadInt64(&timestamp) &&
58 iter->ReadString(&sct->extensions) &&
59 iter->ReadInt(&hash_algorithm) &&
60 iter->ReadInt(&sig_algorithm) &&
61 iter->ReadString(&sct->signature.signature_data))) {
62 return NULL;
63 }
64 // Now set the rest of the member vars:
wtc 2013/11/28 01:28:02 Nit: vars => variables Our Style Guide seems to r
alcutter 2013/11/28 12:08:19 Done.
65 sct->version = static_cast<Version>(version);
66 sct->timestamp = base::Time::FromInternalValue(timestamp);
67 sct->signature.hash_algorithm =
68 static_cast<DigitallySigned::HashAlgorithm>(hash_algorithm);
69 sct->signature.signature_algorithm =
70 static_cast<DigitallySigned::SignatureAlgorithm>(sig_algorithm);
71 return sct;
72 }
73
31 LogEntry::LogEntry() {} 74 LogEntry::LogEntry() {}
32 75
33 LogEntry::~LogEntry() {} 76 LogEntry::~LogEntry() {}
34 77
35 void LogEntry::Reset() { 78 void LogEntry::Reset() {
36 type = LogEntry::LOG_ENTRY_TYPE_X509; 79 type = LogEntry::LOG_ENTRY_TYPE_X509;
37 leaf_certificate.clear(); 80 leaf_certificate.clear();
38 tbs_certificate.clear(); 81 tbs_certificate.clear();
39 } 82 }
40 83
41 DigitallySigned::DigitallySigned() {} 84 DigitallySigned::DigitallySigned() {}
42 85
43 DigitallySigned::~DigitallySigned() {} 86 DigitallySigned::~DigitallySigned() {}
44 87
45 } // namespace ct 88 } // namespace ct
46 89
47 } // namespace net 90 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698