StaticStorageKeyProvider

A StorageKeyProvider over keys the application already holds, for example keys it loaded from its own secret store, and for tests. loadOrCreateKey returns current and never creates a key; createKey only returns a key that was passed in. removeKey forgets the key in this instance; deleting its copy is up to the application. The keys only live in memory; this class is not secure key storage.

Constructors

Link copied to clipboard
constructor(current: StorageEncryptionKey, vararg others: StorageEncryptionKey)

Functions

Link copied to clipboard
open suspend override fun createKey(id: StorageKeyId): StorageEncryptionKey

Creates key id for a storage key rotation and returns it once it is persisted and read back. If the provider already has key id, returns that key unchanged: a key is never overwritten or replaced, so a repeated or concurrent call yields the same key. Other keys are not touched. Throws StorageEncryptionException.KeyUnavailable if the provider holds no key yet (rotation needs provisioned storage) or its state cannot be read; nothing is changed then.

Link copied to clipboard
open suspend override fun hasKeys(): Boolean

Always true: the application passed at least current.

Link copied to clipboard
open suspend override fun key(id: StorageKeyId): StorageEncryptionKey?

The existing key id, or null if the provider does not have it. Never creates a key: this is called for storage that is already encrypted with id.

Link copied to clipboard
open suspend override fun loadOrCreateKey(): StorageEncryptionKey

The key for storage that has no key bound yet: a new database, or a database from before record encryption that is about to be encrypted. Returns the provider's only key, or creates and persists key ID 1 if the provider has none. Throws StorageEncryptionException.KeyUnavailable if the provider holds several keys (its namespace belongs to a database in or after a storage key rotation) or no key can be provided.

Link copied to clipboard
open suspend override fun removeKey(id: StorageKeyId): Boolean

Removes key id, for retiring a storage key after a rotation proved that no record uses it. Returns true if this call removed it and false if the provider did not have it. Other keys are not touched. Throws IllegalStateException and changes nothing if id is the provider's last key: a provider never removes all of its keys.