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 {
|
|
|
|
class AuthKey;
|
|
|
|
using AuthKeyPtr = std::shared_ptr<AuthKey>;
|
|
|
|
} // namespace MTP
|
|
|
|
|
|
|
|
namespace Main {
|
|
|
|
class Account;
|
|
|
|
class Accounts;
|
|
|
|
} // namespace Main
|
|
|
|
|
|
|
|
namespace Storage {
|
|
|
|
|
|
|
|
enum class StartResult : uchar {
|
|
|
|
Success,
|
|
|
|
IncorrectPasscode,
|
|
|
|
};
|
|
|
|
|
|
|
|
class Accounts final {
|
|
|
|
public:
|
|
|
|
Accounts(not_null<Main::Accounts*> owner, const QString &dataName);
|
|
|
|
~Accounts();
|
|
|
|
|
2020-06-16 09:40:43 +00:00
|
|
|
[[nodiscard]] StartResult start(const QByteArray &passcode);
|
2020-06-16 06:42:47 +00:00
|
|
|
void startAdded(not_null<Main::Account*> account);
|
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();
|
|
|
|
|
|
|
|
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);
|
|
|
|
void writeInfo();
|
|
|
|
|
|
|
|
const not_null<Main::Accounts*> _owner;
|
|
|
|
const QString _dataName;
|
|
|
|
|
|
|
|
MTP::AuthKeyPtr _localKey;
|
|
|
|
MTP::AuthKeyPtr _passcodeKey;
|
|
|
|
QByteArray _passcodeKeySalt;
|
|
|
|
QByteArray _passcodeKeyEncrypted;
|
|
|
|
int _oldVersion = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Storage
|