diff options
| author | Harsh Shandilya <me@msfjarvis.dev> | 2022-01-09 15:37:45 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-09 10:07:45 +0000 |
| commit | ccb33af854132f1b35b71393ff68d24850de6960 (patch) | |
| tree | 52e71e7ca560194d863b7c823385271e42eea7d0 /crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/KeyManager.kt | |
| parent | 6c6ade85a8696142b5fc13df9034f73b4089c912 (diff) | |
| download | HardenedPass-ccb33af854132f1b35b71393ff68d24850de6960.tar.gz HardenedPass-ccb33af854132f1b35b71393ff68d24850de6960.zip | |
Refactor and simplify KeyManager API (#1650)
Diffstat (limited to 'crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/KeyManager.kt')
| -rw-r--r-- | crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/KeyManager.kt | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/KeyManager.kt b/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/KeyManager.kt index 2f901354..dacdfc6a 100644 --- a/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/KeyManager.kt +++ b/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/KeyManager.kt @@ -7,12 +7,37 @@ package dev.msfjarvis.aps.crypto import com.github.michaelbull.result.Result -public interface KeyManager<T : KeyPair> { +/** + * [KeyManager] defines a contract for implementing a management system for [Key]s as they would be + * used by an implementation of [CryptoHandler] to obtain eligible public or private keys as + * required. + */ +public interface KeyManager { + + /** + * Inserts a [key] into the store. If the key already exists, this method will return + * [KeyManagerException.KeyAlreadyExistsException] unless [replace] is `true`. + */ + public suspend fun addKey(key: Key, replace: Boolean = false): Result<Key, Throwable> + + /** Removes [key] from the store. */ + public suspend fun removeKey(key: Key): Result<Key, Throwable> + + /** + * Get a [Key] for the given [id]. The actual semantics of what [id] is are left to individual + * implementations to figure out for themselves. For example, in GPG this can be a full + * hexadecimal key ID, an email, a short hex key ID, and probably a few more things. + */ + public suspend fun getKeyById(id: String): Result<Key, Throwable> + + /** Returns all keys currently in the store as a [List]. */ + public suspend fun getAllKeys(): Result<List<Key>, Throwable> - public suspend fun addKey(key: T, replace: Boolean = false): Result<T, Throwable> - public suspend fun removeKey(key: T): Result<T, Throwable> - public suspend fun getKeyById(id: String): Result<T, Throwable> - public suspend fun getAllKeys(): Result<List<T>, Throwable> + /** + * Get a stable identifier for the given [key]. The returned key ID should be suitable to be used + * as an identifier for the cryptographic identity tied to this key. + */ + public suspend fun getKeyId(key: Key): String? /** Given a [fileName], return whether this instance can handle it. */ public fun canHandle(fileName: String): Boolean |
