Pass encrypt/decrypt callback to tgcalls.

This commit is contained in:
John Preston 2025-03-25 23:16:39 +05:00
parent f9a7c46868
commit ebe11fdb1e
3 changed files with 46 additions and 0 deletions

View file

@ -2547,6 +2547,14 @@ bool GroupCall::tryCreateController() {
}
});
};
auto e2eEncryptDecrypt = Fn<std::vector<uint8_t>(
const std::vector<uint8_t>&,
bool)>();
if (_e2e) {
e2eEncryptDecrypt = [e2e = _e2e](const std::vector<uint8_t> &data, bool encrypt) {
return encrypt ? e2e->encrypt(data) : e2e->decrypt(data);
};
}
tgcalls::GroupInstanceDescriptor descriptor = {
.threads = tgcalls::StaticThreads::getThreads(),
@ -2633,6 +2641,7 @@ bool GroupCall::tryCreateController() {
});
return result;
},
.e2eEncryptDecrypt = e2eEncryptDecrypt,
};
if (Logs::DebugEnabled()) {
auto callLogFolder = cWorkingDir() + u"DebugLogs"_q;

View file

@ -85,4 +85,36 @@ Call::ApplyResult Call::apply(const Block &block) {
: ApplyResult::BlockSkipped;
}
std::vector<uint8_t> Call::encrypt(const std::vector<uint8_t> &data) const {
const auto result = tde2e_api::call_encrypt(
std::int64_t(_id.v),
std::string_view{
reinterpret_cast<const char*>(data.data()),
data.size(),
});
if (!result.is_ok()) {
return {};
}
const auto &value = result.value();
const auto start = reinterpret_cast<const uint8_t*>(value.data());
const auto end = start + value.size();
return std::vector<uint8_t>{ start, end };
}
std::vector<uint8_t> Call::decrypt(const std::vector<uint8_t> &data) const {
const auto result = tde2e_api::call_decrypt(
std::int64_t(_id.v),
std::string_view{
reinterpret_cast<const char*>(data.data()),
data.size(),
});
if (!result.is_ok()) {
return {};
}
const auto &value = result.value();
const auto start = reinterpret_cast<const uint8_t*>(value.data());
const auto end = start + value.size();
return std::vector<uint8_t>{ start, end };
}
} // namespace TdE2E

View file

@ -55,6 +55,11 @@ public:
};
[[nodiscard]] ApplyResult apply(const Block &block);
[[nodiscard]] std::vector<uint8_t> encrypt(
const std::vector<uint8_t> &data) const;
[[nodiscard]] std::vector<uint8_t> decrypt(
const std::vector<uint8_t> &data) const;
private:
CallId _id;
UserId _myUserId;