Add KDoc to the libraries/cryptography API interfaces

Document the members of SecretKeyRepository and EncryptionDecryptionService.

The caveat worth having in the API doc comes from KeyStoreSecretKeyRepository:
requiresUserAuthentication only takes effect when the key is created, so an
existing key keeps whatever protection it was created with.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Benoit Marty
2026-08-14 11:51:32 +02:00
parent b683c62d8f
commit d713017afe
2 changed files with 34 additions and 0 deletions
@@ -15,8 +15,35 @@ import javax.crypto.SecretKey
* Simple service to provide encryption and decryption operations.
*/
interface EncryptionDecryptionService {
/**
* Creates a cipher ready to encrypt, for the callers that need the cipher itself, such as to bind it to a biometric prompt.
*
* @param key the key to encrypt with.
*/
fun createEncryptionCipher(key: SecretKey): Cipher
/**
* Creates a cipher ready to decrypt, for the callers that need the cipher itself.
*
* @param key the key to decrypt with.
* @param initializationVector the vector produced when the data was encrypted.
*/
fun createDecryptionCipher(key: SecretKey, initializationVector: ByteArray): Cipher
/**
* Encrypts data in one call.
*
* @param key the key to encrypt with.
* @param input the plaintext bytes.
* @return the ciphertext along with the initialization vector needed to decrypt it.
*/
fun encrypt(key: SecretKey, input: ByteArray): EncryptionResult
/**
* Decrypts data in one call.
*
* @param key the key the data was encrypted with.
* @param encryptionResult the ciphertext and its initialization vector, as returned by [encrypt].
*/
fun decrypt(key: SecretKey, encryptionResult: EncryptionResult): ByteArray
}
@@ -16,10 +16,17 @@ import javax.crypto.SecretKey
* Implementation should be able to store the generated key securely.
*/
interface SecretKeyRepository {
/**
* Whether a key exists for the given alias, re-emitted when it is created or deleted.
*
* @param alias the alias to watch.
*/
fun hasKey(alias: String): Flow<Boolean>
/**
* Get or create a secret key for a given alias.
* Note that [requiresUserAuthentication] only applies when the key is created: an existing key keeps the protection it was created with.
*
* @param alias the alias to use
* @param requiresUserAuthentication true if the key should be protected by user authentication
*/