Initial version
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
|
||||
/// Remembers scooter PINs in platform secure storage (Android Keystore backed
|
||||
/// storage, iOS Keychain), keyed by the BLE peripheral id.
|
||||
///
|
||||
/// The peripheral id is not a permanent scooter identity (see ScooterDevice).
|
||||
/// Once the Apollo UID is read over AT+UID? this should key by that instead.
|
||||
class PinStore {
|
||||
PinStore([FlutterSecureStorage? storage])
|
||||
: _storage = storage ?? const FlutterSecureStorage();
|
||||
|
||||
final FlutterSecureStorage _storage;
|
||||
|
||||
String _key(String deviceId) => 'pin:$deviceId';
|
||||
|
||||
Future<String?> read(String deviceId) async {
|
||||
try {
|
||||
return await _storage.read(key: _key(deviceId));
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> save(String deviceId, String pin) =>
|
||||
_storage.write(key: _key(deviceId), value: pin);
|
||||
|
||||
Future<void> forget(String deviceId) => _storage.delete(key: _key(deviceId));
|
||||
}
|
||||
Reference in New Issue
Block a user