summaryrefslogtreecommitdiff
path: root/crypto-pgpainless/src/test/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'crypto-pgpainless/src/test/kotlin')
-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()),
+ }
}