aboutsummaryrefslogtreecommitdiffstats
path: root/crypto-common/src/main/kotlin/app/passwordstore/crypto/CryptoHandler.kt
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2022-07-15 00:53:48 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2022-07-15 01:13:47 +0530
commit549ee790d3e52bc62565ddf92e6a556e98b5195e (patch)
treed5758e5eb80093704e683c8da926838e18182588 /crypto-common/src/main/kotlin/app/passwordstore/crypto/CryptoHandler.kt
parent010c6e227c9cc27f4d01bc912311f977b2aeb3a7 (diff)
downloadHardenedPass-549ee790d3e52bc62565ddf92e6a556e98b5195e.tar.gz
HardenedPass-549ee790d3e52bc62565ddf92e6a556e98b5195e.zip
all: re-do package structure yet again
Diffstat (limited to 'crypto-common/src/main/kotlin/app/passwordstore/crypto/CryptoHandler.kt')
-rw-r--r--crypto-common/src/main/kotlin/app/passwordstore/crypto/CryptoHandler.kt42
1 files changed, 42 insertions, 0 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
new file mode 100644
index 00000000..952f4a7e
--- /dev/null
+++ b/crypto-common/src/main/kotlin/app/passwordstore/crypto/CryptoHandler.kt
@@ -0,0 +1,42 @@
+/*
+ * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+package app.passwordstore.crypto
+
+import app.passwordstore.crypto.errors.CryptoHandlerException
+import com.github.michaelbull.result.Result
+import java.io.InputStream
+import java.io.OutputStream
+
+/** Generic interface to implement cryptographic operations on top of. */
+public interface CryptoHandler<Key> {
+
+ /**
+ * Decrypt the given [ciphertextStream] using a [privateKey] and [passphrase], and writes the
+ * resultant plaintext to [outputStream]. The returned [Result] should be checked to ensure it is
+ * **not** an instance of [com.github.michaelbull.result.Err] before the contents of
+ * [outputStream] are used.
+ */
+ public fun decrypt(
+ privateKey: Key,
+ passphrase: String,
+ ciphertextStream: InputStream,
+ outputStream: OutputStream,
+ ): Result<Unit, CryptoHandlerException>
+
+ /**
+ * Encrypt the given [plaintextStream] to the provided [keys], and writes the encrypted ciphertext
+ * to [outputStream]. The returned [Result] should be checked to ensure it is **not** an instance
+ * of [com.github.michaelbull.result.Err] before the contents of [outputStream] are used.
+ */
+ public fun encrypt(
+ keys: List<Key>,
+ plaintextStream: InputStream,
+ outputStream: OutputStream,
+ ): Result<Unit, CryptoHandlerException>
+
+ /** Given a [fileName], return whether this instance can handle it. */
+ public fun canHandle(fileName: String): Boolean
+}