Sort unlaunched apps on app list start page by apps grid order.
[chromium-blink-merge.git] / net / quic / crypto / source_address_token.cc
blobdcb7267e15c3c6cf736360532bf0571599b7375c
1 // Copyright (c) 2013 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/source_address_token.h"
7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_split.h"
10 using std::string;
12 namespace net {
14 SourceAddressToken::SourceAddressToken()
15 : has_cached_network_parameters_(false) {
18 SourceAddressToken::~SourceAddressToken() {
21 string SourceAddressToken::SerializeAsString() const {
22 string out;
23 out.push_back(static_cast<char>(ip_.size()));
24 out.append(ip_);
25 string time_str = base::Int64ToString(timestamp_);
26 out.push_back(static_cast<char>(time_str.size()));
27 out.append(time_str);
28 // TODO(rtenneti): Implement serialization of optional CachedNetworkParameters
29 // when they are used.
30 return out;
33 bool SourceAddressToken::ParseFromArray(const char* plaintext,
34 size_t plaintext_length) {
35 if (plaintext_length == 0) {
36 return false;
38 size_t ip_len = plaintext[0];
39 if (plaintext_length <= 1 + ip_len) {
40 return false;
42 size_t time_len = plaintext[1 + ip_len];
43 if (plaintext_length != 1 + ip_len + 1 + time_len) {
44 return false;
47 string time_str(&plaintext[1 + ip_len + 1], time_len);
48 int64 timestamp;
49 if (!base::StringToInt64(time_str, &timestamp)) {
50 return false;
53 ip_.assign(&plaintext[1], ip_len);
54 timestamp_ = timestamp;
56 // TODO(rtenneti): Implement parsing of optional CachedNetworkParameters when
57 // they are used.
58 return true;
61 SourceAddressTokens::SourceAddressTokens() {
64 SourceAddressTokens::~SourceAddressTokens() {
65 STLDeleteElements(&tokens_);
68 string SourceAddressTokens::SerializeAsString() const {
69 string out;
71 for (size_t i = 0; i < tokens_size(); i++) {
72 const SourceAddressToken& source_address_token = tokens(i);
73 out.append(source_address_token.SerializeAsString());
75 return out;
78 bool SourceAddressTokens::ParseFromArray(const char* plaintext,
79 size_t plaintext_length) {
80 // TODO(rtenneti): Implement parsing of SourceAddressTokens when they are
81 // used.
82 return true;
85 } // namespace net