Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / content / common / ssl_status_serialization.cc
blob364dba0538a4cdf6bdc17263e1fca8a663c74b69
1 // Copyright (c) 2012 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.
5 #include "content/common/ssl_status_serialization.h"
7 #include "base/logging.h"
8 #include "base/pickle.h"
10 namespace content {
12 std::string SerializeSecurityInfo(
13 int cert_id,
14 net::CertStatus cert_status,
15 int security_bits,
16 int ssl_connection_status,
17 const SignedCertificateTimestampIDStatusList&
18 signed_certificate_timestamp_ids) {
19 base::Pickle pickle;
20 pickle.WriteInt(cert_id);
21 pickle.WriteUInt32(cert_status);
22 pickle.WriteInt(security_bits);
23 pickle.WriteInt(ssl_connection_status);
24 pickle.WriteInt(signed_certificate_timestamp_ids.size());
25 for (SignedCertificateTimestampIDStatusList::const_iterator iter =
26 signed_certificate_timestamp_ids.begin();
27 iter != signed_certificate_timestamp_ids.end(); ++iter) {
28 pickle.WriteInt(iter->id);
29 pickle.WriteUInt16(iter->status);
31 return std::string(static_cast<const char*>(pickle.data()), pickle.size());
34 bool DeserializeSecurityInfo(const std::string& state, SSLStatus* ssl_status) {
35 *ssl_status = SSLStatus();
37 if (state.empty()) {
38 // No SSL used.
39 return true;
42 base::Pickle pickle(state.data(), static_cast<int>(state.size()));
43 base::PickleIterator iter(pickle);
44 int num_scts_to_read;
45 if (!iter.ReadInt(&ssl_status->cert_id) ||
46 !iter.ReadUInt32(&ssl_status->cert_status) ||
47 !iter.ReadInt(&ssl_status->security_bits) ||
48 !iter.ReadInt(&ssl_status->connection_status) ||
49 !iter.ReadInt(&num_scts_to_read)) {
50 *ssl_status = SSLStatus();
51 return false;
54 // Sanity check |security_bits|: the only allowed negative value is -1.
55 if (ssl_status->security_bits < -1) {
56 *ssl_status = SSLStatus();
57 return false;
60 for (; num_scts_to_read > 0; --num_scts_to_read) {
61 int id;
62 uint16 status;
63 if (!iter.ReadInt(&id) || !iter.ReadUInt16(&status)) {
64 *ssl_status = SSLStatus();
65 return false;
68 ssl_status->signed_certificate_timestamp_ids.push_back(
69 SignedCertificateTimestampIDAndStatus(
70 id, static_cast<net::ct::SCTVerifyStatus>(status)));
73 return true;
76 } // namespace content