CryptoViewModel

class CryptoViewModel @Inject constructor(keyRepository: KeyRepository, cryptoOperations: CryptoOperations) : ViewModel

ViewModel backing the crypto screen.

Exposes an observable CryptoUiState and the live key list, and drives all encrypt/decrypt/sign/verify operations for text, file and folder payloads. Heavy work runs on background dispatchers; passphrase char arrays are wiped after each operation.

Constructors

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

Properties

Link copied to clipboard
val keys: StateFlow<List<KeySummary>>
Link copied to clipboard
val uiState: StateFlow<CryptoUiState>

Functions

Link copied to clipboard
open fun addCloseable(closeable: AutoCloseable)
fun addCloseable(key: String, closeable: AutoCloseable)
Link copied to clipboard

Clears any produced output file.

Link copied to clipboard
fun decrypt()

Decrypts the current text (or delegates to decryptFile for files).

Link copied to clipboard

Decrypts the selected encrypted file using the chosen secret key.

Link copied to clipboard
fun encrypt()

Encrypts the current payload according to the active CryptoPayload.

Link copied to clipboard

Encrypts the selected input file to the chosen recipients.

Link copied to clipboard

Packs the selected files into a tar archive and encrypts it.

Link copied to clipboard
Link copied to clipboard

Reacts to a mode change, downgrading FOLDER payloads for non-encrypt modes.

Link copied to clipboard
fun selectSecretKey(keyId: Long)

Selects the secret key used for decrypt/sign operations.

Link copied to clipboard
fun setCiphertext(value: String)

Updates the ciphertext input.

Link copied to clipboard

Sets the files for folder encryption, enforcing the total size limit.

Link copied to clipboard
fun setInputFile(name: String, bytes: ByteArray)

Sets the selected input file, enforcing the maximum stream size.

Link copied to clipboard
fun setPassphrase(value: String)

Updates the passphrase input.

Link copied to clipboard

Switches the active payload type and clears any file/output state.

Link copied to clipboard
fun setPlaintext(value: String)

Updates the plaintext input.

Link copied to clipboard

Replaces the set of recipient key ids.

Link copied to clipboard
fun setSignatureFile(name: String, bytes: ByteArray)

Sets the detached signature file used for verification.

Link copied to clipboard

Updates the signed-text input and resets any prior verification result.

Link copied to clipboard
fun sign()

Clear-signs the current text (or delegates to signFile for files).

Link copied to clipboard
fun signFile()

Produces a detached binary signature for the selected file.

Link copied to clipboard
fun toggleRecipient(keyId: Long)

Adds or removes keyId from the recipient set.

Link copied to clipboard
fun verify()

Verifies the signed text (or delegates to verifyFile for files).

Link copied to clipboard

Verifies a detached signature against the selected signed file.