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

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

Issue 612323013: QUIC - (no behavior change) s/NULL/nullptr/g in .../quic/... (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « net/quic/crypto/crypto_framer.h ('k') | net/quic/crypto/crypto_framer_test.cc » ('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) 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 27 matching lines...) Expand all
38 CryptoHandshakeMessage* release() { return out_.release(); } 38 CryptoHandshakeMessage* release() { return out_.release(); }
39 39
40 private: 40 private:
41 scoped_ptr<CryptoHandshakeMessage> out_; 41 scoped_ptr<CryptoHandshakeMessage> out_;
42 bool error_; 42 bool error_;
43 }; 43 };
44 44
45 } // namespace 45 } // namespace
46 46
47 CryptoFramer::CryptoFramer() 47 CryptoFramer::CryptoFramer()
48 : visitor_(NULL), 48 : visitor_(nullptr),
49 num_entries_(0), 49 num_entries_(0),
50 values_len_(0) { 50 values_len_(0) {
51 Clear(); 51 Clear();
52 } 52 }
53 53
54 CryptoFramer::~CryptoFramer() {} 54 CryptoFramer::~CryptoFramer() {}
55 55
56 // static 56 // static
57 CryptoHandshakeMessage* CryptoFramer::ParseMessage(StringPiece in) { 57 CryptoHandshakeMessage* CryptoFramer::ParseMessage(StringPiece in) {
58 OneShotVisitor visitor; 58 OneShotVisitor visitor;
59 CryptoFramer framer; 59 CryptoFramer framer;
60 60
61 framer.set_visitor(&visitor); 61 framer.set_visitor(&visitor);
62 if (!framer.ProcessInput(in) || visitor.error() || 62 if (!framer.ProcessInput(in) || visitor.error() ||
63 framer.InputBytesRemaining()) { 63 framer.InputBytesRemaining()) {
64 return NULL; 64 return nullptr;
65 } 65 }
66 66
67 return visitor.release(); 67 return visitor.release();
68 } 68 }
69 69
70 bool CryptoFramer::ProcessInput(StringPiece input) { 70 bool CryptoFramer::ProcessInput(StringPiece input) {
71 DCHECK_EQ(QUIC_NO_ERROR, error_); 71 DCHECK_EQ(QUIC_NO_ERROR, error_);
72 if (error_ != QUIC_NO_ERROR) { 72 if (error_ != QUIC_NO_ERROR) {
73 return false; 73 return false;
74 } 74 }
(...skipping 22 matching lines...) Expand all
97 97
98 size_t delta = message.minimum_size() - len; 98 size_t delta = message.minimum_size() - len;
99 const size_t overhead = kQuicTagSize + kCryptoEndOffsetSize; 99 const size_t overhead = kQuicTagSize + kCryptoEndOffsetSize;
100 if (delta > overhead) { 100 if (delta > overhead) {
101 pad_length = delta - overhead; 101 pad_length = delta - overhead;
102 } 102 }
103 len += overhead + pad_length; 103 len += overhead + pad_length;
104 } 104 }
105 105
106 if (num_entries > kMaxEntries) { 106 if (num_entries > kMaxEntries) {
107 return NULL; 107 return nullptr;
108 } 108 }
109 109
110 110
111 QuicDataWriter writer(len); 111 QuicDataWriter writer(len);
112 if (!writer.WriteUInt32(message.tag())) { 112 if (!writer.WriteUInt32(message.tag())) {
113 DCHECK(false) << "Failed to write message tag."; 113 DCHECK(false) << "Failed to write message tag.";
114 return NULL; 114 return nullptr;
115 } 115 }
116 if (!writer.WriteUInt16(num_entries)) { 116 if (!writer.WriteUInt16(num_entries)) {
117 DCHECK(false) << "Failed to write size."; 117 DCHECK(false) << "Failed to write size.";
118 return NULL; 118 return nullptr;
119 } 119 }
120 if (!writer.WriteUInt16(0)) { 120 if (!writer.WriteUInt16(0)) {
121 DCHECK(false) << "Failed to write padding."; 121 DCHECK(false) << "Failed to write padding.";
122 return NULL; 122 return nullptr;
123 } 123 }
124 124
125 uint32 end_offset = 0; 125 uint32 end_offset = 0;
126 // Tags and offsets 126 // Tags and offsets
127 for (QuicTagValueMap::const_iterator it = message.tag_value_map().begin(); 127 for (QuicTagValueMap::const_iterator it = message.tag_value_map().begin();
128 it != message.tag_value_map().end(); ++it) { 128 it != message.tag_value_map().end(); ++it) {
129 if (it->first == kPAD && need_pad_tag) { 129 if (it->first == kPAD && need_pad_tag) {
130 // Existing PAD tags are only checked when padding needs to be added 130 // Existing PAD tags are only checked when padding needs to be added
131 // because parts of the code may need to reserialize received messages 131 // because parts of the code may need to reserialize received messages
132 // and those messages may, legitimately include padding. 132 // and those messages may, legitimately include padding.
133 DCHECK(false) << "Message needed padding but already contained a PAD tag"; 133 DCHECK(false) << "Message needed padding but already contained a PAD tag";
134 return NULL; 134 return nullptr;
135 } 135 }
136 136
137 if (it->first > kPAD && need_pad_tag) { 137 if (it->first > kPAD && need_pad_tag) {
138 need_pad_tag = false; 138 need_pad_tag = false;
139 if (!WritePadTag(&writer, pad_length, &end_offset)) { 139 if (!WritePadTag(&writer, pad_length, &end_offset)) {
140 return NULL; 140 return nullptr;
141 } 141 }
142 } 142 }
143 143
144 if (!writer.WriteUInt32(it->first)) { 144 if (!writer.WriteUInt32(it->first)) {
145 DCHECK(false) << "Failed to write tag."; 145 DCHECK(false) << "Failed to write tag.";
146 return NULL; 146 return nullptr;
147 } 147 }
148 end_offset += it->second.length(); 148 end_offset += it->second.length();
149 if (!writer.WriteUInt32(end_offset)) { 149 if (!writer.WriteUInt32(end_offset)) {
150 DCHECK(false) << "Failed to write end offset."; 150 DCHECK(false) << "Failed to write end offset.";
151 return NULL; 151 return nullptr;
152 } 152 }
153 } 153 }
154 154
155 if (need_pad_tag) { 155 if (need_pad_tag) {
156 if (!WritePadTag(&writer, pad_length, &end_offset)) { 156 if (!WritePadTag(&writer, pad_length, &end_offset)) {
157 return NULL; 157 return nullptr;
158 } 158 }
159 } 159 }
160 160
161 // Values 161 // Values
162 for (QuicTagValueMap::const_iterator it = message.tag_value_map().begin(); 162 for (QuicTagValueMap::const_iterator it = message.tag_value_map().begin();
163 it != message.tag_value_map().end(); ++it) { 163 it != message.tag_value_map().end(); ++it) {
164 if (it->first > kPAD && need_pad_value) { 164 if (it->first > kPAD && need_pad_value) {
165 need_pad_value = false; 165 need_pad_value = false;
166 if (!writer.WriteRepeatedByte('-', pad_length)) { 166 if (!writer.WriteRepeatedByte('-', pad_length)) {
167 DCHECK(false) << "Failed to write padding."; 167 DCHECK(false) << "Failed to write padding.";
168 return NULL; 168 return nullptr;
169 } 169 }
170 } 170 }
171 171
172 if (!writer.WriteBytes(it->second.data(), it->second.length())) { 172 if (!writer.WriteBytes(it->second.data(), it->second.length())) {
173 DCHECK(false) << "Failed to write value."; 173 DCHECK(false) << "Failed to write value.";
174 return NULL; 174 return nullptr;
175 } 175 }
176 } 176 }
177 177
178 if (need_pad_value) { 178 if (need_pad_value) {
179 if (!writer.WriteRepeatedByte('-', pad_length)) { 179 if (!writer.WriteRepeatedByte('-', pad_length)) {
180 DCHECK(false) << "Failed to write padding."; 180 DCHECK(false) << "Failed to write padding.";
181 return NULL; 181 return nullptr;
182 } 182 }
183 } 183 }
184 184
185 return new QuicData(writer.take(), len, true); 185 return new QuicData(writer.take(), len, true);
186 } 186 }
187 187
188 void CryptoFramer::Clear() { 188 void CryptoFramer::Clear() {
189 message_.Clear(); 189 message_.Clear();
190 tags_and_lengths_.clear(); 190 tags_and_lengths_.clear();
191 error_ = QUIC_NO_ERROR; 191 error_ = QUIC_NO_ERROR;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 } 281 }
282 *end_offset += pad_length; 282 *end_offset += pad_length;
283 if (!writer->WriteUInt32(*end_offset)) { 283 if (!writer->WriteUInt32(*end_offset)) {
284 DCHECK(false) << "Failed to write end offset."; 284 DCHECK(false) << "Failed to write end offset.";
285 return false; 285 return false;
286 } 286 }
287 return true; 287 return true;
288 } 288 }
289 289
290 } // namespace net 290 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/crypto/crypto_framer.h ('k') | net/quic/crypto/crypto_framer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698