73 lines
2.6 KiB
Dart
73 lines
2.6 KiB
Dart
import 'package:fluttery/fluttery.dart';
|
|
|
|
/// Interface for secure storage operations.
|
|
///
|
|
/// Provides methods for securely storing and retrieving sensitive data
|
|
/// like passwords, tokens, API keys, etc. Data stored through this interface
|
|
/// is encrypted and stored in the device's secure storage (Keychain on iOS,
|
|
/// Keystore on Android).
|
|
abstract class SecureStorage implements Service {
|
|
/// Stores a string value securely with the given [key].
|
|
///
|
|
/// Returns a Future that completes when the value is successfully stored.
|
|
/// Throws an exception if the storage operation fails.
|
|
Future<void> write(String key, String value);
|
|
|
|
/// Retrieves the securely stored string value for the given [key].
|
|
///
|
|
/// Returns the stored value if found, null otherwise.
|
|
/// Throws an exception if the retrieval operation fails.
|
|
Future<String?> read(String key);
|
|
|
|
/// Stores an integer value securely with the given [key].
|
|
///
|
|
/// The integer is converted to a string for storage.
|
|
Future<void> writeInt(String key, int value);
|
|
|
|
/// Retrieves the securely stored integer value for the given [key].
|
|
///
|
|
/// Returns the stored integer if found and valid, null otherwise.
|
|
Future<int?> readInt(String key);
|
|
|
|
/// Stores a boolean value securely with the given [key].
|
|
///
|
|
/// The boolean is converted to a string for storage.
|
|
Future<void> writeBool(String key, bool value);
|
|
|
|
/// Retrieves the securely stored boolean value for the given [key].
|
|
///
|
|
/// Returns the stored boolean if found and valid, null otherwise.
|
|
Future<bool?> readBool(String key);
|
|
|
|
/// Stores a double value securely with the given [key].
|
|
///
|
|
/// The double is converted to a string for storage.
|
|
Future<void> writeDouble(String key, double value);
|
|
|
|
/// Retrieves the securely stored double value for the given [key].
|
|
///
|
|
/// Returns the stored double if found and valid, null otherwise.
|
|
Future<double?> readDouble(String key);
|
|
|
|
/// Removes the securely stored value for the given [key].
|
|
///
|
|
/// Returns a Future that completes when the value is successfully removed.
|
|
Future<void> delete(String key);
|
|
|
|
/// Removes all securely stored values.
|
|
///
|
|
/// Returns a Future that completes when all values are successfully removed.
|
|
/// Use with caution as this operation cannot be undone.
|
|
Future<void> deleteAll();
|
|
|
|
/// Returns all keys currently stored in secure storage.
|
|
///
|
|
/// Useful for debugging or migration purposes.
|
|
Future<Set<String>> readAllKeys();
|
|
|
|
/// Checks if a value exists for the given [key].
|
|
///
|
|
/// Returns true if a value exists, false otherwise.
|
|
Future<bool> containsKey(String key);
|
|
}
|