1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-12-05 03:41:07 +01:00

Add OpenPGPComponentKey.getSecretKey() extension method

This commit is contained in:
Paul Schaub 2025-10-21 17:40:09 +02:00
parent cd99330a97
commit 8f1fff5403
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -5,6 +5,7 @@
package org.pgpainless.bouncycastle.extensions
import org.bouncycastle.openpgp.PGPPublicKeyEncryptedData
import org.bouncycastle.openpgp.api.OpenPGPCertificate.OpenPGPComponentKey
import org.bouncycastle.openpgp.api.OpenPGPKey
import org.bouncycastle.openpgp.api.OpenPGPKey.OpenPGPPrivateKey
import org.bouncycastle.openpgp.api.OpenPGPKey.OpenPGPSecretKey
@ -19,6 +20,13 @@ import org.pgpainless.util.Passphrase
fun OpenPGPKey.getSecretKeyFor(pkesk: PGPPublicKeyEncryptedData): OpenPGPSecretKey? =
this.getSecretKey(pkesk.keyIdentifier)
fun OpenPGPComponentKey.getSecretKey(): OpenPGPSecretKey? =
if (this.certificate is OpenPGPKey) {
(this.certificate as OpenPGPKey).getSecretKey(this)
} else {
null
}
/**
* Unlock the [OpenPGPSecretKey], returning the unlocked [OpenPGPPrivateKey].
*