aboutsummaryrefslogtreecommitdiff
path: root/crypto-pgpainless/src
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2022-07-18 22:52:58 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2022-07-18 23:04:58 +0530
commit82923983490fa87303303f37f39585b4785d9275 (patch)
treea64f4a0e5da196834be484f140213d0f397637d8 /crypto-pgpainless/src
parentb92a2ca18b50d479e22ad68400b3c6f33e2dc477 (diff)
Add `KeyUtils#tryGetEmail`
Diffstat (limited to 'crypto-pgpainless/src')
-rw-r--r--crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/KeyUtils.kt6
1 files changed, 6 insertions, 0 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 39478751..586603fd 100644
--- a/crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/KeyUtils.kt
+++ b/crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/KeyUtils.kt
@@ -6,6 +6,7 @@
package app.passwordstore.crypto
import app.passwordstore.crypto.GpgIdentifier.KeyId
+import app.passwordstore.crypto.GpgIdentifier.UserId
import com.github.michaelbull.result.get
import com.github.michaelbull.result.runCatching
import org.bouncycastle.openpgp.PGPKeyRing
@@ -34,4 +35,9 @@ public object KeyUtils {
val keyRing = tryParseKeyring(key) ?: return null
return KeyId(keyRing.publicKey.keyID)
}
+
+ public fun tryGetEmail(key: PGPKey): UserId? {
+ val keyRing = tryParseKeyring(key) ?: return null
+ return UserId(keyRing.publicKey.userIDs.next())
+ }
}