aboutsummaryrefslogtreecommitdiff
path: root/crypto-common/src
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2022-10-29 04:36:00 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2022-10-29 04:36:00 +0530
commit633cbe271460980ff18a350fb6b7864a424ec83a (patch)
treebe3560a97823f02316ad8d220c0b53ce893a99c9 /crypto-common/src
parent390286f95fffdfad434f60a460fff21473fefc32 (diff)
feat(crypto-common): support passing arbitrary crypto options
Diffstat (limited to 'crypto-common/src')
-rw-r--r--crypto-common/src/main/kotlin/app/passwordstore/crypto/CryptoHandler.kt4
-rw-r--r--crypto-common/src/main/kotlin/app/passwordstore/crypto/CryptoOptions.kt8
2 files changed, 11 insertions, 1 deletions
diff --git a/crypto-common/src/main/kotlin/app/passwordstore/crypto/CryptoHandler.kt b/crypto-common/src/main/kotlin/app/passwordstore/crypto/CryptoHandler.kt
index ea42af6d..898cf058 100644
--- a/crypto-common/src/main/kotlin/app/passwordstore/crypto/CryptoHandler.kt
+++ b/crypto-common/src/main/kotlin/app/passwordstore/crypto/CryptoHandler.kt
@@ -11,7 +11,7 @@ import java.io.InputStream
import java.io.OutputStream
/** Generic interface to implement cryptographic operations on top of. */
-public interface CryptoHandler<Key> {
+public interface CryptoHandler<Key, EncOpts : CryptoOptions, DecryptOpts : CryptoOptions> {
/**
* Decrypt the given [ciphertextStream] using a set of potential [keys] and [passphrase], and
@@ -24,6 +24,7 @@ public interface CryptoHandler<Key> {
passphrase: String,
ciphertextStream: InputStream,
outputStream: OutputStream,
+ options: DecryptOpts,
): Result<Unit, CryptoHandlerException>
/**
@@ -35,6 +36,7 @@ public interface CryptoHandler<Key> {
keys: List<Key>,
plaintextStream: InputStream,
outputStream: OutputStream,
+ options: EncOpts,
): Result<Unit, CryptoHandlerException>
/** Given a [fileName], return whether this instance can handle it. */
diff --git a/crypto-common/src/main/kotlin/app/passwordstore/crypto/CryptoOptions.kt b/crypto-common/src/main/kotlin/app/passwordstore/crypto/CryptoOptions.kt
new file mode 100644
index 00000000..1e60cdba
--- /dev/null
+++ b/crypto-common/src/main/kotlin/app/passwordstore/crypto/CryptoOptions.kt
@@ -0,0 +1,8 @@
+package app.passwordstore.crypto
+
+/** Defines the contract for a grab-bag of options for individual cryptographic operations. */
+public interface CryptoOptions {
+
+ /** Returns a [Boolean] indicating if the [option] is enabled for this operation. */
+ public fun isOptionEnabled(option: String): Boolean
+}