aboutsummaryrefslogtreecommitdiff
path: root/crypto-pgpainless/src
diff options
context:
space:
mode:
Diffstat (limited to 'crypto-pgpainless/src')
-rw-r--r--crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/KeyUtils.kt4
-rw-r--r--crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPIdentifier.kt (renamed from crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/GpgIdentifier.kt)16
-rw-r--r--crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPKeyManager.kt12
-rw-r--r--crypto-pgpainless/src/test/kotlin/app/passwordstore/crypto/KeyUtilsTest.kt2
-rw-r--r--crypto-pgpainless/src/test/kotlin/app/passwordstore/crypto/PGPIdentifierTest.kt (renamed from crypto-pgpainless/src/test/kotlin/app/passwordstore/crypto/GpgIdentifierTest.kt)18
-rw-r--r--crypto-pgpainless/src/test/kotlin/app/passwordstore/crypto/PGPKeyManagerTest.kt4
6 files changed, 28 insertions, 28 deletions
diff --git a/crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/KeyUtils.kt b/crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/KeyUtils.kt
index da77bf33..3c36060f 100644
--- a/crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/KeyUtils.kt
+++ b/crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/KeyUtils.kt
@@ -5,8 +5,8 @@
package app.passwordstore.crypto
-import app.passwordstore.crypto.GpgIdentifier.KeyId
-import app.passwordstore.crypto.GpgIdentifier.UserId
+import app.passwordstore.crypto.PGPIdentifier.KeyId
+import app.passwordstore.crypto.PGPIdentifier.UserId
import com.github.michaelbull.result.get
import com.github.michaelbull.result.runCatching
import org.bouncycastle.openpgp.PGPKeyRing
diff --git a/crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/GpgIdentifier.kt b/crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPIdentifier.kt
index 96b9cc88..98a1de2e 100644
--- a/crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/GpgIdentifier.kt
+++ b/crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPIdentifier.kt
@@ -8,11 +8,11 @@ package app.passwordstore.crypto
import java.util.Locale
import java.util.regex.Pattern
-/** Supertype for valid identifiers of GPG keys. */
-public sealed class GpgIdentifier {
+/** Supertype for valid identifiers of PGP keys. */
+public sealed class PGPIdentifier {
- /** A [GpgIdentifier] that represents either a long key ID or a fingerprint. */
- public data class KeyId(val id: Long) : GpgIdentifier() {
+ /** A [PGPIdentifier] that represents either a long key ID or a fingerprint. */
+ public data class KeyId(val id: Long) : PGPIdentifier() {
override fun toString(): String {
return convertKeyIdToHex(id)
}
@@ -36,10 +36,10 @@ public sealed class GpgIdentifier {
}
/**
- * A [GpgIdentifier] that represents the textual name/email combination corresponding to a key.
+ * A [PGPIdentifier] that represents the textual name/email combination corresponding to a key.
* Despite the [email] property in this class, the value is not guaranteed to be a valid email.
*/
- public data class UserId(val email: String) : GpgIdentifier() {
+ public data class UserId(val email: String) : PGPIdentifier() {
override fun toString(): String {
return email
}
@@ -53,10 +53,10 @@ public sealed class GpgIdentifier {
private const val TRUNCATED_FINGERPRINT_LENGTH = 16
/**
- * Attempts to parse an untyped String identifier into a concrete subtype of [GpgIdentifier].
+ * Attempts to parse an untyped String identifier into a concrete subtype of [PGPIdentifier].
*/
@Suppress("ReturnCount")
- public fun fromString(identifier: String): GpgIdentifier? {
+ public fun fromString(identifier: String): PGPIdentifier? {
if (identifier.isEmpty()) return null
// Match long key IDs:
// FF22334455667788 or 0xFF22334455667788
diff --git a/crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPKeyManager.kt b/crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPKeyManager.kt
index f6ef50b3..a34d0379 100644
--- a/crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPKeyManager.kt
+++ b/crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPKeyManager.kt
@@ -32,7 +32,7 @@ public class PGPKeyManager
constructor(
filesDir: String,
private val dispatcher: CoroutineDispatcher,
-) : KeyManager<PGPKey, GpgIdentifier> {
+) : KeyManager<PGPKey, PGPIdentifier> {
private val keyDir = File(filesDir, KEY_DIR_NAME)
@@ -74,7 +74,7 @@ constructor(
}
/** @see KeyManager.removeKey */
- override suspend fun removeKey(identifier: GpgIdentifier): Result<Unit, Throwable> =
+ override suspend fun removeKey(identifier: PGPIdentifier): Result<Unit, Throwable> =
withContext(dispatcher) {
runSuspendCatching {
if (!keyDirExists()) throw KeyDirectoryUnavailableException
@@ -87,7 +87,7 @@ constructor(
}
/** @see KeyManager.getKeyById */
- override suspend fun getKeyById(id: GpgIdentifier): Result<PGPKey, Throwable> =
+ override suspend fun getKeyById(id: PGPIdentifier): Result<PGPKey, Throwable> =
withContext(dispatcher) {
runSuspendCatching {
if (!keyDirExists()) throw KeyDirectoryUnavailableException
@@ -97,14 +97,14 @@ constructor(
val matchResult =
when (id) {
- is GpgIdentifier.KeyId -> {
+ is PGPIdentifier.KeyId -> {
val keyIdMatch =
keys
.map { key -> key to tryGetId(key) }
.firstOrNull { (_, keyId) -> keyId?.id == id.id }
keyIdMatch?.first
}
- is GpgIdentifier.UserId -> {
+ is PGPIdentifier.UserId -> {
val selector = SelectUserId.byEmail(id.email)
val userIdMatch =
keys
@@ -134,7 +134,7 @@ constructor(
}
/** @see KeyManager.getKeyById */
- override suspend fun getKeyId(key: PGPKey): GpgIdentifier? = tryGetId(key)
+ override suspend fun getKeyId(key: PGPKey): PGPIdentifier? = tryGetId(key)
/** Checks if [keyDir] exists and attempts to create it if not. */
private fun keyDirExists(): Boolean {
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 f7bf46d9..39af53b1 100644
--- a/crypto-pgpainless/src/test/kotlin/app/passwordstore/crypto/KeyUtilsTest.kt
+++ b/crypto-pgpainless/src/test/kotlin/app/passwordstore/crypto/KeyUtilsTest.kt
@@ -18,7 +18,7 @@ class KeyUtilsTest {
assertIs<PGPSecretKeyRing>(keyring)
val keyId = tryGetId(key)
assertNotNull(keyId)
- assertIs<GpgIdentifier.KeyId>(keyId)
+ assertIs<PGPIdentifier.KeyId>(keyId)
assertEquals("b950ae2813841585", keyId.toString())
}
}
diff --git a/crypto-pgpainless/src/test/kotlin/app/passwordstore/crypto/GpgIdentifierTest.kt b/crypto-pgpainless/src/test/kotlin/app/passwordstore/crypto/PGPIdentifierTest.kt
index 009976a2..efc6e0ba 100644
--- a/crypto-pgpainless/src/test/kotlin/app/passwordstore/crypto/GpgIdentifierTest.kt
+++ b/crypto-pgpainless/src/test/kotlin/app/passwordstore/crypto/PGPIdentifierTest.kt
@@ -9,33 +9,33 @@ import kotlin.test.Test
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
-class GpgIdentifierTest {
+class PGPIdentifierTest {
@Test
fun parseHexKeyIdWithout0xPrefix() {
- val identifier = GpgIdentifier.fromString("79E8208280490C77")
+ val identifier = PGPIdentifier.fromString("79E8208280490C77")
assertNotNull(identifier)
- assertTrue { identifier is GpgIdentifier.KeyId }
+ assertTrue { identifier is PGPIdentifier.KeyId }
}
@Test
fun parseHexKeyId() {
- val identifier = GpgIdentifier.fromString("0x79E8208280490C77")
+ val identifier = PGPIdentifier.fromString("0x79E8208280490C77")
assertNotNull(identifier)
- assertTrue { identifier is GpgIdentifier.KeyId }
+ assertTrue { identifier is PGPIdentifier.KeyId }
}
@Test
fun parseValidEmail() {
- val identifier = GpgIdentifier.fromString("john.doe@example.org")
+ val identifier = PGPIdentifier.fromString("john.doe@example.org")
assertNotNull(identifier)
- assertTrue { identifier is GpgIdentifier.UserId }
+ assertTrue { identifier is PGPIdentifier.UserId }
}
@Test
fun parseEmailWithoutTLD() {
- val identifier = GpgIdentifier.fromString("john.doe@example")
+ val identifier = PGPIdentifier.fromString("john.doe@example")
assertNotNull(identifier)
- assertTrue { identifier is GpgIdentifier.UserId }
+ assertTrue { identifier is PGPIdentifier.UserId }
}
}
diff --git a/crypto-pgpainless/src/test/kotlin/app/passwordstore/crypto/PGPKeyManagerTest.kt b/crypto-pgpainless/src/test/kotlin/app/passwordstore/crypto/PGPKeyManagerTest.kt
index c8bd66c5..43a62bd7 100644
--- a/crypto-pgpainless/src/test/kotlin/app/passwordstore/crypto/PGPKeyManagerTest.kt
+++ b/crypto-pgpainless/src/test/kotlin/app/passwordstore/crypto/PGPKeyManagerTest.kt
@@ -1,8 +1,8 @@
package app.passwordstore.crypto
-import app.passwordstore.crypto.GpgIdentifier.KeyId
-import app.passwordstore.crypto.GpgIdentifier.UserId
import app.passwordstore.crypto.KeyUtils.tryGetId
+import app.passwordstore.crypto.PGPIdentifier.KeyId
+import app.passwordstore.crypto.PGPIdentifier.UserId
import app.passwordstore.crypto.errors.KeyAlreadyExistsException
import app.passwordstore.crypto.errors.KeyNotFoundException
import app.passwordstore.crypto.errors.NoKeysAvailableException