feat: работа с шифрованным текстом/фото

This commit is contained in:
Jganenokk
2026-07-26 16:23:05 +07:00
parent ba1f63ad05
commit ac951ea80a
90 changed files with 7248 additions and 64 deletions
@@ -0,0 +1,38 @@
import 'per_chat_json_store.dart';
import 'token_storage.dart';
class ChatEncryptionStore extends PerChatJsonStore<bool> {
ChatEncryptionStore._()
: super(
prefsKey: 'chat_encryption',
fromJson: (raw) => raw == true ? true : null,
toJson: (value) => value,
);
static final ChatEncryptionStore instance = ChatEncryptionStore._();
static const String _keyPrefix = 'chat_encryption_key';
bool isEnabled(int accountId, int chatId) => read(accountId, chatId) == true;
Future<void> setEnabled(int accountId, int chatId, bool enabled) =>
write(accountId, chatId, enabled ? true : null);
Future<String?> readKey(int accountId, int chatId) async {
if (accountId == 0) return null;
return TokenStorage.readSecure(_secureKey(accountId, chatId));
}
Future<void> writeKey(int accountId, int chatId, String key) async {
if (accountId == 0) return;
await TokenStorage.writeSecure(_secureKey(accountId, chatId), key);
}
Future<void> deleteKey(int accountId, int chatId) async {
if (accountId == 0) return;
await TokenStorage.deleteSecure(_secureKey(accountId, chatId));
}
String _secureKey(int accountId, int chatId) =>
'${_keyPrefix}_${accountId}_$chatId';
}