Add KeyUtils#tryGetEmail

This commit is contained in:
Harsh Shandilya
2022-07-18 22:52:58 +05:30
parent b92a2ca18b
commit 8292398349

View File

@@ -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())
}
}