mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-05 20:07:44 +00:00
165 lines
3.6 KiB
Dart
165 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);
|
||
|
}
|
||
|
}
|