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/test_tools/quic_test_utils.h" | 5 #include "net/quic/test_tools/quic_test_utils.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/sha1.h" | 9 #include "base/sha1.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 const QuicFrames& frames, | 75 const QuicFrames& frames, |
76 size_t packet_size) { | 76 size_t packet_size) { |
77 char* buffer = new char[packet_size]; | 77 char* buffer = new char[packet_size]; |
78 size_t length = framer->BuildDataPacket(header, frames, buffer, packet_size); | 78 size_t length = framer->BuildDataPacket(header, frames, buffer, packet_size); |
79 DCHECK_NE(0u, length); | 79 DCHECK_NE(0u, length); |
80 // Re-construct the data packet with data ownership. | 80 // Re-construct the data packet with data ownership. |
81 return new QuicPacket(buffer, length, /* owns_buffer */ true, | 81 return new QuicPacket(buffer, length, /* owns_buffer */ true, |
82 header.public_header.connection_id_length, | 82 header.public_header.connection_id_length, |
83 header.public_header.version_flag, | 83 header.public_header.version_flag, |
84 header.public_header.multipath_flag, | 84 header.public_header.multipath_flag, |
| 85 header.public_header.nonce != nullptr, |
85 header.public_header.packet_number_length); | 86 header.public_header.packet_number_length); |
86 } | 87 } |
87 | 88 |
88 uint64_t SimpleRandom::RandUint64() { | 89 uint64_t SimpleRandom::RandUint64() { |
89 unsigned char hash[base::kSHA1Length]; | 90 unsigned char hash[base::kSHA1Length]; |
90 base::SHA1HashBytes(reinterpret_cast<unsigned char*>(&seed_), sizeof(seed_), | 91 base::SHA1HashBytes(reinterpret_cast<unsigned char*>(&seed_), sizeof(seed_), |
91 hash); | 92 hash); |
92 memcpy(&seed_, hash, sizeof(seed_)); | 93 memcpy(&seed_, hash, sizeof(seed_)); |
93 return seed_; | 94 return seed_; |
94 } | 95 } |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 QuicTime::Zero(), Perspective::IS_CLIENT); | 602 QuicTime::Zero(), Perspective::IS_CLIENT); |
602 | 603 |
603 std::unique_ptr<QuicPacket> packet( | 604 std::unique_ptr<QuicPacket> packet( |
604 BuildUnsizedDataPacket(&framer, header, frames)); | 605 BuildUnsizedDataPacket(&framer, header, frames)); |
605 EXPECT_TRUE(packet != nullptr); | 606 EXPECT_TRUE(packet != nullptr); |
606 | 607 |
607 // Now set the packet's private flags byte to 0xFF, which is an invalid value. | 608 // Now set the packet's private flags byte to 0xFF, which is an invalid value. |
608 reinterpret_cast<unsigned char*>( | 609 reinterpret_cast<unsigned char*>( |
609 packet->mutable_data())[GetStartOfEncryptedData( | 610 packet->mutable_data())[GetStartOfEncryptedData( |
610 connection_id_length, version_flag, multipath_flag, | 611 connection_id_length, version_flag, multipath_flag, |
611 packet_number_length)] = 0xFF; | 612 false /* no diversification nonce */, packet_number_length)] = 0xFF; |
612 | 613 |
613 char* buffer = new char[kMaxPacketSize]; | 614 char* buffer = new char[kMaxPacketSize]; |
614 size_t encrypted_length = framer.EncryptPayload( | 615 size_t encrypted_length = framer.EncryptPayload( |
615 ENCRYPTION_NONE, path_id, packet_number, *packet, buffer, kMaxPacketSize); | 616 ENCRYPTION_NONE, path_id, packet_number, *packet, buffer, kMaxPacketSize); |
616 EXPECT_NE(0u, encrypted_length); | 617 EXPECT_NE(0u, encrypted_length); |
617 return new QuicEncryptedPacket(buffer, encrypted_length, true); | 618 return new QuicEncryptedPacket(buffer, encrypted_length, true); |
618 } | 619 } |
619 | 620 |
620 void CompareCharArraysWithHexError(const string& description, | 621 void CompareCharArraysWithHexError(const string& description, |
621 const char* actual, | 622 const char* actual, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 QuicPacket* ConstructHandshakePacket(QuicConnectionId connection_id, | 693 QuicPacket* ConstructHandshakePacket(QuicConnectionId connection_id, |
693 QuicTag tag) { | 694 QuicTag tag) { |
694 CryptoHandshakeMessage message; | 695 CryptoHandshakeMessage message; |
695 message.set_tag(tag); | 696 message.set_tag(tag); |
696 return ConstructPacketFromHandshakeMessage(connection_id, message, false); | 697 return ConstructPacketFromHandshakeMessage(connection_id, message, false); |
697 } | 698 } |
698 | 699 |
699 size_t GetPacketLengthForOneStream(QuicVersion version, | 700 size_t GetPacketLengthForOneStream(QuicVersion version, |
700 bool include_version, | 701 bool include_version, |
701 bool include_path_id, | 702 bool include_path_id, |
| 703 bool include_diversification_nonce, |
702 QuicConnectionIdLength connection_id_length, | 704 QuicConnectionIdLength connection_id_length, |
703 QuicPacketNumberLength packet_number_length, | 705 QuicPacketNumberLength packet_number_length, |
704 size_t* payload_length) { | 706 size_t* payload_length) { |
705 *payload_length = 1; | 707 *payload_length = 1; |
706 const size_t stream_length = | 708 const size_t stream_length = |
707 NullEncrypter().GetCiphertextSize(*payload_length) + | 709 NullEncrypter().GetCiphertextSize(*payload_length) + |
708 QuicPacketCreator::StreamFramePacketOverhead( | 710 QuicPacketCreator::StreamFramePacketOverhead( |
709 PACKET_8BYTE_CONNECTION_ID, include_version, include_path_id, | 711 PACKET_8BYTE_CONNECTION_ID, include_version, include_path_id, |
710 packet_number_length, 0u); | 712 include_diversification_nonce, packet_number_length, 0u); |
711 const size_t ack_length = | 713 const size_t ack_length = |
712 NullEncrypter().GetCiphertextSize( | 714 NullEncrypter().GetCiphertextSize( |
713 QuicFramer::GetMinAckFrameSize(PACKET_1BYTE_PACKET_NUMBER)) + | 715 QuicFramer::GetMinAckFrameSize(PACKET_1BYTE_PACKET_NUMBER)) + |
714 GetPacketHeaderSize(connection_id_length, include_version, | 716 GetPacketHeaderSize(connection_id_length, include_version, |
715 include_path_id, packet_number_length); | 717 include_path_id, include_diversification_nonce, |
| 718 packet_number_length); |
716 if (stream_length < ack_length) { | 719 if (stream_length < ack_length) { |
717 *payload_length = 1 + ack_length - stream_length; | 720 *payload_length = 1 + ack_length - stream_length; |
718 } | 721 } |
719 | 722 |
720 return NullEncrypter().GetCiphertextSize(*payload_length) + | 723 return NullEncrypter().GetCiphertextSize(*payload_length) + |
721 QuicPacketCreator::StreamFramePacketOverhead( | 724 QuicPacketCreator::StreamFramePacketOverhead( |
722 connection_id_length, include_version, include_path_id, | 725 connection_id_length, include_version, include_path_id, |
723 packet_number_length, 0u); | 726 include_diversification_nonce, packet_number_length, 0u); |
724 } | 727 } |
725 | 728 |
726 TestEntropyCalculator::TestEntropyCalculator() {} | 729 TestEntropyCalculator::TestEntropyCalculator() {} |
727 | 730 |
728 TestEntropyCalculator::~TestEntropyCalculator() {} | 731 TestEntropyCalculator::~TestEntropyCalculator() {} |
729 | 732 |
730 QuicPacketEntropyHash TestEntropyCalculator::EntropyHash( | 733 QuicPacketEntropyHash TestEntropyCalculator::EntropyHash( |
731 QuicPacketNumber packet_number) const { | 734 QuicPacketNumber packet_number) const { |
732 return 1u; | 735 return 1u; |
733 } | 736 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 // strike register worries that we've just overflowed a uint32_t time. | 824 // strike register worries that we've just overflowed a uint32_t time. |
822 (*server_connection)->AdvanceTime(connection_start_time); | 825 (*server_connection)->AdvanceTime(connection_start_time); |
823 } | 826 } |
824 | 827 |
825 QuicStreamId QuicClientDataStreamId(int i) { | 828 QuicStreamId QuicClientDataStreamId(int i) { |
826 return kClientDataStreamId1 + 2 * i; | 829 return kClientDataStreamId1 + 2 * i; |
827 } | 830 } |
828 | 831 |
829 } // namespace test | 832 } // namespace test |
830 } // namespace net | 833 } // namespace net |
OLD | NEW |