DeviceKeyStoreFixture

sealed interface DeviceKeyStoreFixture

How a DeviceKeyStoreConformanceSuite reaches the store under test, and what its medium can suffer.

Every arm opens a store through open(beforeKeyIsMade). The store must call beforeKeyIsMade each time it is about to make a key — the first one, and every replacement — and at no other time. It is how the suite counts the keys a store makes and forces concurrent first calls to overlap, so a store takes it through an internal constructor or factory, and its public entry points pass a no-op.

Why this is two-armed and not nullable

InMemoryDeviceKeyStore has no medium: it cannot survive a restart, and so cannot suffer a corrupt key, a mismatched pair, a cleared item or a crash between writes. That is correct rather than a gap, and its own KDoc says so. Nullable damage hooks would express it, and would let a durable store whose damage handling was broken opt out the same way, so the suite would report nothing. A sealed pair makes the medium a decision the subclass states once, and makes each arm checkable: Durable must keep its key across a restart and survive every damage hook, while KeepsNothing must forget across a restart, so a durable store that declared it fails just as loudly. Every damage hook on Durable is non-nullable for the same reason.

What the arms cannot detect

KeepsNothing proves only that a restart is a new device. It proves nothing about keeping a key, because there is nothing to keep. Durable cannot tell a genuine reopen from a thin wrapper that delegates every call to the original store, though it does assert the reopened store and key are new objects that made no key; and it cannot tell stable storage from a page cache.

Inheritors

Types

Link copied to clipboard
class Durable(reopen: suspend (beforeKeyIsMade: suspend () -> Unit) -> DeviceKeyStore, val corruptKey: suspend () -> Unit, val plantMismatchedKey: suspend () -> DidKey, val clearKey: suspend () -> Unit, val interruptKeyWrite: suspend () -> DeviceKeyStoreFixture.KeyWriteInterruption, val corruptGrants: suspend () -> Unit, val makeKeyUnreadable: suspend () -> DeviceKeyStoreFixture.UnreadableKey, val makeGrantsUnreadable: suspend () -> DeviceKeyStoreFixture.UnreadableGrants) : DeviceKeyStoreFixture

A store over a medium that outlives the process. Each open is a restart: a new store over the same medium, sharing no memory with the stores opened before it.

Link copied to clipboard
class KeepsNothing(start: suspend (beforeKeyIsMade: suspend () -> Unit) -> DeviceKeyStore) : DeviceKeyStoreFixture

A store with no medium. Each open is a new process: a new device, holding no grants.

Link copied to clipboard
sealed interface KeyWriteInterruption

What Durable.interruptKeyWrite left behind: residue a crash would leave, or a statement that this medium writes a key in one step and leaves none.

Link copied to clipboard
class UnreadableGrants(val probe: suspend () -> Unit, val probeWrite: suspend () -> Unit, val restore: suspend () -> Boolean)

What Durable.makeGrantsUnreadable did: the grants record is out of reach until restore runs.

Link copied to clipboard
sealed interface UnreadableKey

What Durable.makeKeyUnreadable did: put the key out of reach, or say why this medium never can.

Functions

Link copied to clipboard
abstract suspend fun open(beforeKeyIsMade: suspend () -> Unit): DeviceKeyStore

Opens a store over this fixture's medium; see DeviceKeyStoreFixture for beforeKeyIsMade.