2018-03-27 15:11:15 +02:00
|
|
|
//
|
2022-01-01 01:35:39 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
|
2018-03-27 15:11:15 +02:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "td/telegram/SecureValue.h"
|
|
|
|
|
|
|
|
#include "td/telegram/files/FileId.hpp"
|
|
|
|
|
|
|
|
#include "td/utils/tl_helpers.h"
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
|
|
|
template <class StorerT>
|
2018-04-20 16:48:17 +02:00
|
|
|
void store(DatedFile file, StorerT &storer) {
|
2018-03-27 15:11:15 +02:00
|
|
|
store(file.file_id, storer);
|
2018-04-19 15:43:09 +02:00
|
|
|
store(file.date, storer);
|
2018-04-20 16:48:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(DatedFile &file, ParserT &parser) {
|
|
|
|
parse(file.file_id, parser);
|
|
|
|
parse(file.date, parser);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void store(EncryptedSecureFile file, StorerT &storer) {
|
|
|
|
store(file.file, storer);
|
2018-03-27 15:11:15 +02:00
|
|
|
store(file.file_hash, storer);
|
|
|
|
store(file.encrypted_secret, storer);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
2018-04-06 15:41:38 +02:00
|
|
|
void parse(EncryptedSecureFile &file, ParserT &parser) {
|
2018-04-20 16:48:17 +02:00
|
|
|
parse(file.file, parser);
|
2018-03-27 15:11:15 +02:00
|
|
|
parse(file.file_hash, parser);
|
|
|
|
parse(file.encrypted_secret, parser);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class StorerT>
|
2018-04-06 15:41:38 +02:00
|
|
|
void store(const EncryptedSecureData &data, StorerT &storer) {
|
2018-03-27 15:11:15 +02:00
|
|
|
store(data.data, storer);
|
|
|
|
store(data.hash, storer);
|
|
|
|
store(data.encrypted_secret, storer);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
2018-04-06 15:41:38 +02:00
|
|
|
void parse(EncryptedSecureData &data, ParserT &parser) {
|
2018-03-27 15:11:15 +02:00
|
|
|
parse(data.data, parser);
|
|
|
|
parse(data.hash, parser);
|
|
|
|
parse(data.encrypted_secret, parser);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class StorerT>
|
2018-04-06 21:37:30 +02:00
|
|
|
void store(const EncryptedSecureCredentials &credentials, StorerT &storer) {
|
2018-03-27 15:11:15 +02:00
|
|
|
store(credentials.data, storer);
|
|
|
|
store(credentials.hash, storer);
|
|
|
|
store(credentials.encrypted_secret, storer);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
2018-04-06 21:37:30 +02:00
|
|
|
void parse(EncryptedSecureCredentials &credentials, ParserT &parser) {
|
2018-03-27 15:11:15 +02:00
|
|
|
parse(credentials.data, parser);
|
|
|
|
parse(credentials.hash, parser);
|
|
|
|
parse(credentials.encrypted_secret, parser);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void store(const EncryptedSecureValue &value, StorerT &storer) {
|
|
|
|
bool has_data_hash = !value.data.hash.empty();
|
|
|
|
bool has_files = !value.files.empty();
|
2018-04-27 14:38:02 +02:00
|
|
|
bool has_front_side = value.front_side.file.file_id.is_valid();
|
|
|
|
bool has_reverse_side = value.reverse_side.file.file_id.is_valid();
|
2018-04-20 16:48:17 +02:00
|
|
|
bool has_selfie = value.selfie.file.file_id.is_valid();
|
2018-08-10 18:39:48 +02:00
|
|
|
bool has_hash = !value.hash.empty();
|
|
|
|
bool has_translations = !value.translations.empty();
|
2018-03-27 15:11:15 +02:00
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(has_data_hash);
|
|
|
|
STORE_FLAG(has_files);
|
2018-04-27 14:38:02 +02:00
|
|
|
STORE_FLAG(has_front_side);
|
|
|
|
STORE_FLAG(has_reverse_side);
|
2018-03-27 15:11:15 +02:00
|
|
|
STORE_FLAG(has_selfie);
|
2018-08-10 18:39:48 +02:00
|
|
|
STORE_FLAG(has_hash);
|
|
|
|
STORE_FLAG(has_translations);
|
2018-03-27 15:11:15 +02:00
|
|
|
END_STORE_FLAGS();
|
|
|
|
store(value.type, storer);
|
|
|
|
if (has_data_hash) {
|
|
|
|
store(value.data, storer);
|
|
|
|
} else {
|
|
|
|
store(value.data.data, storer);
|
|
|
|
}
|
|
|
|
if (has_files) {
|
|
|
|
store(value.files, storer);
|
|
|
|
}
|
2018-04-27 14:38:02 +02:00
|
|
|
if (has_front_side) {
|
|
|
|
store(value.front_side, storer);
|
|
|
|
}
|
|
|
|
if (has_reverse_side) {
|
|
|
|
store(value.reverse_side, storer);
|
|
|
|
}
|
2018-03-27 15:11:15 +02:00
|
|
|
if (has_selfie) {
|
|
|
|
store(value.selfie, storer);
|
|
|
|
}
|
2018-08-10 18:39:48 +02:00
|
|
|
if (has_hash) {
|
|
|
|
store(value.hash, storer);
|
|
|
|
}
|
|
|
|
if (has_translations) {
|
|
|
|
store(value.translations, storer);
|
|
|
|
}
|
2018-03-27 15:11:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(EncryptedSecureValue &value, ParserT &parser) {
|
|
|
|
bool has_data_hash;
|
|
|
|
bool has_files;
|
2018-04-27 14:38:02 +02:00
|
|
|
bool has_front_side;
|
|
|
|
bool has_reverse_side;
|
2018-03-27 15:11:15 +02:00
|
|
|
bool has_selfie;
|
2018-08-10 18:39:48 +02:00
|
|
|
bool has_hash;
|
|
|
|
bool has_translations;
|
2018-03-27 15:11:15 +02:00
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(has_data_hash);
|
|
|
|
PARSE_FLAG(has_files);
|
2018-04-27 14:38:02 +02:00
|
|
|
PARSE_FLAG(has_front_side);
|
|
|
|
PARSE_FLAG(has_reverse_side);
|
2018-03-27 15:11:15 +02:00
|
|
|
PARSE_FLAG(has_selfie);
|
2018-08-10 18:39:48 +02:00
|
|
|
PARSE_FLAG(has_hash);
|
|
|
|
PARSE_FLAG(has_translations);
|
2018-03-27 15:11:15 +02:00
|
|
|
END_PARSE_FLAGS();
|
|
|
|
parse(value.type, parser);
|
|
|
|
if (has_data_hash) {
|
|
|
|
parse(value.data, parser);
|
|
|
|
} else {
|
|
|
|
parse(value.data.data, parser);
|
|
|
|
}
|
|
|
|
if (has_files) {
|
|
|
|
parse(value.files, parser);
|
|
|
|
}
|
2018-04-27 14:38:02 +02:00
|
|
|
if (has_front_side) {
|
|
|
|
parse(value.front_side, parser);
|
|
|
|
}
|
|
|
|
if (has_reverse_side) {
|
|
|
|
parse(value.reverse_side, parser);
|
|
|
|
}
|
2018-03-27 15:11:15 +02:00
|
|
|
if (has_selfie) {
|
|
|
|
parse(value.selfie, parser);
|
|
|
|
}
|
2018-08-10 18:39:48 +02:00
|
|
|
if (has_hash) {
|
|
|
|
parse(value.hash, parser);
|
|
|
|
}
|
|
|
|
if (has_translations) {
|
|
|
|
parse(value.translations, parser);
|
|
|
|
}
|
2018-03-27 15:11:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace td
|