2020-06-15 16:25:02 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace MTP {
|
2020-06-17 09:36:25 +00:00
|
|
|
class Config;
|
2020-06-15 16:25:02 +00:00
|
|
|
class AuthKey;
|
|
|
|
using AuthKeyPtr = std::shared_ptr<AuthKey>;
|
|
|
|
} // namespace MTP
|
|
|
|
|
|
|
|
namespace Main {
|
|
|
|
class Account;
|
2020-06-18 18:04:16 +00:00
|
|
|
class Domain;
|
2020-06-15 16:25:02 +00:00
|
|
|
} // namespace Main
|
|
|
|
|
|
|
|
namespace Storage {
|
|
|
|
|
|
|
|
enum class StartResult : uchar {
|
|
|
|
Success,
|
|
|
|
IncorrectPasscode,
|
2020-07-22 12:10:17 +00:00
|
|
|
IncorrectPasscodeLegacy,
|
2020-06-15 16:25:02 +00:00
|
|
|
};
|
|
|
|
|
2020-06-18 18:04:16 +00:00
|
|
|
class Domain final {
|
2020-06-15 16:25:02 +00:00
|
|
|
public:
|
2020-06-18 18:04:16 +00:00
|
|
|
Domain(not_null<Main::Domain*> owner, const QString &dataName);
|
|
|
|
~Domain();
|
2020-06-15 16:25:02 +00:00
|
|
|
|
2020-06-16 09:40:43 +00:00
|
|
|
[[nodiscard]] StartResult start(const QByteArray &passcode);
|
2020-06-17 09:36:25 +00:00
|
|
|
void startAdded(
|
|
|
|
not_null<Main::Account*> account,
|
|
|
|
std::unique_ptr<MTP::Config> config);
|
2020-06-15 16:25:02 +00:00
|
|
|
void writeAccounts();
|
2020-06-16 09:40:43 +00:00
|
|
|
void startFromScratch();
|
2020-06-15 16:25:02 +00:00
|
|
|
|
|
|
|
[[nodiscard]] bool checkPasscode(const QByteArray &passcode) const;
|
|
|
|
void setPasscode(const QByteArray &passcode);
|
|
|
|
|
|
|
|
[[nodiscard]] int oldVersion() const;
|
|
|
|
void clearOldVersion();
|
|
|
|
|
2021-03-24 11:30:01 +00:00
|
|
|
[[nodiscard]] QString webviewDataPath() const;
|
|
|
|
|
2020-06-15 16:25:02 +00:00
|
|
|
private:
|
|
|
|
enum class StartModernResult {
|
|
|
|
Success,
|
|
|
|
IncorrectPasscode,
|
|
|
|
Failed,
|
|
|
|
Empty,
|
|
|
|
};
|
|
|
|
|
2020-06-16 09:40:43 +00:00
|
|
|
[[nodiscard]] StartModernResult startModern(const QByteArray &passcode);
|
2020-06-15 16:25:02 +00:00
|
|
|
void startWithSingleAccount(
|
|
|
|
const QByteArray &passcode,
|
|
|
|
std::unique_ptr<Main::Account> account);
|
|
|
|
void generateLocalKey();
|
|
|
|
void encryptLocalKey(const QByteArray &passcode);
|
|
|
|
|
2020-06-18 18:04:16 +00:00
|
|
|
const not_null<Main::Domain*> _owner;
|
2020-06-15 16:25:02 +00:00
|
|
|
const QString _dataName;
|
|
|
|
|
|
|
|
MTP::AuthKeyPtr _localKey;
|
|
|
|
MTP::AuthKeyPtr _passcodeKey;
|
|
|
|
QByteArray _passcodeKeySalt;
|
|
|
|
QByteArray _passcodeKeyEncrypted;
|
|
|
|
int _oldVersion = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Storage
|