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();
|
|
|
|
|
|
|
|
[[nodiscard]] StartResult start(
|
|
|
|
const QByteArray &passcode,
|
|
|
|
Fn<void(int, std::unique_ptr<Main::Account>)> callback);
|
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();
|
|
|
|
|
|
|
|
[[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,
|
|
|
|
};
|
|
|
|
|
|
|
|
[[nodiscard]] StartModernResult startModern(
|
|
|
|
const QByteArray &passcode,
|
|
|
|
Fn<void(int, std::unique_ptr<Main::Account>)> callback);
|
|
|
|
void startWithSingleAccount(
|
|
|
|
const QByteArray &passcode,
|
|
|
|
Fn<void(int, std::unique_ptr<Main::Account>)> callback,
|
|
|
|
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
|