aboutsummaryrefslogtreecommitdiff
path: root/crypto-pgpainless/src/test/kotlin/app
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2023-07-05 02:36:05 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2023-07-05 02:36:05 +0530
commit66a9c884486d016dceabeee8b929dc31696bd23a (patch)
treeb4dc64ae236aa6dff5fb8d23e121ba4a5a8e9285 /crypto-pgpainless/src/test/kotlin/app
parent496a1c4cb77743f724ccd3414115f92291345dbd (diff)
feat(crypto-pgpainless): add `KeyUtils#isKeyUsable`
Diffstat (limited to 'crypto-pgpainless/src/test/kotlin/app')
-rw-r--r--crypto-pgpainless/src/test/kotlin/app/passwordstore/crypto/KeyUtilsTest.kt12
-rw-r--r--crypto-pgpainless/src/test/kotlin/app/passwordstore/crypto/TestUtils.kt13
2 files changed, 25 insertions, 0 deletions
diff --git a/crypto-pgpainless/src/test/kotlin/app/passwordstore/crypto/KeyUtilsTest.kt b/crypto-pgpainless/src/test/kotlin/app/passwordstore/crypto/KeyUtilsTest.kt
index 39af53b1..f8e4218e 100644
--- a/crypto-pgpainless/src/test/kotlin/app/passwordstore/crypto/KeyUtilsTest.kt
+++ b/crypto-pgpainless/src/test/kotlin/app/passwordstore/crypto/KeyUtilsTest.kt
@@ -1,7 +1,9 @@
package app.passwordstore.crypto
+import app.passwordstore.crypto.KeyUtils.isKeyUsable
import app.passwordstore.crypto.KeyUtils.tryGetId
import app.passwordstore.crypto.KeyUtils.tryParseKeyring
+import app.passwordstore.crypto.TestUtils.AllKeys
import app.passwordstore.crypto.TestUtils.getArmoredSecretKeyWithMultipleIdentities
import kotlin.test.Test
import kotlin.test.assertEquals
@@ -21,4 +23,14 @@ class KeyUtilsTest {
assertIs<PGPIdentifier.KeyId>(keyId)
assertEquals("b950ae2813841585", keyId.toString())
}
+
+ @OptIn(ExperimentalStdlibApi::class)
+ @Test
+ fun isKeyUsable() {
+ val params = AllKeys.entries.map { it to (it != AllKeys.AEAD_PUB && it != AllKeys.AEAD_SEC) }
+ params.forEach { (allKeys, isUsable) ->
+ val key = PGPKey(allKeys.keyMaterial)
+ assertEquals(isUsable, isKeyUsable(key), "${allKeys.name} failed expectation:")
+ }
+ }
}
diff --git a/crypto-pgpainless/src/test/kotlin/app/passwordstore/crypto/TestUtils.kt b/crypto-pgpainless/src/test/kotlin/app/passwordstore/crypto/TestUtils.kt
index 96614ee9..90b98ac9 100644
--- a/crypto-pgpainless/src/test/kotlin/app/passwordstore/crypto/TestUtils.kt
+++ b/crypto-pgpainless/src/test/kotlin/app/passwordstore/crypto/TestUtils.kt
@@ -16,4 +16,17 @@ object TestUtils {
fun getArmoredPublicKeyWithMultipleIdentities() =
this::class.java.classLoader.getResource("public_key_multiple_identities").readBytes()
+
+ fun getAEADPublicKey() = this::class.java.classLoader.getResource("aead_pub").readBytes()
+
+ fun getAEADSecretKey() = this::class.java.classLoader.getResource("aead_sec").readBytes()
+
+ enum class AllKeys(val keyMaterial: ByteArray) {
+ ARMORED_SEC(getArmoredSecretKey()),
+ ARMORED_PUB(getArmoredPublicKey()),
+ MULTIPLE_IDENTITIES_SEC(getArmoredSecretKeyWithMultipleIdentities()),
+ MULTIPLE_IDENTITIES_PUB(getArmoredPublicKeyWithMultipleIdentities()),
+ AEAD_SEC(getAEADSecretKey()),
+ AEAD_PUB(getAEADPublicKey()),
+ }
}