KeyRepository

interface KeyRepository

Domain repository for PGP key ring lifecycle: import, export, certification, keyserver sync, and trust management.

Combines Room metadata, encrypted blob storage, and the PGP engine. UI and service layers depend on this interface rather than KeyRepositoryImpl.

Inheritors

Functions

Link copied to clipboard
abstract suspend fun addUserId(keyId: Long, passphrase: CharArray, userId: String)

Adds a user id to a secret key ring and re-persists blobs and uid rows.

Link copied to clipboard
abstract suspend fun certifyKey(certifierKeyId: Long, targetKeyId: Long, certifierPassphrase: CharArray, userId: String): ByteArray

Certifies targetKeyId with certifierKeyId and embeds the signature in stored public material.

Link copied to clipboard
abstract suspend fun changePassphrase(keyId: Long, newSecretArmored: ByteArray)

Convenience wrapper around replaceSecretKeyRing after passphrase change.

Link copied to clipboard
abstract suspend fun deleteKey(keyId: Long)

Deletes database rows and removes associated blob files.

Link copied to clipboard
abstract suspend fun exportKeyRing(keyId: Long): ByteArray

Returns the raw armored blob (secret or public) for keyId.

Link copied to clipboard
abstract suspend fun generateRevocationCert(keyId: Long, passphrase: CharArray, reasonText: String = ""): ByteArray

Generates an armored revocation certificate for keyId.

Link copied to clipboard
abstract suspend fun getArmoredPublic(keyId: Long): ByteArray?

Returns armored public key bytes, deriving from secret if no public blob exists.

Link copied to clipboard
abstract suspend fun getArmoredSecret(keyId: Long): ByteArray?

Returns armored secret key bytes, or null if not a secret key or missing.

Link copied to clipboard
abstract suspend fun getKeyDetail(keyId: Long): KeyDetail?

Loads key detail and subkeys, or null if missing or blob is unreadable.

Link copied to clipboard
abstract suspend fun importGeneratedKeyRing(publicArmored: ByteArray, secretArmored: ByteArray, primaryAlgorithm: String): KeyRingInfo

Persists a newly generated key pair (separate public and secret armored blocks).

Link copied to clipboard
abstract suspend fun importKeyRing(armored: ByteArray, secret: Boolean): KeyRingInfo

Imports an armored key ring from file or clipboard.

Link copied to clipboard
abstract fun observeKeys(): Flow<List<KeySummary>>

Observes all stored keys with primary user ids, ordered by creation time.

Link copied to clipboard
abstract suspend fun purgeMissingBlobKeys(): Int

Removes database entries whose blob files are missing from disk.

Link copied to clipboard
abstract suspend fun refreshKeyFromKeyserver(keyId: Long, baseUrl: String): KeyRingInfo

Refreshes public key material from a keyserver and updates metadata.

Link copied to clipboard
abstract suspend fun replaceSecretKeyRing(keyId: Long, secretArmored: ByteArray, publicArmored: ByteArray)

Replaces on-disk secret and public blobs after passphrase or uid changes.

Link copied to clipboard
abstract suspend fun revokeKey(keyId: Long)

Marks keyId as revoked in local metadata (does not rewrite the blob).

Link copied to clipboard
abstract suspend fun search(query: String): List<KeySummary>

Searches keys by fingerprint fragment.

Link copied to clipboard
abstract suspend fun setTrustLevel(keyId: Long, trustLevel: Int)

Sets local trust level (0–3) for keyId.

Link copied to clipboard
abstract suspend fun uploadPublicKey(keyId: Long, baseUrl: String)

Uploads the public key for keyId to baseUrl.