Fixes for updated tdutils

GitOrigin-RevId: 44ef7ad802652dba0f7e90f59fa2b81e72641db1
This commit is contained in:
Arseny Smirnov 2018-12-19 17:49:13 +03:00
parent d34831c613
commit e0b9cf2586
10 changed files with 21 additions and 141 deletions

View File

@ -168,7 +168,7 @@ void ObfuscatedTransport::init(ChainBufferReader *input, ChainBufferWriter *outp
string rheader = header;
std::reverse(rheader.begin(), rheader.end());
auto key = as<UInt256>(rheader.data() + 8);
UInt256 key = as<UInt256>(rheader.data() + 8);
if (secret_.size() == 17) {
secret_ = secret_.substr(1);
}

View File

@ -19,7 +19,6 @@
namespace td {
namespace mtproto {
// mtproto v1.0
template <class HeaderT>
std::tuple<uint32, UInt128> Transport::calc_message_ack_and_key(const HeaderT &head, size_t data_size) {
@ -80,10 +79,9 @@ Status Transport::read_no_crypto(MutableSlice message, PacketInfo *info, Mutable
return Status::Error(PSLICE() << "Invalid mtproto message: too small [message.size()=" << message.size()
<< "] < [sizeof(NoCryptoHeader) = " << sizeof(NoCryptoHeader) << "]");
}
auto &header = as<NoCryptoHeader>(message.begin());
size_t data_size = message.size() - sizeof(NoCryptoHeader);
CHECK(message.size() == calc_no_crypto_size(data_size));
*data = MutableSlice(header.data, data_size);
*data = MutableSlice(message.begin() + sizeof(NoCryptoHeader), data_size);
return Status::OK();
}
@ -94,7 +92,8 @@ Status Transport::read_crypto_impl(int X, MutableSlice message, const AuthKey &a
return Status::Error(PSLICE() << "Invalid mtproto message: too small [message.size()=" << message.size()
<< "] < [sizeof(HeaderT) = " << sizeof(HeaderT) << "]");
}
auto *header = &as<HeaderT>(message.begin());
//FIXME: rewrite without reinterpret cast
auto *header = reinterpret_cast<HeaderT *>(message.begin());
*header_ptr = header;
auto to_decrypt = MutableSlice(header->encrypt_begin(), message.uend());
to_decrypt = to_decrypt.truncate(to_decrypt.size() & ~15);
@ -123,7 +122,8 @@ Status Transport::read_crypto_impl(int X, MutableSlice message, const AuthKey &a
if (tail_size < sizeof(PrefixT)) {
return Status::Error("Too small encrypted part");
}
auto *prefix = &as<PrefixT>(header->data);
//FIXME: rewrite without reinterpret cast
auto *prefix = reinterpret_cast<PrefixT *>(header->data);
*prefix_ptr = prefix;
size_t data_size = prefix->message_data_length + sizeof(PrefixT);
bool is_length_ok = prefix->message_data_length % 4 == 0;
@ -191,9 +191,9 @@ size_t Transport::write_no_crypto(const Storer &storer, PacketInfo *info, Mutabl
if (size > dest.size()) {
return size;
}
auto &header = as<NoCryptoHeader>(dest.begin());
header.auth_key_id = 0;
auto real_size = storer.store(header.data);
// NoCryptoHeader
as<uint64>(dest.begin()) = uint64(0);
auto real_size = storer.store(dest.ubegin() + sizeof(uint64));
CHECK(real_size == storer.size());
return size;
}
@ -249,7 +249,8 @@ size_t Transport::write_crypto(const Storer &storer, const AuthKey &auth_key, Pa
return size;
}
auto &header = as<CryptoHeader>(dest.begin());
//FIXME: rewrite without reinterpret cast
auto &header = *reinterpret_cast<CryptoHeader *>(dest.begin());
header.auth_key_id = auth_key.id();
header.salt = info->salt;
header.session_id = info->session_id;
@ -271,7 +272,8 @@ size_t Transport::write_e2e_crypto(const Storer &storer, const AuthKey &auth_key
return size;
}
auto &header = as<EndToEndHeader>(dest.begin());
//FIXME: rewrite without reinterpret cast
auto &header = *reinterpret_cast<EndToEndHeader *>(dest.begin());
header.auth_key_id = auth_key.id();
write_crypto_impl(info->is_creator || info->version == 1 ? 0 : 8, storer, auth_key, info, &header, data_size);

View File

@ -312,7 +312,7 @@ Result<size_t> FileDownloader::process_part(Part part, NetQueryPtr net_query) {
// Encryption
if (need_cdn_decrypt) {
auto iv = as<UInt128>(cdn_encryption_iv_.c_str());
UInt128 iv = as<UInt128>(cdn_encryption_iv_.c_str());
CHECK(part.offset % 16 == 0);
auto offset = narrow_cast<uint32>(part.offset / 16);
offset =

View File

@ -9,11 +9,6 @@ set(TD_TEST_SOURCE
${CMAKE_CURRENT_SOURCE_DIR}/secret.cpp
${CMAKE_CURRENT_SOURCE_DIR}/secure_storage.cpp
${CMAKE_CURRENT_SOURCE_DIR}/string_cleaning.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TestsRunner.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tests_runner.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TestsRunner.h
${CMAKE_CURRENT_SOURCE_DIR}/tests_runner.h
${CMAKE_CURRENT_SOURCE_DIR}/data.cpp
${CMAKE_CURRENT_SOURCE_DIR}/data.h

View File

@ -1,63 +0,0 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include "test/TestsRunner.h"
#include "td/utils/common.h"
#include "td/utils/FileLog.h"
#include "td/utils/format.h"
#include "td/utils/logging.h"
#include "td/utils/port/path.h"
#include "td/utils/tests.h"
#include <limits>
DESC_TESTS(string_cleaning);
DESC_TESTS(message_entities);
DESC_TESTS(variant);
DESC_TESTS(secret);
DESC_TESTS(actors_main);
DESC_TESTS(actors_simple);
DESC_TESTS(actors_workers);
DESC_TESTS(db);
DESC_TESTS(json);
DESC_TESTS(http);
DESC_TESTS(heap);
DESC_TESTS(pq);
DESC_TESTS(mtproto);
namespace td {
void TestsRunner::run_all_tests() {
LOAD_TESTS(string_cleaning);
LOAD_TESTS(message_entities);
LOAD_TESTS(variant);
LOAD_TESTS(secret);
LOAD_TESTS(actors_main);
LOAD_TESTS(actors_simple);
LOAD_TESTS(actors_workers);
LOAD_TESTS(db);
LOAD_TESTS(json);
LOAD_TESTS(http);
LOAD_TESTS(heap);
LOAD_TESTS(pq);
LOAD_TESTS(mtproto);
Test::run_all();
}
static FileLog file_log;
static TsLog ts_log(&file_log);
void TestsRunner::init(string dir) {
SET_VERBOSITY_LEVEL(VERBOSITY_NAME(ERROR));
chdir(dir).ensure();
LOG(WARNING) << "Redirect log into " << tag("file", dir + TD_DIR_SLASH + "log.txt");
if (file_log.init("log.txt", std::numeric_limits<int64>::max()).is_ok()) {
log_interface = &ts_log;
}
}
} // namespace td

View File

@ -1,19 +0,0 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once
#include "td/utils/common.h"
namespace td {
class TestsRunner {
public:
static void init(string dir);
static void run_all_tests();
};
} // namespace td

View File

@ -16,26 +16,27 @@
int main(int argc, char **argv) {
// TODO port OptionsParser to Windows
td::TestsRunner &runner = td::TestsRunner::get_default();
SET_VERBOSITY_LEVEL(VERBOSITY_NAME(ERROR));
for (int i = 1; i < argc; i++) {
if (!std::strcmp(argv[i], "--filter")) {
CHECK(i + 1 < argc);
td::Test::add_substr_filter(argv[++i]);
runner.add_substr_filter(argv[++i]);
}
if (!std::strcmp(argv[i], "--stress")) {
td::Test::set_stress_flag(true);
runner.set_stress_flag(true);
}
}
#if TD_EMSCRIPTEN
emscripten_set_main_loop(
[] {
if (!td::Test::run_all_step()) {
if (!runner.run_all_step()) {
emscripten_cancel_main_loop();
}
},
10, 0);
#else
td::Test::run_all();
runner.run_all();
#endif
return 0;
}

View File

@ -163,7 +163,7 @@ class Mtproto_ping : public td::Test {
ConcurrentScheduler sched_;
Status result_;
};
Mtproto_ping mtproto_ping("Mtproto_ping");
RegisterTest<Mtproto_ping> mtproto_ping("Mtproto_ping");
class HandshakeContext : public mtproto::AuthKeyHandshakeContext {
public:
@ -296,7 +296,7 @@ class Mtproto_handshake : public td::Test {
ConcurrentScheduler sched_;
Status result_;
};
Mtproto_handshake mtproto_handshake("Mtproto_handshake");
RegisterTest<Mtproto_handshake> mtproto_handshake("Mtproto_handshake");
class Socks5TestActor : public Actor {
public:

View File

@ -1,18 +0,0 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include "test/tests_runner.h"
#include "test/TestsRunner.h"
extern "C" {
void tests_runner_init(const char *dir) {
td::TestsRunner::init(dir);
}
void run_all_tests() {
td::TestsRunner::run_all_tests();
}
}

View File

@ -1,18 +0,0 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
void tests_runner_init(const char *dir);
void run_all_tests();
#ifdef __cplusplus
}
#endif