tdesktop/Telegram/SourceFiles/storage/storage_domain.h

74 lines
1.6 KiB
C
Raw Normal View History

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 Config;
2020-06-15 16:25:02 +00:00
class AuthKey;
using AuthKeyPtr = std::shared_ptr<AuthKey>;
} // namespace MTP
namespace Main {
class Account;
class Domain;
2020-06-15 16:25:02 +00:00
} // namespace Main
namespace Storage {
enum class StartResult : uchar {
Success,
IncorrectPasscode,
IncorrectPasscodeLegacy,
2020-06-15 16:25:02 +00:00
};
class Domain final {
2020-06-15 16:25:02 +00:00
public:
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);
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();
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);
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