mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-24 12:29:37 +00:00
164 lines
3.6 KiB
Dart
164 lines
3.6 KiB
Dart
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
|
|
|
abstract class FlutterSecureStorageInterface {
|
|
Future<void> write({
|
|
required String key,
|
|
required String? value,
|
|
IOSOptions? iOptions,
|
|
AndroidOptions? aOptions,
|
|
LinuxOptions? lOptions,
|
|
WebOptions? webOptions,
|
|
MacOsOptions? mOptions,
|
|
WindowsOptions? wOptions,
|
|
});
|
|
|
|
Future<String?> read({
|
|
required String key,
|
|
IOSOptions? iOptions,
|
|
AndroidOptions? aOptions,
|
|
LinuxOptions? lOptions,
|
|
WebOptions? webOptions,
|
|
MacOsOptions? mOptions,
|
|
WindowsOptions? wOptions,
|
|
});
|
|
|
|
Future<void> delete({
|
|
required String key,
|
|
IOSOptions? iOptions,
|
|
AndroidOptions? aOptions,
|
|
LinuxOptions? lOptions,
|
|
WebOptions? webOptions,
|
|
MacOsOptions? mOptions,
|
|
WindowsOptions? wOptions,
|
|
});
|
|
}
|
|
|
|
class SecureStorageWrapper implements FlutterSecureStorageInterface {
|
|
final FlutterSecureStorage secureStore;
|
|
|
|
const SecureStorageWrapper(this.secureStore);
|
|
|
|
@override
|
|
Future<String?> read({
|
|
required String key,
|
|
IOSOptions? iOptions,
|
|
AndroidOptions? aOptions,
|
|
LinuxOptions? lOptions,
|
|
WebOptions? webOptions,
|
|
MacOsOptions? mOptions,
|
|
WindowsOptions? wOptions,
|
|
}) {
|
|
return secureStore.read(
|
|
key: key,
|
|
iOptions: iOptions,
|
|
aOptions: aOptions,
|
|
lOptions: lOptions,
|
|
webOptions: webOptions,
|
|
mOptions: mOptions,
|
|
wOptions: wOptions,
|
|
);
|
|
}
|
|
|
|
@override
|
|
Future<void> write({
|
|
required String key,
|
|
required String? value,
|
|
IOSOptions? iOptions,
|
|
AndroidOptions? aOptions,
|
|
LinuxOptions? lOptions,
|
|
WebOptions? webOptions,
|
|
MacOsOptions? mOptions,
|
|
WindowsOptions? wOptions,
|
|
}) {
|
|
return secureStore.write(
|
|
key: key,
|
|
value: value,
|
|
iOptions: iOptions,
|
|
aOptions: aOptions,
|
|
lOptions: lOptions,
|
|
webOptions: webOptions,
|
|
mOptions: mOptions,
|
|
wOptions: wOptions,
|
|
);
|
|
}
|
|
|
|
@override
|
|
Future<void> delete({
|
|
required String key,
|
|
IOSOptions? iOptions,
|
|
AndroidOptions? aOptions,
|
|
LinuxOptions? lOptions,
|
|
WebOptions? webOptions,
|
|
MacOsOptions? mOptions,
|
|
WindowsOptions? wOptions,
|
|
}) async {
|
|
await secureStore.delete(
|
|
key: key,
|
|
iOptions: iOptions,
|
|
aOptions: aOptions,
|
|
lOptions: lOptions,
|
|
webOptions: webOptions,
|
|
mOptions: mOptions,
|
|
wOptions: wOptions,
|
|
);
|
|
}
|
|
}
|
|
|
|
// Mock class for testing purposes
|
|
class FakeSecureStorage implements FlutterSecureStorageInterface {
|
|
final Map<String, String?> _store = {};
|
|
int _interactions = 0;
|
|
int get interactions => _interactions;
|
|
int _writes = 0;
|
|
int get writes => _writes;
|
|
int _reads = 0;
|
|
int get reads => _reads;
|
|
int _deletes = 0;
|
|
int get deletes => _deletes;
|
|
|
|
@override
|
|
Future<String?> read({
|
|
required String key,
|
|
IOSOptions? iOptions,
|
|
AndroidOptions? aOptions,
|
|
LinuxOptions? lOptions,
|
|
WebOptions? webOptions,
|
|
MacOsOptions? mOptions,
|
|
WindowsOptions? wOptions,
|
|
}) async {
|
|
_interactions++;
|
|
_reads++;
|
|
return _store[key];
|
|
}
|
|
|
|
@override
|
|
Future<void> write({
|
|
required String key,
|
|
required String? value,
|
|
IOSOptions? iOptions,
|
|
AndroidOptions? aOptions,
|
|
LinuxOptions? lOptions,
|
|
WebOptions? webOptions,
|
|
MacOsOptions? mOptions,
|
|
WindowsOptions? wOptions,
|
|
}) async {
|
|
_interactions++;
|
|
_writes++;
|
|
_store[key] = value;
|
|
}
|
|
|
|
@override
|
|
Future<void> delete({
|
|
required String key,
|
|
IOSOptions? iOptions,
|
|
AndroidOptions? aOptions,
|
|
LinuxOptions? lOptions,
|
|
WebOptions? webOptions,
|
|
MacOsOptions? mOptions,
|
|
WindowsOptions? wOptions,
|
|
}) async {
|
|
_interactions++;
|
|
_deletes++;
|
|
_store.remove(key);
|
|
}
|
|
}
|