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

Side by Side Diff: net/quic/crypto/source_address_token.cc

Issue 23464033: Land Recent QUIC changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix valgrind error Created 7 years, 3 months 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 | Annotate | Revision Log
« no previous file with comments | « net/quic/crypto/crypto_server_config.cc ('k') | net/quic/quic_ack_notifier.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 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/quic/crypto/source_address_token.h" 5 #include "net/quic/crypto/source_address_token.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
11 11
12 using std::string; 12 using std::string;
13 using std::vector; 13 using std::vector;
14 14
15 namespace net { 15 namespace net {
16 16
17 SourceAddressToken::SourceAddressToken() { 17 SourceAddressToken::SourceAddressToken() {
18 } 18 }
19 19
20 SourceAddressToken::~SourceAddressToken() { 20 SourceAddressToken::~SourceAddressToken() {
21 } 21 }
22 22
23 string SourceAddressToken::SerializeAsString() const { 23 string SourceAddressToken::SerializeAsString() const {
24 return ip_ + " " + base::Int64ToString(timestamp_); 24 string out;
25 out.push_back(ip_.size());
26 out.append(ip_);
27 string time_str = base::Int64ToString(timestamp_);
28 out.push_back(time_str.size());
29 out.append(time_str);
30 return out;
25 } 31 }
26 32
27 bool SourceAddressToken::ParseFromArray(const char* plaintext, 33 bool SourceAddressToken::ParseFromArray(const char* plaintext,
28 size_t plaintext_length) { 34 size_t plaintext_length) {
29 string data(plaintext, plaintext_length); 35 if (plaintext_length == 0) {
30 vector<string> results; 36 return false;
31 base::SplitString(data, ' ', &results); 37 }
32 if (results.size() < 2) { 38 size_t ip_len = plaintext[0];
39 if (plaintext_length <= 1 + ip_len) {
40 return false;
41 }
42 size_t time_len = plaintext[1 + ip_len];
43 if (plaintext_length != 1 + ip_len + 1 + time_len) {
33 return false; 44 return false;
34 } 45 }
35 46
47 string time_str(&plaintext[1 + ip_len + 1], time_len);
36 int64 timestamp; 48 int64 timestamp;
37 if (!base::StringToInt64(results[1], &timestamp)) { 49 if (!base::StringToInt64(time_str, &timestamp)) {
38 return false; 50 return false;
39 } 51 }
40 52
41 ip_ = results[0]; 53 ip_.assign(&plaintext[1], ip_len);
42 timestamp_ = timestamp; 54 timestamp_ = timestamp;
43 return true; 55 return true;
44 } 56 }
45 57
46 } // namespace net 58 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/crypto/crypto_server_config.cc ('k') | net/quic/quic_ack_notifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698