summaryrefslogtreecommitdiff
path: root/crypto-common/src/main
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2022-01-18 17:40:16 +0530
committerGitHub <noreply@github.com>2022-01-18 17:40:16 +0530
commit5509558eedbcd90f130b32d4e6c41632da291b15 (patch)
tree7b6839928889698ebe0da48a83b2e1532ed6d094 /crypto-common/src/main
parent3ead6596ba9c2b65434f6cd948bf6ebf41a230eb (diff)
Parameterize key and key identifier types for KeyManager (#1669)
Diffstat (limited to 'crypto-common/src/main')
-rw-r--r--crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/CryptoException.kt2
-rw-r--r--crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/CryptoHandler.kt2
-rw-r--r--crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/Key.kt14
-rw-r--r--crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/KeyManager.kt6
4 files changed, 5 insertions, 19 deletions
diff --git a/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/CryptoException.kt b/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/CryptoException.kt
index 431cd90c..42429a14 100644
--- a/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/CryptoException.kt
+++ b/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/CryptoException.kt
@@ -15,7 +15,7 @@ public sealed class KeyManagerException(message: String? = null) : CryptoExcepti
/** Failed to delete given key. */
public object KeyDeletionFailedException : KeyManagerException("Couldn't delete the key file")
- /** Failed to parse a [Key] as a known type. */
+ /** Failed to parse the key as a known type. */
public object InvalidKeyException :
KeyManagerException("Given key cannot be parsed as a known key type")
diff --git a/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/CryptoHandler.kt b/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/CryptoHandler.kt
index eb04ee7a..fc4c500d 100644
--- a/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/CryptoHandler.kt
+++ b/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/CryptoHandler.kt
@@ -9,7 +9,7 @@ import java.io.InputStream
import java.io.OutputStream
/** Generic interface to implement cryptographic operations on top of. */
-public interface CryptoHandler {
+public interface CryptoHandler<Key> {
/**
* Decrypt the given [ciphertextStream] using a [privateKey] and [passphrase], and writes the
diff --git a/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/Key.kt b/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/Key.kt
deleted file mode 100644
index 73dee199..00000000
--- a/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/Key.kt
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-package dev.msfjarvis.aps.crypto
-
-/**
- * A simple value class wrapping over a [ByteArray] that can be used as a key type for cryptographic
- * purposes. The public/private distinction is elided specifically to defer that decision to
- * implementations of [KeyManager]. Similarly, identification of the key's identities is also
- * deferred to [KeyManager] to ensure maximum flexibility.
- */
-@JvmInline public value class Key(public val contents: ByteArray)
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 dacdfc6a..aa71abf6 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
@@ -12,7 +12,7 @@ import com.github.michaelbull.result.Result
* used by an implementation of [CryptoHandler] to obtain eligible public or private keys as
* required.
*/
-public interface KeyManager {
+public interface KeyManager<Key, KeyIdentifier> {
/**
* Inserts a [key] into the store. If the key already exists, this method will return
@@ -28,7 +28,7 @@ public interface KeyManager {
* 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>
+ public suspend fun getKeyById(id: KeyIdentifier): Result<Key, Throwable>
/** Returns all keys currently in the store as a [List]. */
public suspend fun getAllKeys(): Result<List<Key>, Throwable>
@@ -37,7 +37,7 @@ public interface KeyManager {
* 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?
+ public suspend fun getKeyId(key: Key): KeyIdentifier?
/** Given a [fileName], return whether this instance can handle it. */
public fun canHandle(fileName: String): Boolean