| OLD | NEW |
| 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 CachedNetworkParameters::CachedNetworkParameters() { |
| 18 } |
| 19 |
| 20 CachedNetworkParameters::~CachedNetworkParameters() { |
| 21 } |
| 22 |
| 17 SourceAddressToken::SourceAddressToken() { | 23 SourceAddressToken::SourceAddressToken() { |
| 18 } | 24 } |
| 19 | 25 |
| 20 SourceAddressToken::~SourceAddressToken() { | 26 SourceAddressToken::~SourceAddressToken() { |
| 21 } | 27 } |
| 22 | 28 |
| 23 string SourceAddressToken::SerializeAsString() const { | 29 string SourceAddressToken::SerializeAsString() const { |
| 24 string out; | 30 string out; |
| 25 out.push_back(ip_.size()); | 31 out.push_back(ip_.size()); |
| 26 out.append(ip_); | 32 out.append(ip_); |
| 27 string time_str = base::Int64ToString(timestamp_); | 33 string time_str = base::Int64ToString(timestamp_); |
| 28 out.push_back(time_str.size()); | 34 out.push_back(time_str.size()); |
| 29 out.append(time_str); | 35 out.append(time_str); |
| 36 // TODO(rtenneti): Implement serialization of optional CachedNetworkParameters |
| 37 // when they are used. |
| 30 return out; | 38 return out; |
| 31 } | 39 } |
| 32 | 40 |
| 33 bool SourceAddressToken::ParseFromArray(const char* plaintext, | 41 bool SourceAddressToken::ParseFromArray(const char* plaintext, |
| 34 size_t plaintext_length) { | 42 size_t plaintext_length) { |
| 35 if (plaintext_length == 0) { | 43 if (plaintext_length == 0) { |
| 36 return false; | 44 return false; |
| 37 } | 45 } |
| 38 size_t ip_len = plaintext[0]; | 46 size_t ip_len = plaintext[0]; |
| 39 if (plaintext_length <= 1 + ip_len) { | 47 if (plaintext_length <= 1 + ip_len) { |
| 40 return false; | 48 return false; |
| 41 } | 49 } |
| 42 size_t time_len = plaintext[1 + ip_len]; | 50 size_t time_len = plaintext[1 + ip_len]; |
| 43 if (plaintext_length != 1 + ip_len + 1 + time_len) { | 51 if (plaintext_length != 1 + ip_len + 1 + time_len) { |
| 44 return false; | 52 return false; |
| 45 } | 53 } |
| 46 | 54 |
| 47 string time_str(&plaintext[1 + ip_len + 1], time_len); | 55 string time_str(&plaintext[1 + ip_len + 1], time_len); |
| 48 int64 timestamp; | 56 int64 timestamp; |
| 49 if (!base::StringToInt64(time_str, ×tamp)) { | 57 if (!base::StringToInt64(time_str, ×tamp)) { |
| 50 return false; | 58 return false; |
| 51 } | 59 } |
| 52 | 60 |
| 53 ip_.assign(&plaintext[1], ip_len); | 61 ip_.assign(&plaintext[1], ip_len); |
| 54 timestamp_ = timestamp; | 62 timestamp_ = timestamp; |
| 63 |
| 64 // TODO(rtenneti): Implement parsing of optional CachedNetworkParameters when |
| 65 // they are used. |
| 55 return true; | 66 return true; |
| 56 } | 67 } |
| 57 | 68 |
| 58 } // namespace net | 69 } // namespace net |
| OLD | NEW |