From 8e0baa9b16da8cec091557234175cf19e52f3ec9 Mon Sep 17 00:00:00 2001 From: Arseny Smirnov Date: Tue, 25 Feb 2020 12:47:31 +0100 Subject: [PATCH] get_emojis_fingerprint: simplified, uses bswap64 now GitOrigin-RevId: a5ac0742dfa45fc9fb59e75d8cfd302fe666f483 --- td/telegram/CallActor.cpp | 8 +++----- tdutils/test/misc.cpp | 9 +++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/td/telegram/CallActor.cpp b/td/telegram/CallActor.cpp index 3ef23874f..58fbc1e52 100644 --- a/td/telegram/CallActor.cpp +++ b/td/telegram/CallActor.cpp @@ -22,6 +22,8 @@ #include "td/telegram/Td.h" #include "td/telegram/UpdatesManager.h" +#include "td/utils/as.h" +#include "td/utils/bits.h" #include "td/utils/buffer.h" #include "td/utils/common.h" #include "td/utils/crypto.h" @@ -779,11 +781,7 @@ vector CallActor::get_emojis_fingerprint(const string &key, const string vector result; result.reserve(4); for (int i = 0; i < 4; i++) { - uint64 num = - (static_cast(sha256_buf[8 * i + 0]) << 56) | (static_cast(sha256_buf[8 * i + 1]) << 48) | - (static_cast(sha256_buf[8 * i + 2]) << 40) | (static_cast(sha256_buf[8 * i + 3]) << 32) | - (static_cast(sha256_buf[8 * i + 4]) << 24) | (static_cast(sha256_buf[8 * i + 5]) << 16) | - (static_cast(sha256_buf[8 * i + 6]) << 8) | (static_cast(sha256_buf[8 * i + 7])); + uint64 num = bswap64(as(sha256_buf + 8 * i)); result.push_back(get_emoji_fingerprint(num)); } return result; diff --git a/tdutils/test/misc.cpp b/tdutils/test/misc.cpp index c288b15a6..9c44678a9 100644 --- a/tdutils/test/misc.cpp +++ b/tdutils/test/misc.cpp @@ -829,6 +829,15 @@ TEST(Misc, Bits) { ASSERT_EQ(0x12345678u, td::bswap32(0x78563412u)); ASSERT_EQ(0x12345678abcdef67ull, td::bswap64(0x67efcdab78563412ull)); + uint8 buf[8] = {1, 90, 2, 18, 129, 255, 0, 2}; + uint64 num2 = bswap64(as(buf)); + uint64 num = + (static_cast(buf[0]) << 56) | (static_cast(buf[1]) << 48) | + (static_cast(buf[2]) << 40) | (static_cast(buf[3]) << 32) | + (static_cast(buf[4]) << 24) | (static_cast(buf[5]) << 16) | + (static_cast(buf[6]) << 8) | (static_cast(buf[7])); + ASSERT_EQ(num, num2); + ASSERT_EQ(0, count_bits32(0)); ASSERT_EQ(0, count_bits64(0)); ASSERT_EQ(4, count_bits32((1u << 31) | 7));