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

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