Reduce transaction ids independent of host byte order.
Bug: webrtc:9972 Change-Id: I91df2f2c4854bec6d581c3beb9f57235a1ce47b1 Reviewed-on: https://webrtc-review.googlesource.com/c/112926 Reviewed-by: Qingsi Wang <qingsi@webrtc.org> Reviewed-by: Björn Terelius <terelius@webrtc.org> Commit-Queue: Zach Stein <zstein@webrtc.org> Cr-Commit-Position: refs/heads/master@{#25939}
This commit is contained in:
parent
168456c128
commit
ff71a49b30
@ -32,13 +32,12 @@ uint32_t ReduceTransactionId(const std::string& transaction_id) {
|
||||
RTC_DCHECK(transaction_id.length() == cricket::kStunTransactionIdLength ||
|
||||
transaction_id.length() ==
|
||||
cricket::kStunLegacyTransactionIdLength);
|
||||
uint32_t transaction_id_as_ints[4];
|
||||
memcpy(transaction_id_as_ints, transaction_id.c_str(),
|
||||
transaction_id.length());
|
||||
|
||||
ByteBufferReader reader(transaction_id.c_str(), transaction_id.length(),
|
||||
rtc::ByteBuffer::ORDER_NETWORK);
|
||||
uint32_t result = 0;
|
||||
for (size_t i = 0; i < transaction_id.length() / 4; ++i) {
|
||||
result ^= transaction_id_as_ints[i];
|
||||
uint32_t next;
|
||||
while (reader.ReadUInt32(&next)) {
|
||||
result ^= next;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -1561,4 +1561,12 @@ TEST_F(StunTest, CopyAttribute) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(StunTest, ReduceTransactionIdIsHostOrderIndependent) {
|
||||
std::string transaction_id = "abcdefghijkl";
|
||||
StunMessage message;
|
||||
ASSERT_TRUE(message.SetTransactionID(transaction_id));
|
||||
uint32_t reduced_transaction_id = message.reduced_transaction_id();
|
||||
EXPECT_EQ(reduced_transaction_id, 1835954016u);
|
||||
}
|
||||
|
||||
} // namespace cricket
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user