diff --git a/Telegram/SourceFiles/calls/group/calls_group_call.cpp b/Telegram/SourceFiles/calls/group/calls_group_call.cpp index 2785652891..f086e5416c 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_call.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_call.cpp @@ -2547,6 +2547,14 @@ bool GroupCall::tryCreateController() { } }); }; + auto e2eEncryptDecrypt = Fn( + const std::vector&, + bool)>(); + if (_e2e) { + e2eEncryptDecrypt = [e2e = _e2e](const std::vector &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; diff --git a/Telegram/SourceFiles/tde2e/tde2e_api.cpp b/Telegram/SourceFiles/tde2e/tde2e_api.cpp index 04ae7340ac..4c01426925 100644 --- a/Telegram/SourceFiles/tde2e/tde2e_api.cpp +++ b/Telegram/SourceFiles/tde2e/tde2e_api.cpp @@ -85,4 +85,36 @@ Call::ApplyResult Call::apply(const Block &block) { : ApplyResult::BlockSkipped; } +std::vector Call::encrypt(const std::vector &data) const { + const auto result = tde2e_api::call_encrypt( + std::int64_t(_id.v), + std::string_view{ + reinterpret_cast(data.data()), + data.size(), + }); + if (!result.is_ok()) { + return {}; + } + const auto &value = result.value(); + const auto start = reinterpret_cast(value.data()); + const auto end = start + value.size(); + return std::vector{ start, end }; +} + +std::vector Call::decrypt(const std::vector &data) const { + const auto result = tde2e_api::call_decrypt( + std::int64_t(_id.v), + std::string_view{ + reinterpret_cast(data.data()), + data.size(), + }); + if (!result.is_ok()) { + return {}; + } + const auto &value = result.value(); + const auto start = reinterpret_cast(value.data()); + const auto end = start + value.size(); + return std::vector{ start, end }; +} + } // namespace TdE2E diff --git a/Telegram/SourceFiles/tde2e/tde2e_api.h b/Telegram/SourceFiles/tde2e/tde2e_api.h index 36a634576d..ae8d70279e 100644 --- a/Telegram/SourceFiles/tde2e/tde2e_api.h +++ b/Telegram/SourceFiles/tde2e/tde2e_api.h @@ -55,6 +55,11 @@ public: }; [[nodiscard]] ApplyResult apply(const Block &block); + [[nodiscard]] std::vector encrypt( + const std::vector &data) const; + [[nodiscard]] std::vector decrypt( + const std::vector &data) const; + private: CallId _id; UserId _myUserId;