aboutsummaryrefslogtreecommitdiff
path: root/crypto-pgpainless/src/main/kotlin
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2022-07-16 21:25:04 +0530
committerGitHub <noreply@github.com>2022-07-16 15:55:04 +0000
commitdb01ed2a2e2a210de33cc96751b7a5281a96db77 (patch)
treecfe1ccaa39c1e168de3cce697a8ef33973f77d5d /crypto-pgpainless/src/main/kotlin
parent205a1d942ec9cc56f3b250bf2bf4c5142917bb6e (diff)
Use `KeyRingUtils#publicKeyRingCollectionFrom` to extract public keys (#2009)
Diffstat (limited to 'crypto-pgpainless/src/main/kotlin')
-rw-r--r--crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandler.kt20
1 files changed, 10 insertions, 10 deletions
diff --git a/crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandler.kt b/crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandler.kt
index 440b162e..fa56ebd8 100644
--- a/crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandler.kt
+++ b/crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandler.kt
@@ -25,6 +25,7 @@ import org.pgpainless.encryption_signing.EncryptionOptions
import org.pgpainless.encryption_signing.ProducerOptions
import org.pgpainless.exception.WrongPassphraseException
import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector
+import org.pgpainless.key.util.KeyRingUtils
import org.pgpainless.util.Passphrase
public class PGPainlessCryptoHandler @Inject constructor() : CryptoHandler<PGPKey> {
@@ -71,16 +72,15 @@ public class PGPainlessCryptoHandler @Inject constructor() : CryptoHandler<PGPKe
val armoredKeys =
keys.joinToString("\n") { key -> key.contents.decodeToString() }.toByteArray()
val secKeysStream = ByteArrayInputStream(armoredKeys)
- val secretKeyRingCollection =
- PGPainless.readKeyRing().secretKeyRingCollection(secKeysStream)
- secretKeyRingCollection.forEach { secretKeyRing ->
- publicKeyRings.add(PGPainless.extractCertificate(secretKeyRing))
- }
- if (publicKeyRings.isEmpty()) {
- val pubKeysStream = ByteArrayInputStream(armoredKeys)
- val publicKeyRingCollection =
- PGPainless.readKeyRing().publicKeyRingCollection(pubKeysStream)
- publicKeyRings.addAll(publicKeyRingCollection)
+ publicKeyRings.addAll(
+ KeyRingUtils.publicKeyRingCollectionFrom(
+ PGPainless.readKeyRing().secretKeyRingCollection(secKeysStream)
+ )
+ )
+ val pubKeysStream = ByteArrayInputStream(armoredKeys)
+ publicKeyRings.addAll(PGPainless.readKeyRing().publicKeyRingCollection(pubKeysStream))
+ require(keys.size == publicKeyRings.size) {
+ "Failed to parse all keys: keys=${keys.size},parsed=${publicKeyRings.size}"
}
require(publicKeyRings.isNotEmpty()) { "No public keys to encrypt message to" }
val publicKeyRingCollection = PGPPublicKeyRingCollection(publicKeyRings)