InMemoryDeviceKeyStore

A DeviceKeyStore that keeps everything in memory, and forgets everything with the process.

Its key is made in software on the first deviceKey call and is gone when the process ends, so a device using this store is a new device every time the app starts: nothing it was granted, and no seat it held, can be recognised after a restart. That is right for tests and for an app that has chosen not to be recognised; an app that wants to be remembered uses a platform store.

Safe under a multi-threaded dispatcher: one Mutex guards the key and the grants, and is held across the first key's generation, so concurrent first calls wait for that one key rather than each making their own.

Constructors

Link copied to clipboard
constructor()

A store whose key, made on first use, is DeviceKey.generate's.

constructor(scheme: KeyScheme)

A store whose key, made on first use, is scheme's, and whose keyScheme is scheme, with the same grant rules as every other store. It takes any scheme: the opt-in is the only fence.

Properties

Link copied to clipboard
open override val keyScheme: KeyScheme

The scheme a room built on this store signs and checks every signature with: KeyScheme.P256, ECDSA through the platform's provider, unless the store was built for tests.

Functions

Link copied to clipboard
open suspend override fun deviceKey(): DeviceKey

This device's key: created on first call, the same on every call after.

Link copied to clipboard
open suspend override fun grants(): List<Grant>

The grants this device holds: the newest per issuer and scope, but for a post-dated one a fresh pass replaced (keepFreshGrant). Not secret — useless without the key.

Link copied to clipboard
open suspend override fun keepFreshGrant(grant: Grant)

Keeps grant as keepGrant does, with one exception: a held grant from the same issuer for the same scope dated more than GrantTrust.CLOCK_SKEW_ALLOWANCE_MILLIS after grant gives way to it, although grant is older (identity Task 2.5, #3221).

Link copied to clipboard
open suspend override fun keepGrant(grant: Grant)

Keeps grant, replacing the one held from the same Grant.issuer for the same Grant.scope when grant is newer by Grant.issuedAt. One host key can host many rooms, so a pass into Room("A") and one into Room("B") from the same issuer are both kept, and so is a grant from another issuer. A grant that is not newer — older, or issued at the same instant — is ignored, so a replayed or reordered copy can never displace the grant already held (Decided 21).