mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-09 02:09:38 +02:00
WIP: Migrate away from static methods
This commit is contained in:
parent
66a2b7e0fc
commit
dd4a989606
1 changed files with 14 additions and 1 deletions
|
@ -10,7 +10,9 @@ import org.bouncycastle.openpgp.PGPKeyRing
|
|||
import org.bouncycastle.openpgp.PGPPublicKeyRing
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing
|
||||
import org.bouncycastle.openpgp.PGPSignature
|
||||
import org.bouncycastle.openpgp.api.OpenPGPApi
|
||||
import org.bouncycastle.openpgp.api.OpenPGPImplementation
|
||||
import org.bouncycastle.openpgp.api.bc.BcOpenPGPApi
|
||||
import org.pgpainless.algorithm.OpenPGPKeyVersion
|
||||
import org.pgpainless.bouncycastle.PolicyAdapter
|
||||
import org.pgpainless.decryption_verification.DecryptionBuilder
|
||||
|
@ -30,11 +32,17 @@ class PGPainless(
|
|||
val algorithmPolicy: Policy = Policy.getInstance()
|
||||
) {
|
||||
|
||||
private var api: OpenPGPApi
|
||||
|
||||
init {
|
||||
implementation.setPolicy(
|
||||
PolicyAdapter(algorithmPolicy)) // adapt PGPainless' Policy to BCs OpenPGPPolicy
|
||||
api = BcOpenPGPApi(implementation)
|
||||
}
|
||||
|
||||
fun generateKey(version: OpenPGPKeyVersion = OpenPGPKeyVersion.v4): KeyRingTemplates =
|
||||
KeyRingTemplates(version)
|
||||
|
||||
companion object {
|
||||
|
||||
@Volatile private var instance: PGPainless? = null
|
||||
|
@ -43,6 +51,11 @@ class PGPainless(
|
|||
fun getInstance() =
|
||||
instance ?: synchronized(this) { instance ?: PGPainless().also { instance = it } }
|
||||
|
||||
@JvmStatic
|
||||
fun setInstance(pgpainless: PGPainless) {
|
||||
instance = pgpainless
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a fresh OpenPGP key ring from predefined templates.
|
||||
*
|
||||
|
@ -51,7 +64,7 @@ class PGPainless(
|
|||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun generateKeyRing(version: OpenPGPKeyVersion = OpenPGPKeyVersion.v4) =
|
||||
KeyRingTemplates(version)
|
||||
getInstance().generateKey(version)
|
||||
|
||||
/**
|
||||
* Build a custom OpenPGP key ring.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue