KeyListViewModel

class KeyListViewModel @Inject constructor(keyRepository: KeyRepository, cryptoOperations: CryptoOperations, settingsRepository: SettingsRepository) : ViewModel

ViewModel backing the key list and key detail screens.

Exposes the observable key list plus loading/error state, and coordinates all mutating key operations against the repository and CryptoOperations. Every passphrase CharArray is zeroed once the corresponding operation completes.

Constructors

Link copied to clipboard
@Inject
constructor(keyRepository: KeyRepository, cryptoOperations: CryptoOperations, settingsRepository: SettingsRepository)

Properties

Link copied to clipboard
val error: StateFlow<String?>
Link copied to clipboard
val isLoading: StateFlow<Boolean>
Link copied to clipboard
val keys: StateFlow<List<KeySummary>>
Link copied to clipboard

Functions

Link copied to clipboard
open fun addCloseable(closeable: AutoCloseable)
fun addCloseable(key: String, closeable: AutoCloseable)
Link copied to clipboard
fun addSubkey(keyId: Long, passphrase: CharArray, subkeyType: SubkeyType, rsaBits: Int, onDone: () -> Unit)

Adds a subkey of subkeyType to the secret key keyId and persists the updated public/secret rings. The passphrase is wiped on completion.

Link copied to clipboard
fun addUserId(keyId: Long, passphrase: CharArray, userId: String, onDone: () -> Unit)

Adds a new userId to the key keyId; the passphrase is wiped on completion.

Link copied to clipboard
fun certifyKey(certifierKeyId: Long, targetKeyId: Long, passphrase: CharArray, userId: String, onDone: () -> Unit)

Signs (certifies) the userId of targetKeyId using certifierKeyId. The passphrase is wiped on completion.

Link copied to clipboard
fun changePassphrase(keyId: Long, oldPassphrase: CharArray, newPassphrase: CharArray, onDone: () -> Unit)

Re-encrypts the secret key keyId from oldPassphrase to newPassphrase. Both passphrase arrays are wiped on completion.

Link copied to clipboard

Clears the current error message.

Link copied to clipboard
fun createKey(userId: String, passphrase: CharArray, algorithmType: KeyAlgorithmType, rsaBits: Int, onDone: () -> Unit)

Generates a new key ring for userId and imports it into the repository. The passphrase is wiped on completion; onDone runs on success.

Link copied to clipboard
fun deleteKey(keyId: Long, onDone: () -> Unit? = null)

Permanently deletes the key ring identified by keyId.

Link copied to clipboard
fun exportRevocationCert(keyId: Long, passphrase: CharArray, reasonText: String, onDone: (ByteArray) -> Unit)

Generates a revocation certificate for keyId with the given reasonText and delivers the armored bytes via onDone. The passphrase is wiped after.

Link copied to clipboard
Link copied to clipboard
fun importArmored(armored: String, secret: Boolean, onDone: () -> Unit)

Imports an ASCII-armored key ring; secret marks it as a secret import.

Link copied to clipboard
fun importFromBytes(bytes: ByteArray, secret: Boolean, onDone: () -> Unit)

Imports a key ring from raw bytes; secret marks it as a secret import.

Link copied to clipboard
fun refreshAllFromKeyserver(onDone: (Int) -> Unit)

Refreshes all keys from the keyserver, reporting the success count via onDone.

Link copied to clipboard
fun refreshFromKeyserver(keyId: Long, onDone: () -> Unit)

Refreshes a single key keyId from the configured keyserver.

Link copied to clipboard
fun reportError(message: String)

Surfaces an externally produced error message to the UI.

Link copied to clipboard
fun revokeKey(keyId: Long)

Marks the key ring identified by keyId as revoked.

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

Updates the local owner-trust level for keyId.

Link copied to clipboard
fun uploadPublicKey(keyId: Long, onDone: () -> Unit)

Publishes the public key keyId to the configured keyserver.