KeyValueStorage

interface KeyValueStorage

A storage for key-value pairs. Implementations can either be secure or insecure. Secure storage should store data in a secure enclave on the device. Insecure storage can save directly to disk with no need for encryption.

An insecure storage can be used for user preferences, application settings, and other inconsequential data. For more important data, like an authentication token, user identifier, the secure storage should be used. The main reason to use secure storage is to keep any third party from gaining access to the data.

Types

Key
Link copied to clipboard
interface Key<T : Any>
Storage key is used to retrieve and store data in the storage.
StorageSecurity
Link copied to clipboard
enum StorageSecurity : Enum<KeyValueStorage.StorageSecurity>
Security of the storage, can be used as qualified for dependency injection to support having both secure and insecure implementations available for use.

Functions

contains
Link copied to clipboard
abstract fun <T : Any> contains(key: KeyValueStorage.Key<T>): Boolean
Checks whether the storage contains a value with the given key.
get
Link copied to clipboard
abstract operator fun <T : Any> get(key: KeyValueStorage.Key<T>): T?
Gets the value stored for the given key, or null if no value was stored for the key.
open fun <T : Any> get(key: KeyValueStorage.Key<T>, defaultValue: T): T
Gets the value stored for the given key, or returns the passed defaultValue if no value was stored for the key.
observe
Link copied to clipboard
abstract fun <T : Any> observe(key: KeyValueStorage.Key<T>): Flow<T?>
Observe changes to the key's value.
open fun <T : Any> observe(key: KeyValueStorage.Key<T>, defaultValue: T): Flow<T>
Observe changes to the key's value.
purge
Link copied to clipboard
abstract fun purge()
Remove all stored key-values from the storage.
set
Link copied to clipboard
abstract operator fun <T : Any> set(key: KeyValueStorage.Key<T>, value: T?)
Stores the passed value for the given key.

Properties

storageSecurity
Link copied to clipboard
abstract val storageSecurity: KeyValueStorage.StorageSecurity
The security of this storage.

Inheritors

BaseKeyValueStorage
Link copied to clipboard

Extensions

property
Link copied to clipboard
fun <OWNER, T : Any> KeyValueStorage.property(key: KeyValueStorage.Key<T>): ReadWriteProperty<OWNER, T?>
A property delegate for the given key.
fun <OWNER, T : Any> KeyValueStorage.property(key: KeyValueStorage.Key<T>, defaultValue: T): ReadWriteProperty<OWNER, T>
A property delegate for the given key.