get_emojis_fingerprint: simplified, uses bswap64 now

GitOrigin-RevId: a5ac0742dfa45fc9fb59e75d8cfd302fe666f483
This commit is contained in:
Arseny Smirnov 2020-02-25 12:47:31 +01:00
parent c407b244a0
commit 8e0baa9b16
2 changed files with 12 additions and 5 deletions

View File

@ -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<string> CallActor::get_emojis_fingerprint(const string &key, const string
vector<string> result;
result.reserve(4);
for (int i = 0; i < 4; i++) {
uint64 num =
(static_cast<uint64>(sha256_buf[8 * i + 0]) << 56) | (static_cast<uint64>(sha256_buf[8 * i + 1]) << 48) |
(static_cast<uint64>(sha256_buf[8 * i + 2]) << 40) | (static_cast<uint64>(sha256_buf[8 * i + 3]) << 32) |
(static_cast<uint64>(sha256_buf[8 * i + 4]) << 24) | (static_cast<uint64>(sha256_buf[8 * i + 5]) << 16) |
(static_cast<uint64>(sha256_buf[8 * i + 6]) << 8) | (static_cast<uint64>(sha256_buf[8 * i + 7]));
uint64 num = bswap64(as<td::uint64>(sha256_buf + 8 * i));
result.push_back(get_emoji_fingerprint(num));
}
return result;

View File

@ -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<td::uint64>(buf));
uint64 num =
(static_cast<uint64>(buf[0]) << 56) | (static_cast<uint64>(buf[1]) << 48) |
(static_cast<uint64>(buf[2]) << 40) | (static_cast<uint64>(buf[3]) << 32) |
(static_cast<uint64>(buf[4]) << 24) | (static_cast<uint64>(buf[5]) << 16) |
(static_cast<uint64>(buf[6]) << 8) | (static_cast<uint64>(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));