Fixes for updated tdutils
GitOrigin-RevId: 44ef7ad802652dba0f7e90f59fa2b81e72641db1
This commit is contained in:
parent
d34831c613
commit
e0b9cf2586
@ -168,7 +168,7 @@ void ObfuscatedTransport::init(ChainBufferReader *input, ChainBufferWriter *outp
|
|||||||
|
|
||||||
string rheader = header;
|
string rheader = header;
|
||||||
std::reverse(rheader.begin(), rheader.end());
|
std::reverse(rheader.begin(), rheader.end());
|
||||||
auto key = as<UInt256>(rheader.data() + 8);
|
UInt256 key = as<UInt256>(rheader.data() + 8);
|
||||||
if (secret_.size() == 17) {
|
if (secret_.size() == 17) {
|
||||||
secret_ = secret_.substr(1);
|
secret_ = secret_.substr(1);
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace mtproto {
|
namespace mtproto {
|
||||||
|
|
||||||
// mtproto v1.0
|
// mtproto v1.0
|
||||||
template <class HeaderT>
|
template <class HeaderT>
|
||||||
std::tuple<uint32, UInt128> Transport::calc_message_ack_and_key(const HeaderT &head, size_t data_size) {
|
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()
|
return Status::Error(PSLICE() << "Invalid mtproto message: too small [message.size()=" << message.size()
|
||||||
<< "] < [sizeof(NoCryptoHeader) = " << sizeof(NoCryptoHeader) << "]");
|
<< "] < [sizeof(NoCryptoHeader) = " << sizeof(NoCryptoHeader) << "]");
|
||||||
}
|
}
|
||||||
auto &header = as<NoCryptoHeader>(message.begin());
|
|
||||||
size_t data_size = message.size() - sizeof(NoCryptoHeader);
|
size_t data_size = message.size() - sizeof(NoCryptoHeader);
|
||||||
CHECK(message.size() == calc_no_crypto_size(data_size));
|
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();
|
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()
|
return Status::Error(PSLICE() << "Invalid mtproto message: too small [message.size()=" << message.size()
|
||||||
<< "] < [sizeof(HeaderT) = " << sizeof(HeaderT) << "]");
|
<< "] < [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;
|
*header_ptr = header;
|
||||||
auto to_decrypt = MutableSlice(header->encrypt_begin(), message.uend());
|
auto to_decrypt = MutableSlice(header->encrypt_begin(), message.uend());
|
||||||
to_decrypt = to_decrypt.truncate(to_decrypt.size() & ~15);
|
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)) {
|
if (tail_size < sizeof(PrefixT)) {
|
||||||
return Status::Error("Too small encrypted part");
|
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;
|
*prefix_ptr = prefix;
|
||||||
size_t data_size = prefix->message_data_length + sizeof(PrefixT);
|
size_t data_size = prefix->message_data_length + sizeof(PrefixT);
|
||||||
bool is_length_ok = prefix->message_data_length % 4 == 0;
|
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()) {
|
if (size > dest.size()) {
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
auto &header = as<NoCryptoHeader>(dest.begin());
|
// NoCryptoHeader
|
||||||
header.auth_key_id = 0;
|
as<uint64>(dest.begin()) = uint64(0);
|
||||||
auto real_size = storer.store(header.data);
|
auto real_size = storer.store(dest.ubegin() + sizeof(uint64));
|
||||||
CHECK(real_size == storer.size());
|
CHECK(real_size == storer.size());
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
@ -249,7 +249,8 @@ size_t Transport::write_crypto(const Storer &storer, const AuthKey &auth_key, Pa
|
|||||||
return size;
|
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.auth_key_id = auth_key.id();
|
||||||
header.salt = info->salt;
|
header.salt = info->salt;
|
||||||
header.session_id = info->session_id;
|
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;
|
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();
|
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);
|
write_crypto_impl(info->is_creator || info->version == 1 ? 0 : 8, storer, auth_key, info, &header, data_size);
|
||||||
|
@ -312,7 +312,7 @@ Result<size_t> FileDownloader::process_part(Part part, NetQueryPtr net_query) {
|
|||||||
|
|
||||||
// Encryption
|
// Encryption
|
||||||
if (need_cdn_decrypt) {
|
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);
|
CHECK(part.offset % 16 == 0);
|
||||||
auto offset = narrow_cast<uint32>(part.offset / 16);
|
auto offset = narrow_cast<uint32>(part.offset / 16);
|
||||||
offset =
|
offset =
|
||||||
|
@ -9,11 +9,6 @@ set(TD_TEST_SOURCE
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/secret.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/secret.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/secure_storage.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/secure_storage.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/string_cleaning.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.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/data.h
|
${CMAKE_CURRENT_SOURCE_DIR}/data.h
|
||||||
|
@ -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
|
|
@ -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
|
|
@ -16,26 +16,27 @@
|
|||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
// TODO port OptionsParser to Windows
|
// TODO port OptionsParser to Windows
|
||||||
|
td::TestsRunner &runner = td::TestsRunner::get_default();
|
||||||
SET_VERBOSITY_LEVEL(VERBOSITY_NAME(ERROR));
|
SET_VERBOSITY_LEVEL(VERBOSITY_NAME(ERROR));
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
if (!std::strcmp(argv[i], "--filter")) {
|
if (!std::strcmp(argv[i], "--filter")) {
|
||||||
CHECK(i + 1 < argc);
|
CHECK(i + 1 < argc);
|
||||||
td::Test::add_substr_filter(argv[++i]);
|
runner.add_substr_filter(argv[++i]);
|
||||||
}
|
}
|
||||||
if (!std::strcmp(argv[i], "--stress")) {
|
if (!std::strcmp(argv[i], "--stress")) {
|
||||||
td::Test::set_stress_flag(true);
|
runner.set_stress_flag(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if TD_EMSCRIPTEN
|
#if TD_EMSCRIPTEN
|
||||||
emscripten_set_main_loop(
|
emscripten_set_main_loop(
|
||||||
[] {
|
[] {
|
||||||
if (!td::Test::run_all_step()) {
|
if (!runner.run_all_step()) {
|
||||||
emscripten_cancel_main_loop();
|
emscripten_cancel_main_loop();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
10, 0);
|
10, 0);
|
||||||
#else
|
#else
|
||||||
td::Test::run_all();
|
runner.run_all();
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,7 @@ class Mtproto_ping : public td::Test {
|
|||||||
ConcurrentScheduler sched_;
|
ConcurrentScheduler sched_;
|
||||||
Status result_;
|
Status result_;
|
||||||
};
|
};
|
||||||
Mtproto_ping mtproto_ping("Mtproto_ping");
|
RegisterTest<Mtproto_ping> mtproto_ping("Mtproto_ping");
|
||||||
|
|
||||||
class HandshakeContext : public mtproto::AuthKeyHandshakeContext {
|
class HandshakeContext : public mtproto::AuthKeyHandshakeContext {
|
||||||
public:
|
public:
|
||||||
@ -296,7 +296,7 @@ class Mtproto_handshake : public td::Test {
|
|||||||
ConcurrentScheduler sched_;
|
ConcurrentScheduler sched_;
|
||||||
Status result_;
|
Status result_;
|
||||||
};
|
};
|
||||||
Mtproto_handshake mtproto_handshake("Mtproto_handshake");
|
RegisterTest<Mtproto_handshake> mtproto_handshake("Mtproto_handshake");
|
||||||
|
|
||||||
class Socks5TestActor : public Actor {
|
class Socks5TestActor : public Actor {
|
||||||
public:
|
public:
|
||||||
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
@ -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
|
|
Loading…
x
Reference in New Issue
Block a user