| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/crypto_framer.h" | 5 #include "net/quic/crypto/crypto_framer.h" |
| 6 | 6 |
| 7 #include "net/quic/crypto/crypto_protocol.h" | 7 #include "net/quic/crypto/crypto_protocol.h" |
| 8 #include "net/quic/quic_data_reader.h" | 8 #include "net/quic/quic_data_reader.h" |
| 9 #include "net/quic/quic_data_writer.h" | 9 #include "net/quic/quic_data_writer.h" |
| 10 | 10 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 if (delta > overhead) { | 99 if (delta > overhead) { |
| 100 pad_length = delta - overhead; | 100 pad_length = delta - overhead; |
| 101 } | 101 } |
| 102 len += overhead + pad_length; | 102 len += overhead + pad_length; |
| 103 } | 103 } |
| 104 | 104 |
| 105 if (num_entries > kMaxEntries) { | 105 if (num_entries > kMaxEntries) { |
| 106 return nullptr; | 106 return nullptr; |
| 107 } | 107 } |
| 108 | 108 |
| 109 | 109 scoped_ptr<char[]> buffer(new char[len]); |
| 110 QuicDataWriter writer(len); | 110 QuicDataWriter writer(len, buffer.get()); |
| 111 if (!writer.WriteUInt32(message.tag())) { | 111 if (!writer.WriteUInt32(message.tag())) { |
| 112 DCHECK(false) << "Failed to write message tag."; | 112 DCHECK(false) << "Failed to write message tag."; |
| 113 return nullptr; | 113 return nullptr; |
| 114 } | 114 } |
| 115 if (!writer.WriteUInt16(static_cast<uint16>(num_entries))) { | 115 if (!writer.WriteUInt16(static_cast<uint16>(num_entries))) { |
| 116 DCHECK(false) << "Failed to write size."; | 116 DCHECK(false) << "Failed to write size."; |
| 117 return nullptr; | 117 return nullptr; |
| 118 } | 118 } |
| 119 if (!writer.WriteUInt16(0)) { | 119 if (!writer.WriteUInt16(0)) { |
| 120 DCHECK(false) << "Failed to write padding."; | 120 DCHECK(false) << "Failed to write padding."; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 } | 174 } |
| 175 } | 175 } |
| 176 | 176 |
| 177 if (need_pad_value) { | 177 if (need_pad_value) { |
| 178 if (!writer.WriteRepeatedByte('-', pad_length)) { | 178 if (!writer.WriteRepeatedByte('-', pad_length)) { |
| 179 DCHECK(false) << "Failed to write padding."; | 179 DCHECK(false) << "Failed to write padding."; |
| 180 return nullptr; | 180 return nullptr; |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 | 183 |
| 184 return new QuicData(writer.take(), len, true); | 184 return new QuicData(buffer.release(), len, true); |
| 185 } | 185 } |
| 186 | 186 |
| 187 void CryptoFramer::Clear() { | 187 void CryptoFramer::Clear() { |
| 188 message_.Clear(); | 188 message_.Clear(); |
| 189 tags_and_lengths_.clear(); | 189 tags_and_lengths_.clear(); |
| 190 error_ = QUIC_NO_ERROR; | 190 error_ = QUIC_NO_ERROR; |
| 191 state_ = STATE_READING_TAG; | 191 state_ = STATE_READING_TAG; |
| 192 } | 192 } |
| 193 | 193 |
| 194 QuicErrorCode CryptoFramer::Process(StringPiece input) { | 194 QuicErrorCode CryptoFramer::Process(StringPiece input) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 } | 280 } |
| 281 *end_offset += pad_length; | 281 *end_offset += pad_length; |
| 282 if (!writer->WriteUInt32(*end_offset)) { | 282 if (!writer->WriteUInt32(*end_offset)) { |
| 283 DCHECK(false) << "Failed to write end offset."; | 283 DCHECK(false) << "Failed to write end offset."; |
| 284 return false; | 284 return false; |
| 285 } | 285 } |
| 286 return true; | 286 return true; |
| 287 } | 287 } |
| 288 | 288 |
| 289 } // namespace net | 289 } // namespace net |
| OLD | NEW |