| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 } | 110 } |
| 111 | 111 |
| 112 uint64_t SimpleRandom::RandUint64() { | 112 uint64_t SimpleRandom::RandUint64() { |
| 113 unsigned char hash[base::kSHA1Length]; | 113 unsigned char hash[base::kSHA1Length]; |
| 114 base::SHA1HashBytes(reinterpret_cast<unsigned char*>(&seed_), sizeof(seed_), | 114 base::SHA1HashBytes(reinterpret_cast<unsigned char*>(&seed_), sizeof(seed_), |
| 115 hash); | 115 hash); |
| 116 memcpy(&seed_, hash, sizeof(seed_)); | 116 memcpy(&seed_, hash, sizeof(seed_)); |
| 117 return seed_; | 117 return seed_; |
| 118 } | 118 } |
| 119 | 119 |
| 120 void SimpleRandom::RandBytes(void* data, size_t len) { |
| 121 uint8_t* real_data = static_cast<uint8_t*>(data); |
| 122 for (size_t offset = 0; offset < len; offset++) { |
| 123 real_data[offset] = RandUint64() & 0xff; |
| 124 } |
| 125 } |
| 126 |
| 127 void SimpleRandom::Reseed(const void* additional_entropy, size_t len) { |
| 128 const uint8_t* real_entropy = static_cast<const uint8_t*>(additional_entropy); |
| 129 for (size_t offset = 0; offset < len; offset++) { |
| 130 // Note: this is not actually a well-established way to incorporate new |
| 131 // entropy, but good enough for tests. |
| 132 seed_ *= real_entropy[len]; |
| 133 } |
| 134 } |
| 135 |
| 120 MockFramerVisitor::MockFramerVisitor() { | 136 MockFramerVisitor::MockFramerVisitor() { |
| 121 // By default, we want to accept packets. | 137 // By default, we want to accept packets. |
| 122 ON_CALL(*this, OnProtocolVersionMismatch(_)) | 138 ON_CALL(*this, OnProtocolVersionMismatch(_)) |
| 123 .WillByDefault(testing::Return(false)); | 139 .WillByDefault(testing::Return(false)); |
| 124 | 140 |
| 125 // By default, we want to accept packets. | 141 // By default, we want to accept packets. |
| 126 ON_CALL(*this, OnUnauthenticatedHeader(_)) | 142 ON_CALL(*this, OnUnauthenticatedHeader(_)) |
| 127 .WillByDefault(testing::Return(true)); | 143 .WillByDefault(testing::Return(true)); |
| 128 | 144 |
| 129 ON_CALL(*this, OnUnauthenticatedPublicHeader(_)) | 145 ON_CALL(*this, OnUnauthenticatedPublicHeader(_)) |
| (...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 // strike register worries that we've just overflowed a uint32_t time. | 928 // strike register worries that we've just overflowed a uint32_t time. |
| 913 (*server_connection)->AdvanceTime(connection_start_time); | 929 (*server_connection)->AdvanceTime(connection_start_time); |
| 914 } | 930 } |
| 915 | 931 |
| 916 QuicStreamId QuicClientDataStreamId(int i) { | 932 QuicStreamId QuicClientDataStreamId(int i) { |
| 917 return kClientDataStreamId1 + 2 * i; | 933 return kClientDataStreamId1 + 2 * i; |
| 918 } | 934 } |
| 919 | 935 |
| 920 } // namespace test | 936 } // namespace test |
| 921 } // namespace net | 937 } // namespace net |
| OLD | NEW |