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