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

Side by Side Diff: webrtc/p2p/base/dtlstransportchannel_unittest.cc

Issue 1362503003: Use suffixed {uint,int}{8,16,32,64}_t types. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: google::int32 Created 5 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
OLDNEW
1 /* 1 /*
2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 17 matching lines...) Expand all
28 LOG(LS_INFO) << "Feature disabled... skipping"; \ 28 LOG(LS_INFO) << "Feature disabled... skipping"; \
29 return; \ 29 return; \
30 } 30 }
31 31
32 static const char AES_CM_128_HMAC_SHA1_80[] = "AES_CM_128_HMAC_SHA1_80"; 32 static const char AES_CM_128_HMAC_SHA1_80[] = "AES_CM_128_HMAC_SHA1_80";
33 static const char kIceUfrag1[] = "TESTICEUFRAG0001"; 33 static const char kIceUfrag1[] = "TESTICEUFRAG0001";
34 static const char kIcePwd1[] = "TESTICEPWD00000000000001"; 34 static const char kIcePwd1[] = "TESTICEPWD00000000000001";
35 static const size_t kPacketNumOffset = 8; 35 static const size_t kPacketNumOffset = 8;
36 static const size_t kPacketHeaderLen = 12; 36 static const size_t kPacketHeaderLen = 12;
37 37
38 static bool IsRtpLeadByte(uint8 b) { 38 static bool IsRtpLeadByte(uint8_t b) {
39 return ((b & 0xC0) == 0x80); 39 return ((b & 0xC0) == 0x80);
40 } 40 }
41 41
42 using cricket::ConnectionRole; 42 using cricket::ConnectionRole;
43 43
44 enum Flags { NF_REOFFER = 0x1, NF_EXPECT_FAILURE = 0x2 }; 44 enum Flags { NF_REOFFER = 0x1, NF_EXPECT_FAILURE = 0x2 };
45 45
46 class DtlsTestClient : public sigslot::has_slots<> { 46 class DtlsTestClient : public sigslot::has_slots<> {
47 public: 47 public:
48 DtlsTestClient(const std::string& name, 48 DtlsTestClient(const std::string& name,
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 void SendPackets(size_t channel, size_t size, size_t count, bool srtp) { 246 void SendPackets(size_t channel, size_t size, size_t count, bool srtp) {
247 ASSERT(channel < channels_.size()); 247 ASSERT(channel < channels_.size());
248 rtc::scoped_ptr<char[]> packet(new char[size]); 248 rtc::scoped_ptr<char[]> packet(new char[size]);
249 size_t sent = 0; 249 size_t sent = 0;
250 do { 250 do {
251 // Fill the packet with a known value and a sequence number to check 251 // Fill the packet with a known value and a sequence number to check
252 // against, and make sure that it doesn't look like DTLS. 252 // against, and make sure that it doesn't look like DTLS.
253 memset(packet.get(), sent & 0xff, size); 253 memset(packet.get(), sent & 0xff, size);
254 packet[0] = (srtp) ? 0x80 : 0x00; 254 packet[0] = (srtp) ? 0x80 : 0x00;
255 rtc::SetBE32(packet.get() + kPacketNumOffset, 255 rtc::SetBE32(packet.get() + kPacketNumOffset,
256 static_cast<uint32>(sent)); 256 static_cast<uint32_t>(sent));
257 257
258 // Only set the bypass flag if we've activated DTLS. 258 // Only set the bypass flag if we've activated DTLS.
259 int flags = (certificate_ && srtp) ? cricket::PF_SRTP_BYPASS : 0; 259 int flags = (certificate_ && srtp) ? cricket::PF_SRTP_BYPASS : 0;
260 rtc::PacketOptions packet_options; 260 rtc::PacketOptions packet_options;
261 int rv = channels_[channel]->SendPacket( 261 int rv = channels_[channel]->SendPacket(
262 packet.get(), size, packet_options, flags); 262 packet.get(), size, packet_options, flags);
263 ASSERT_GT(rv, 0); 263 ASSERT_GT(rv, 0);
264 ASSERT_EQ(size, static_cast<size_t>(rv)); 264 ASSERT_EQ(size, static_cast<size_t>(rv));
265 ++sent; 265 ++sent;
266 } while (sent < count); 266 } while (sent < count);
(...skipping 12 matching lines...) Expand all
279 279
280 void ExpectPackets(size_t channel, size_t size) { 280 void ExpectPackets(size_t channel, size_t size) {
281 packet_size_ = size; 281 packet_size_ = size;
282 received_.clear(); 282 received_.clear();
283 } 283 }
284 284
285 size_t NumPacketsReceived() { 285 size_t NumPacketsReceived() {
286 return received_.size(); 286 return received_.size();
287 } 287 }
288 288
289 bool VerifyPacket(const char* data, size_t size, uint32* out_num) { 289 bool VerifyPacket(const char* data, size_t size, uint32_t* out_num) {
290 if (size != packet_size_ || 290 if (size != packet_size_ ||
291 (data[0] != 0 && static_cast<uint8>(data[0]) != 0x80)) { 291 (data[0] != 0 && static_cast<uint8_t>(data[0]) != 0x80)) {
292 return false; 292 return false;
293 } 293 }
294 uint32 packet_num = rtc::GetBE32(data + kPacketNumOffset); 294 uint32_t packet_num = rtc::GetBE32(data + kPacketNumOffset);
295 for (size_t i = kPacketHeaderLen; i < size; ++i) { 295 for (size_t i = kPacketHeaderLen; i < size; ++i) {
296 if (static_cast<uint8>(data[i]) != (packet_num & 0xff)) { 296 if (static_cast<uint8_t>(data[i]) != (packet_num & 0xff)) {
297 return false; 297 return false;
298 } 298 }
299 } 299 }
300 if (out_num) { 300 if (out_num) {
301 *out_num = packet_num; 301 *out_num = packet_num;
302 } 302 }
303 return true; 303 return true;
304 } 304 }
305 bool VerifyEncryptedPacket(const char* data, size_t size) { 305 bool VerifyEncryptedPacket(const char* data, size_t size) {
306 // This is an encrypted data packet; let's make sure it's mostly random; 306 // This is an encrypted data packet; let's make sure it's mostly random;
307 // less than 10% of the bytes should be equal to the cleartext packet. 307 // less than 10% of the bytes should be equal to the cleartext packet.
308 if (size <= packet_size_) { 308 if (size <= packet_size_) {
309 return false; 309 return false;
310 } 310 }
311 uint32 packet_num = rtc::GetBE32(data + kPacketNumOffset); 311 uint32_t packet_num = rtc::GetBE32(data + kPacketNumOffset);
312 int num_matches = 0; 312 int num_matches = 0;
313 for (size_t i = kPacketNumOffset; i < size; ++i) { 313 for (size_t i = kPacketNumOffset; i < size; ++i) {
314 if (static_cast<uint8>(data[i]) == (packet_num & 0xff)) { 314 if (static_cast<uint8_t>(data[i]) == (packet_num & 0xff)) {
315 ++num_matches; 315 ++num_matches;
316 } 316 }
317 } 317 }
318 return (num_matches < ((static_cast<int>(size) - 5) / 10)); 318 return (num_matches < ((static_cast<int>(size) - 5) / 10));
319 } 319 }
320 320
321 // Transport callbacks 321 // Transport callbacks
322 void OnTransportWritableState(cricket::Transport* transport) { 322 void OnTransportWritableState(cricket::Transport* transport) {
323 LOG(LS_INFO) << name_ << ": is writable"; 323 LOG(LS_INFO) << name_ << ": is writable";
324 } 324 }
325 325
326 // Transport channel callbacks 326 // Transport channel callbacks
327 void OnTransportChannelWritableState(cricket::TransportChannel* channel) { 327 void OnTransportChannelWritableState(cricket::TransportChannel* channel) {
328 LOG(LS_INFO) << name_ << ": Channel '" << channel->component() 328 LOG(LS_INFO) << name_ << ": Channel '" << channel->component()
329 << "' is writable"; 329 << "' is writable";
330 } 330 }
331 331
332 void OnTransportChannelReadPacket(cricket::TransportChannel* channel, 332 void OnTransportChannelReadPacket(cricket::TransportChannel* channel,
333 const char* data, size_t size, 333 const char* data, size_t size,
334 const rtc::PacketTime& packet_time, 334 const rtc::PacketTime& packet_time,
335 int flags) { 335 int flags) {
336 uint32 packet_num = 0; 336 uint32_t packet_num = 0;
337 ASSERT_TRUE(VerifyPacket(data, size, &packet_num)); 337 ASSERT_TRUE(VerifyPacket(data, size, &packet_num));
338 received_.insert(packet_num); 338 received_.insert(packet_num);
339 // Only DTLS-SRTP packets should have the bypass flag set. 339 // Only DTLS-SRTP packets should have the bypass flag set.
340 int expected_flags = (certificate_ && IsRtpLeadByte(data[0])) ? 340 int expected_flags = (certificate_ && IsRtpLeadByte(data[0])) ?
341 cricket::PF_SRTP_BYPASS : 0; 341 cricket::PF_SRTP_BYPASS : 0;
342 ASSERT_EQ(expected_flags, flags); 342 ASSERT_EQ(expected_flags, flags);
343 } 343 }
344 344
345 // Hook into the raw packet stream to make sure DTLS packets are encrypted. 345 // Hook into the raw packet stream to make sure DTLS packets are encrypted.
346 void OnFakeTransportChannelReadPacket(cricket::TransportChannel* channel, 346 void OnFakeTransportChannelReadPacket(cricket::TransportChannel* channel,
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 // Each side's remote certificate is the other side's local certificate. 869 // Each side's remote certificate is the other side's local certificate.
870 ASSERT_TRUE( 870 ASSERT_TRUE(
871 client1_.transport()->GetRemoteSSLCertificate(remote_cert1.accept())); 871 client1_.transport()->GetRemoteSSLCertificate(remote_cert1.accept()));
872 ASSERT_EQ(remote_cert1->ToPEMString(), 872 ASSERT_EQ(remote_cert1->ToPEMString(),
873 certificate2->ssl_certificate().ToPEMString()); 873 certificate2->ssl_certificate().ToPEMString());
874 ASSERT_TRUE( 874 ASSERT_TRUE(
875 client2_.transport()->GetRemoteSSLCertificate(remote_cert2.accept())); 875 client2_.transport()->GetRemoteSSLCertificate(remote_cert2.accept()));
876 ASSERT_EQ(remote_cert2->ToPEMString(), 876 ASSERT_EQ(remote_cert2->ToPEMString(),
877 certificate1->ssl_certificate().ToPEMString()); 877 certificate1->ssl_certificate().ToPEMString());
878 } 878 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698