Move as_db_key to TdDb.

This commit is contained in:
levlam 2024-08-01 10:23:18 +03:00
parent 1880382e63
commit 78f6dccb00
4 changed files with 11 additions and 17 deletions

View File

@ -2567,17 +2567,6 @@ vector<td_api::object_ptr<td_api::Update>> 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<td_api::Function> function) {
if (id == 0) {
LOG(ERROR) << "Ignore request with ID == 0: " << to_string(function);
@ -3802,7 +3791,7 @@ Result<std::pair<Td::Parameters, TdDb::Parameters>> 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) {

View File

@ -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_;

View File

@ -662,6 +662,13 @@ Status TdDb::check_parameters(Parameters &parameters) {
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));
}

View File

@ -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<void(CSlice)> &callback);