1 // Copyright 2014 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 "net/quic/crypto/quic_server_info.h"
9 #include "base/pickle.h"
15 const int kQuicCryptoConfigVersion
= 1;
21 QuicServerInfo::State::State() {}
23 QuicServerInfo::State::~State() {}
25 void QuicServerInfo::State::Clear() {
26 server_config
.clear();
27 source_address_token
.clear();
28 server_config_sig
.clear();
32 QuicServerInfo::QuicServerInfo(const QuicServerId
& server_id
)
33 : server_id_(server_id
) {
36 QuicServerInfo::~QuicServerInfo() {
39 const QuicServerInfo::State
& QuicServerInfo::state() const {
43 QuicServerInfo::State
* QuicServerInfo::mutable_state() {
47 bool QuicServerInfo::Parse(const string
& data
) {
48 State
* state
= mutable_state();
52 bool r
= ParseInner(data
);
58 bool QuicServerInfo::ParseInner(const string
& data
) {
59 State
* state
= mutable_state();
61 // No data was read from the disk cache.
66 Pickle
p(data
.data(), data
.size());
67 PickleIterator
iter(p
);
70 if (!p
.ReadInt(&iter
, &version
)) {
71 DVLOG(1) << "Missing version";
75 if (version
!= kQuicCryptoConfigVersion
) {
76 DVLOG(1) << "Unsupported version";
80 if (!p
.ReadString(&iter
, &state
->server_config
)) {
81 DVLOG(1) << "Malformed server_config";
84 if (!p
.ReadString(&iter
, &state
->source_address_token
)) {
85 DVLOG(1) << "Malformed source_address_token";
88 if (!p
.ReadString(&iter
, &state
->server_config_sig
)) {
89 DVLOG(1) << "Malformed server_config_sig";
95 if (!p
.ReadUInt32(&iter
, &num_certs
)) {
96 DVLOG(1) << "Malformed num_certs";
100 for (uint32 i
= 0; i
< num_certs
; i
++) {
102 if (!p
.ReadString(&iter
, &cert
)) {
103 DVLOG(1) << "Malformed cert";
106 state
->certs
.push_back(cert
);
112 string
QuicServerInfo::Serialize() {
113 string pickled_data
= SerializeInner();
118 string
QuicServerInfo::SerializeInner() const {
119 Pickle
p(sizeof(Pickle::Header
));
121 if (!p
.WriteInt(kQuicCryptoConfigVersion
) ||
122 !p
.WriteString(state_
.server_config
) ||
123 !p
.WriteString(state_
.source_address_token
) ||
124 !p
.WriteString(state_
.server_config_sig
) ||
125 state_
.certs
.size() > std::numeric_limits
<uint32
>::max() ||
126 !p
.WriteUInt32(state_
.certs
.size())) {
130 for (size_t i
= 0; i
< state_
.certs
.size(); i
++) {
131 if (!p
.WriteString(state_
.certs
[i
])) {
136 return string(reinterpret_cast<const char *>(p
.data()), p
.size());
139 QuicServerInfoFactory::~QuicServerInfoFactory() {}