diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index af9a37345..e9ddb3091 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -2567,17 +2567,6 @@ vector> Td::get_fake_current_state() const { return updates; } -DbKey Td::as_db_key(string key) { - // Database will still be effectively not encrypted, but - // 1. SQLite database will be protected from corruption, because that's how sqlcipher works - // 2. security through obscurity - // 3. no need for reencryption of SQLite database - if (key.empty()) { - return DbKey::raw_key("cucumber"); - } - return DbKey::raw_key(std::move(key)); -} - void Td::request(uint64 id, tl_object_ptr function) { if (id == 0) { LOG(ERROR) << "Ignore request with ID == 0: " << to_string(function); @@ -3802,7 +3791,7 @@ Result> Td::get_parameters( result.first.api_hash_ = std::move(parameters->api_hash_); result.first.use_secret_chats_ = parameters->use_secret_chats_; - result.second.encryption_key_ = as_db_key(std::move(parameters->database_encryption_key_)); + result.second.encryption_key_ = TdDb::as_db_key(std::move(parameters->database_encryption_key_)); result.second.database_directory_ = std::move(parameters->database_directory_); result.second.files_directory_ = std::move(parameters->files_directory_); result.second.is_test_dc_ = parameters->use_test_dc_; @@ -3850,7 +3839,7 @@ void Td::on_request(uint64 id, const td_api::setTdlibParameters &request) { void Td::on_request(uint64 id, td_api::setDatabaseEncryptionKey &request) { CREATE_OK_REQUEST_PROMISE(); - G()->td_db()->get_binlog()->change_key(as_db_key(std::move(request.new_encryption_key_)), std::move(promise)); + G()->td_db()->get_binlog()->change_key(TdDb::as_db_key(std::move(request.new_encryption_key_)), std::move(promise)); } void Td::on_request(uint64 id, const td_api::getAuthorizationState &request) { diff --git a/td/telegram/Td.h b/td/telegram/Td.h index ee030565a..16dda7e13 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -17,8 +17,6 @@ #include "td/telegram/telegram_api.h" #include "td/telegram/TermsOfService.h" -#include "td/db/DbKey.h" - #include "td/actor/actor.h" #include "td/actor/MultiTimeout.h" @@ -2020,8 +2018,6 @@ class Td final : public Actor { void on_request(uint64 id, td_api::testCallVectorString &request); void on_request(uint64 id, td_api::testCallVectorStringObject &request); - static DbKey as_db_key(string key); - struct Parameters { int32 api_id_ = 0; string api_hash_; diff --git a/td/telegram/TdDb.cpp b/td/telegram/TdDb.cpp index 3cf446caa..5998610c4 100644 --- a/td/telegram/TdDb.cpp +++ b/td/telegram/TdDb.cpp @@ -662,6 +662,13 @@ Status TdDb::check_parameters(Parameters ¶meters) { return Status::OK(); } +DbKey TdDb::as_db_key(string key) { + if (key.empty()) { + return DbKey::raw_key("cucumber"); + } + return DbKey::raw_key(std::move(key)); +} + void TdDb::change_key(DbKey key, Promise<> promise) { get_binlog()->change_key(std::move(key), std::move(promise)); } diff --git a/td/telegram/TdDb.h b/td/telegram/TdDb.h index 7e43a698e..708139232 100644 --- a/td/telegram/TdDb.h +++ b/td/telegram/TdDb.h @@ -148,6 +148,8 @@ class TdDb { StoryDbSyncInterface *get_story_db_sync(); StoryDbAsyncInterface *get_story_db_async(); + static DbKey as_db_key(string key); + void change_key(DbKey key, Promise<> promise); void with_db_path(const std::function &callback);