25 lines
922 B
Dart
25 lines
922 B
Dart
import 'dart:convert';
|
|
import 'package:QuickSSH/classes/ServerCommand.dart';
|
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
|
|
|
class SecureStorageService {
|
|
static const _storage = FlutterSecureStorage();
|
|
static const _key = 'mc_commands_list';
|
|
|
|
// SAVE: Converts list to JSON, then encrypts and stores it
|
|
static Future<void> saveCommands(List<ServerCommand> commands) async {
|
|
final String jsonData = jsonEncode(commands.map((c) => c.toMap()).toList());
|
|
await _storage.write(key: _key, value: jsonData);
|
|
}
|
|
|
|
// LOAD: Decrypts data, then converts JSON back to Objects
|
|
static Future<List<ServerCommand>> loadCommands() async {
|
|
final String? encryptedData = await _storage.read(key: _key);
|
|
|
|
if (encryptedData == null) return [];
|
|
|
|
final List<dynamic> decodedData = jsonDecode(encryptedData);
|
|
return decodedData.map((item) => ServerCommand.fromMap(item)).toList();
|
|
}
|
|
}
|