blob: dcb7267e15c3c6cf736360532bf0571599b7375c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/quic/crypto/source_address_token.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
using std::string;
namespace net {
SourceAddressToken::SourceAddressToken()
: has_cached_network_parameters_(false) {
}
SourceAddressToken::~SourceAddressToken() {
}
string SourceAddressToken::SerializeAsString() const {
string out;
out.push_back(static_cast<char>(ip_.size()));
out.append(ip_);
string time_str = base::Int64ToString(timestamp_);
out.push_back(static_cast<char>(time_str.size()));
out.append(time_str);
// TODO(rtenneti): Implement serialization of optional CachedNetworkParameters
// when they are used.
return out;
}
bool SourceAddressToken::ParseFromArray(const char* plaintext,
size_t plaintext_length) {
if (plaintext_length == 0) {
return false;
}
size_t ip_len = plaintext[0];
if (plaintext_length <= 1 + ip_len) {
return false;
}
size_t time_len = plaintext[1 + ip_len];
if (plaintext_length != 1 + ip_len + 1 + time_len) {
return false;
}
string time_str(&plaintext[1 + ip_len + 1], time_len);
int64 timestamp;
if (!base::StringToInt64(time_str, ×tamp)) {
return false;
}
ip_.assign(&plaintext[1], ip_len);
timestamp_ = timestamp;
// TODO(rtenneti): Implement parsing of optional CachedNetworkParameters when
// they are used.
return true;
}
SourceAddressTokens::SourceAddressTokens() {
}
SourceAddressTokens::~SourceAddressTokens() {
STLDeleteElements(&tokens_);
}
string SourceAddressTokens::SerializeAsString() const {
string out;
for (size_t i = 0; i < tokens_size(); i++) {
const SourceAddressToken& source_address_token = tokens(i);
out.append(source_address_token.SerializeAsString());
}
return out;
}
bool SourceAddressTokens::ParseFromArray(const char* plaintext,
size_t plaintext_length) {
// TODO(rtenneti): Implement parsing of SourceAddressTokens when they are
// used.
return true;
}
} // namespace net
|