Various PassportData fixes.
GitOrigin-RevId: 7c8ce3d564c37dcc75715b5dac7886749e0ed9d3
This commit is contained in:
parent
febdf70626
commit
4e7b07508f
@ -1804,7 +1804,7 @@ fileTypeSecretThumbnail = FileType;
|
||||
//@description The file is a file from Secure storage used for storing Telegram Passport files
|
||||
fileTypeSecure = FileType;
|
||||
|
||||
//@description The file is an encrypted file from Secure storage used for storing Telegram Passport files
|
||||
//@description The file is an encrypted file from Secure storage used for storing Telegram Passport files; for bots only
|
||||
fileTypeSecureEncrypted = FileType;
|
||||
|
||||
//@description The file is a sticker
|
||||
|
@ -21494,7 +21494,7 @@ unique_ptr<MessageContent> MessagesManager::dup_message_content(DialogId dialog_
|
||||
if (to_secret && !file_view.is_encrypted_secret()) {
|
||||
auto download_file_id = file_manager->dup_file_id(file_id);
|
||||
file_id = file_manager
|
||||
->register_generate(FileType::Encrypted, FileLocationSource::FromServer, "",
|
||||
->register_generate(FileType::Encrypted, FileLocationSource::FromServer, file_view.suggested_name(),
|
||||
PSTRING() << "#file_id#" << download_file_id.get(), dialog_id, file_view.size())
|
||||
.ok();
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ class SetSecureValue : public NetQueryCallback {
|
||||
void loop() override;
|
||||
void on_result(NetQueryPtr query) override;
|
||||
|
||||
void start_upload(FileManager *file_manager, FileId file_id, SecureInputFile &info);
|
||||
void start_upload(FileManager *file_manager, FileId &file_id, SecureInputFile &info);
|
||||
void merge(FileManager *file_manager, FileId file_id, EncryptedSecureFile &encrypted_file);
|
||||
};
|
||||
|
||||
@ -395,7 +395,16 @@ void SetSecureValue::start_up() {
|
||||
}
|
||||
}
|
||||
|
||||
void SetSecureValue::start_upload(FileManager *file_manager, FileId file_id, SecureInputFile &info) {
|
||||
void SetSecureValue::start_upload(FileManager *file_manager, FileId &file_id, SecureInputFile &info) {
|
||||
auto file_view = file_manager->get_file_view(file_id);
|
||||
if (!file_view.is_encrypted_secure()) {
|
||||
auto download_file_id = file_manager->dup_file_id(file_id);
|
||||
file_id = file_manager
|
||||
->register_generate(FileType::Secure, FileLocationSource::FromServer, file_view.suggested_name(),
|
||||
PSTRING() << "#file_id#" << download_file_id.get(), DialogId(), file_view.size())
|
||||
.ok();
|
||||
}
|
||||
|
||||
info.file_id = file_manager->dup_file_id(file_id);
|
||||
file_manager->upload(info.file_id, upload_callback_, 1, 0);
|
||||
files_left_to_upload_++;
|
||||
@ -444,12 +453,12 @@ void SetSecureValue::on_result(NetQueryPtr query) {
|
||||
auto *file_manager = G()->td().get_actor_unsafe()->file_manager_.get();
|
||||
auto encrypted_secure_value = get_encrypted_secure_value(file_manager, std::move(result));
|
||||
if (secure_value_.files.size() != encrypted_secure_value.files.size()) {
|
||||
return on_error(Status::Error("Different files count"));
|
||||
return on_error(Status::Error(500, "Different file count"));
|
||||
}
|
||||
for (size_t i = 0; i < secure_value_.files.size(); i++) {
|
||||
merge(file_manager, secure_value_.files[i].file_id, encrypted_secure_value.files[i]);
|
||||
}
|
||||
if (secure_value_.selfie.file_id.is_valid()) {
|
||||
if (secure_value_.selfie.file_id.is_valid() && encrypted_secure_value.selfie.file.file_id.is_valid()) {
|
||||
merge(file_manager, secure_value_.selfie.file_id, encrypted_secure_value.selfie);
|
||||
}
|
||||
auto r_secure_value = decrypt_secure_value(file_manager, *secret_, encrypted_secure_value);
|
||||
|
@ -313,6 +313,10 @@ vector<EncryptedSecureFile> get_encrypted_secure_files(FileManager *file_manager
|
||||
telegram_api::object_ptr<telegram_api::InputSecureFile> get_input_secure_file_object(FileManager *file_manager,
|
||||
const EncryptedSecureFile &file,
|
||||
SecureInputFile &input_file) {
|
||||
if (!file.file.file_id.is_valid()) {
|
||||
LOG(ERROR) << "Receive invalid EncryptedSecureFile";
|
||||
return nullptr;
|
||||
}
|
||||
CHECK(file_manager->get_file_view(file.file.file_id).file_id() ==
|
||||
file_manager->get_file_view(input_file.file_id).file_id());
|
||||
auto res = std::move(input_file.input_file);
|
||||
@ -354,12 +358,15 @@ static vector<td_api::object_ptr<td_api::datedFile>> get_dated_files_object(File
|
||||
vector<telegram_api::object_ptr<telegram_api::InputSecureFile>> get_input_secure_files_object(
|
||||
FileManager *file_manager, const vector<EncryptedSecureFile> &files, vector<SecureInputFile> &input_files) {
|
||||
CHECK(files.size() == input_files.size());
|
||||
vector<telegram_api::object_ptr<telegram_api::InputSecureFile>> res;
|
||||
res.resize(files.size());
|
||||
vector<telegram_api::object_ptr<telegram_api::InputSecureFile>> results;
|
||||
results.reserve(files.size());
|
||||
for (size_t i = 0; i < files.size(); i++) {
|
||||
res[i] = get_input_secure_file_object(file_manager, files[i], input_files[i]);
|
||||
auto result = get_input_secure_file_object(file_manager, files[i], input_files[i]);
|
||||
if (result != nullptr) {
|
||||
results.push_back(std::move(result));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
bool operator==(const EncryptedSecureData &lhs, const EncryptedSecureData &rhs) {
|
||||
@ -1009,11 +1016,11 @@ static EncryptedSecureFile encrypt_secure_file(FileManager *file_manager, const
|
||||
return EncryptedSecureFile();
|
||||
}
|
||||
if (!file_view.encryption_key().is_secure()) {
|
||||
LOG(ERROR) << "File has no encryption key";
|
||||
LOG(ERROR) << "File " << file.file_id << " has no encryption key";
|
||||
return EncryptedSecureFile();
|
||||
}
|
||||
if (!file_view.encryption_key().has_value_hash()) {
|
||||
LOG(ERROR) << "File has no hash";
|
||||
LOG(ERROR) << "File " << file.file_id << " has no hash";
|
||||
return EncryptedSecureFile();
|
||||
}
|
||||
auto value_hash = file_view.encryption_key().value_hash();
|
||||
@ -1033,6 +1040,17 @@ static vector<EncryptedSecureFile> encrypt_secure_files(FileManager *file_manage
|
||||
vector<DatedFile> files, string &to_hash) {
|
||||
return transform(
|
||||
files, [&](auto dated_file) { return encrypt_secure_file(file_manager, master_secret, dated_file, to_hash); });
|
||||
/*
|
||||
vector<EncryptedSecureFile> result;
|
||||
result.reserve(files.size());
|
||||
for (auto &file : files) {
|
||||
auto encrypted_secure_file = encrypt_secure_file(file_manager, master_secret, file, to_hash);
|
||||
if (encrypted_secure_file.file.file_id.is_valid()) {
|
||||
result.push_back(std::move(encrypted_secure_file));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
*/
|
||||
}
|
||||
|
||||
static EncryptedSecureData encrypt_secure_data(const secure_storage::Secret &master_secret, Slice data,
|
||||
|
@ -2026,7 +2026,7 @@ class CliClient final : public Actor {
|
||||
}
|
||||
} else if (op == "cdf") {
|
||||
send_request(make_tl_object<td_api::cancelDownloadFile>(as_file_id(args), true));
|
||||
} else if (op == "uf") {
|
||||
} else if (op == "uf" || op == "ufs" || op == "ufse" || op == "ufsr") {
|
||||
string file_path;
|
||||
string priority;
|
||||
std::tie(file_path, priority) = split(args);
|
||||
@ -2034,18 +2034,19 @@ class CliClient final : public Actor {
|
||||
priority = "1";
|
||||
}
|
||||
|
||||
send_request(make_tl_object<td_api::uploadFile>(as_local_file(file_path), make_tl_object<td_api::fileTypePhoto>(),
|
||||
to_integer<int32>(priority)));
|
||||
} else if (op == "ufs") {
|
||||
string file_path;
|
||||
string priority;
|
||||
std::tie(file_path, priority) = split(args);
|
||||
if (priority.empty()) {
|
||||
priority = "1";
|
||||
td_api::object_ptr<td_api::FileType> type = make_tl_object<td_api::fileTypePhoto>();
|
||||
if (op == "ufs") {
|
||||
type = make_tl_object<td_api::fileTypeSecret>();
|
||||
}
|
||||
if (op == "ufse") {
|
||||
type = make_tl_object<td_api::fileTypeSecureEncrypted>();
|
||||
}
|
||||
if (op == "ufsr") {
|
||||
type = make_tl_object<td_api::fileTypeSecure>();
|
||||
}
|
||||
|
||||
send_request(make_tl_object<td_api::uploadFile>(
|
||||
as_local_file(file_path), make_tl_object<td_api::fileTypeSecret>(), to_integer<int32>(priority)));
|
||||
send_request(
|
||||
make_tl_object<td_api::uploadFile>(as_local_file(file_path), std::move(type), to_integer<int32>(priority)));
|
||||
} else if (op == "ufg") {
|
||||
string file_path;
|
||||
string conversion;
|
||||
|
@ -958,7 +958,7 @@ inline bool operator!=(const FullLocalFileLocation &lhs, const FullLocalFileLoca
|
||||
}
|
||||
|
||||
inline StringBuilder &operator<<(StringBuilder &sb, const FullLocalFileLocation &location) {
|
||||
return sb << tag("path", location.path_);
|
||||
return sb << "[" << file_type_name[static_cast<int32>(location.file_type_)] << "] at \"" << location.path_ << '"';
|
||||
}
|
||||
|
||||
class LocalFileLocation {
|
||||
|
@ -17,7 +17,7 @@ namespace td {
|
||||
/*** PartsManager ***/
|
||||
|
||||
namespace {
|
||||
int64 calc_parts_count(int64 size, int64 part_size) {
|
||||
int64 calc_part_count(int64 size, int64 part_size) {
|
||||
CHECK(part_size != 0);
|
||||
return (size + part_size - 1) / part_size;
|
||||
}
|
||||
@ -39,7 +39,7 @@ Status PartsManager::init_no_size(size_t part_size, const std::vector<int> &read
|
||||
part_size_ = part_size;
|
||||
} else {
|
||||
part_size_ = 32 * (1 << 10);
|
||||
while (use_part_count_limit_ && calc_parts_count(expected_size_, part_size_) > MAX_PART_COUNT) {
|
||||
while (use_part_count_limit_ && calc_part_count(expected_size_, part_size_) > MAX_PART_COUNT) {
|
||||
part_size_ *= 2;
|
||||
CHECK(part_size_ <= MAX_PART_SIZE);
|
||||
}
|
||||
@ -79,22 +79,22 @@ Status PartsManager::init(int64 size, int64 expected_size, bool is_size_final, s
|
||||
|
||||
if (part_size != 0) {
|
||||
part_size_ = part_size;
|
||||
if (use_part_count_limit_ && calc_parts_count(expected_size_, part_size_) > MAX_PART_COUNT) {
|
||||
if (use_part_count_limit_ && calc_part_count(expected_size_, part_size_) > MAX_PART_COUNT) {
|
||||
return Status::Error("FILE_UPLOAD_RESTART");
|
||||
}
|
||||
} else {
|
||||
// TODO choose part_size_ depending on size
|
||||
part_size_ = 64 * (1 << 10);
|
||||
while (use_part_count_limit && calc_parts_count(expected_size_, part_size_) > MAX_PART_COUNT) {
|
||||
while (use_part_count_limit && calc_part_count(expected_size_, part_size_) > MAX_PART_COUNT) {
|
||||
part_size_ *= 2;
|
||||
CHECK(part_size_ <= MAX_PART_SIZE);
|
||||
}
|
||||
}
|
||||
CHECK(1 <= size_) << tag("size_", size_);
|
||||
CHECK(!use_part_count_limit || calc_parts_count(expected_size_, part_size_) <= MAX_PART_COUNT)
|
||||
CHECK(!use_part_count_limit || calc_part_count(expected_size_, part_size_) <= MAX_PART_COUNT)
|
||||
<< tag("size_", size_) << tag("expected_size", size_) << tag("is_size_final", is_size_final)
|
||||
<< tag("part_size_", part_size_) << tag("ready_parts", ready_parts.size());
|
||||
part_count_ = static_cast<int>(calc_parts_count(size_, part_size_));
|
||||
part_count_ = static_cast<int>(calc_part_count(size_, part_size_));
|
||||
|
||||
init_common(ready_parts);
|
||||
return Status::OK();
|
||||
@ -172,7 +172,7 @@ Status PartsManager::set_known_prefix(size_t size, bool is_ready) {
|
||||
|
||||
CHECK(static_cast<size_t>(part_count_) == part_status_.size());
|
||||
if (is_ready) {
|
||||
part_count_ = static_cast<int>(calc_parts_count(size, part_size_));
|
||||
part_count_ = static_cast<int>(calc_part_count(size, part_size_));
|
||||
|
||||
size_ = narrow_cast<int64>(size);
|
||||
unknown_size_flag_ = false;
|
||||
@ -182,7 +182,7 @@ Status PartsManager::set_known_prefix(size_t size, bool is_ready) {
|
||||
CHECK(static_cast<size_t>(part_count_) >= part_status_.size())
|
||||
<< size << " " << is_ready << " " << part_count_ << " " << part_size_ << " " << part_status_.size();
|
||||
part_status_.resize(part_count_);
|
||||
if (use_part_count_limit_ && calc_parts_count(expected_size_, part_size_) > MAX_PART_COUNT) {
|
||||
if (use_part_count_limit_ && calc_part_count(expected_size_, part_size_) > MAX_PART_COUNT) {
|
||||
return Status::Error("FILE_UPLOAD_RESTART");
|
||||
}
|
||||
return Status::OK();
|
||||
|
Reference in New Issue
Block a user