From 82923983490fa87303303f37f39585b4785d9275 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Mon, 18 Jul 2022 22:52:58 +0530 Subject: Add `KeyUtils#tryGetEmail` --- .../src/main/kotlin/app/passwordstore/crypto/KeyUtils.kt | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'crypto-pgpainless') 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()) + } } -- cgit v1.2.3