mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-03 21:54:05 +02:00
Pass encrypt/decrypt callback to tgcalls.
This commit is contained in:
parent
f9a7c46868
commit
ebe11fdb1e
3 changed files with 46 additions and 0 deletions
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue