diff options
| author | Harsh Shandilya <me@msfjarvis.dev> | 2022-07-15 00:53:48 +0530 |
|---|---|---|
| committer | Harsh Shandilya <me@msfjarvis.dev> | 2022-07-15 01:13:47 +0530 |
| commit | 549ee790d3e52bc62565ddf92e6a556e98b5195e (patch) | |
| tree | d5758e5eb80093704e683c8da926838e18182588 /crypto-pgpainless/src/test/kotlin/dev/msfjarvis/aps/crypto/PGPainlessCryptoHandlerTest.kt | |
| parent | 010c6e227c9cc27f4d01bc912311f977b2aeb3a7 (diff) | |
| download | HardenedPass-549ee790d3e52bc62565ddf92e6a556e98b5195e.tar.gz HardenedPass-549ee790d3e52bc62565ddf92e6a556e98b5195e.zip | |
all: re-do package structure yet again
Diffstat (limited to 'crypto-pgpainless/src/test/kotlin/dev/msfjarvis/aps/crypto/PGPainlessCryptoHandlerTest.kt')
| -rw-r--r-- | crypto-pgpainless/src/test/kotlin/dev/msfjarvis/aps/crypto/PGPainlessCryptoHandlerTest.kt | 78 |
1 files changed, 0 insertions, 78 deletions
diff --git a/crypto-pgpainless/src/test/kotlin/dev/msfjarvis/aps/crypto/PGPainlessCryptoHandlerTest.kt b/crypto-pgpainless/src/test/kotlin/dev/msfjarvis/aps/crypto/PGPainlessCryptoHandlerTest.kt deleted file mode 100644 index e39bc06e..00000000 --- a/crypto-pgpainless/src/test/kotlin/dev/msfjarvis/aps/crypto/PGPainlessCryptoHandlerTest.kt +++ /dev/null @@ -1,78 +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 - -import com.github.michaelbull.result.Err -import com.github.michaelbull.result.getError -import com.google.testing.junit.testparameterinjector.TestParameter -import com.google.testing.junit.testparameterinjector.TestParameterInjector -import dev.msfjarvis.aps.crypto.errors.IncorrectPassphraseException -import java.io.ByteArrayOutputStream -import kotlin.test.Test -import kotlin.test.assertEquals -import kotlin.test.assertFalse -import kotlin.test.assertIs -import kotlin.test.assertTrue -import org.junit.runner.RunWith - -@Suppress("Unused") // Test runner handles it internally -enum class EncryptionKey(val key: PGPKey) { - PUBLIC(PGPKey(TestUtils.getArmoredPublicKey())), - SECRET(PGPKey(TestUtils.getArmoredPrivateKey())), -} - -@RunWith(TestParameterInjector::class) -class PGPainlessCryptoHandlerTest { - - @TestParameter private lateinit var encryptionKey: EncryptionKey - private val cryptoHandler = PGPainlessCryptoHandler() - private val privateKey = PGPKey(TestUtils.getArmoredPrivateKey()) - - @Test - fun encryptAndDecrypt() { - val ciphertextStream = ByteArrayOutputStream() - cryptoHandler.encrypt( - listOf(encryptionKey.key), - CryptoConstants.PLAIN_TEXT.byteInputStream(Charsets.UTF_8), - ciphertextStream, - ) - val plaintextStream = ByteArrayOutputStream() - cryptoHandler.decrypt( - privateKey, - CryptoConstants.KEY_PASSPHRASE, - ciphertextStream.toByteArray().inputStream(), - plaintextStream, - ) - assertEquals(CryptoConstants.PLAIN_TEXT, plaintextStream.toString(Charsets.UTF_8)) - } - - @Test - fun decryptWithWrongPassphrase() { - val ciphertextStream = ByteArrayOutputStream() - cryptoHandler.encrypt( - listOf(encryptionKey.key), - CryptoConstants.PLAIN_TEXT.byteInputStream(Charsets.UTF_8), - ciphertextStream, - ) - val plaintextStream = ByteArrayOutputStream() - val result = - cryptoHandler.decrypt( - privateKey, - "very incorrect passphrase", - ciphertextStream.toByteArray().inputStream(), - plaintextStream, - ) - assertIs<Err<Throwable>>(result) - assertIs<IncorrectPassphraseException>(result.getError()) - } - - @Test - fun canHandleFiltersFormats() { - assertFalse { cryptoHandler.canHandle("example.com") } - assertTrue { cryptoHandler.canHandle("example.com.gpg") } - assertFalse { cryptoHandler.canHandle("example.com.asc") } - } -} |
