mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-09 18:29:39 +02:00
Introduce PGPainless.toKeyOrCertificate(PGPKeyRing) and constrain argument type of PGPainless.toCertificate(PGPPublicKeyRing)
This commit is contained in:
parent
221d329254
commit
bab448eb6d
2 changed files with 20 additions and 14 deletions
|
@ -91,8 +91,17 @@ class PGPainless(
|
|||
fun toKey(secretKeyRing: PGPSecretKeyRing): OpenPGPKey =
|
||||
OpenPGPKey(secretKeyRing, implementation)
|
||||
|
||||
fun toCertificate(keyOrCertificate: PGPKeyRing): OpenPGPCertificate =
|
||||
OpenPGPCertificate(keyOrCertificate, implementation)
|
||||
fun toCertificate(certificate: PGPPublicKeyRing): OpenPGPCertificate =
|
||||
OpenPGPCertificate(certificate, implementation)
|
||||
|
||||
fun toKeyOrCertificate(keyOrCertificate: PGPKeyRing): OpenPGPCertificate =
|
||||
when (keyOrCertificate) {
|
||||
is PGPSecretKeyRing -> toKey(keyOrCertificate)
|
||||
is PGPPublicKeyRing -> toCertificate(keyOrCertificate)
|
||||
else ->
|
||||
throw IllegalArgumentException(
|
||||
"Unexpected PGPKeyRing subclass: ${keyOrCertificate.javaClass.name}")
|
||||
}
|
||||
|
||||
fun mergeCertificate(
|
||||
originalCopy: OpenPGPCertificate,
|
||||
|
@ -120,8 +129,8 @@ class PGPainless(
|
|||
instance ?: synchronized(this) { instance ?: PGPainless().also { instance = it } }
|
||||
|
||||
@JvmStatic
|
||||
fun setInstance(pgpainless: PGPainless) {
|
||||
instance = pgpainless
|
||||
fun setInstance(api: PGPainless) {
|
||||
instance = api
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -145,10 +154,8 @@ class PGPainless(
|
|||
@JvmStatic
|
||||
@JvmOverloads
|
||||
@Deprecated("Call buildKey() on an instance of PGPainless instead.")
|
||||
fun buildKeyRing(
|
||||
version: OpenPGPKeyVersion = OpenPGPKeyVersion.v4,
|
||||
api: PGPainless = getInstance()
|
||||
): KeyRingBuilder = KeyRingBuilder(version, api)
|
||||
fun buildKeyRing(version: OpenPGPKeyVersion = OpenPGPKeyVersion.v4): KeyRingBuilder =
|
||||
getInstance().buildKey(version)
|
||||
|
||||
/**
|
||||
* Read an existing OpenPGP key ring.
|
||||
|
@ -262,9 +269,8 @@ class PGPainless(
|
|||
@JvmOverloads
|
||||
fun modifyKeyRing(
|
||||
secretKey: PGPSecretKeyRing,
|
||||
referenceTime: Date = Date(),
|
||||
api: PGPainless = getInstance()
|
||||
): SecretKeyRingEditor = SecretKeyRingEditor(secretKey, api, referenceTime)
|
||||
referenceTime: Date = Date()
|
||||
): SecretKeyRingEditor = getInstance().modify(getInstance().toKey(secretKey), referenceTime)
|
||||
|
||||
/**
|
||||
* Quickly access information about a [org.bouncycastle.openpgp.PGPPublicKeyRing] /
|
||||
|
@ -281,7 +287,7 @@ class PGPainless(
|
|||
"Use inspect(key) on an instance of PGPainless instead.",
|
||||
replaceWith = ReplaceWith("inspect(key)"))
|
||||
fun inspectKeyRing(key: PGPKeyRing, referenceTime: Date = Date()): KeyRingInfo =
|
||||
KeyRingInfo(key, referenceTime)
|
||||
getInstance().inspect(getInstance().toKeyOrCertificate(key), referenceTime)
|
||||
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
|
@ -289,7 +295,7 @@ class PGPainless(
|
|||
"Use inspect(key) on an instance of PGPainless instead.",
|
||||
replaceWith = ReplaceWith("inspect(key)"))
|
||||
fun inspectKeyRing(key: OpenPGPCertificate, referenceTime: Date = Date()): KeyRingInfo =
|
||||
KeyRingInfo(key, getInstance(), referenceTime)
|
||||
getInstance().inspect(key, referenceTime)
|
||||
|
||||
/**
|
||||
* Access, and make changes to PGPainless policy on acceptable/default algorithms etc.
|
||||
|
|
|
@ -83,7 +83,7 @@ abstract class SelectUserId : Predicate<String>, (String) -> Boolean {
|
|||
|
||||
@JvmStatic
|
||||
fun validUserId(keyRing: PGPKeyRing) =
|
||||
validUserId(PGPainless.getInstance().toCertificate(keyRing))
|
||||
validUserId(PGPainless.getInstance().toKeyOrCertificate(keyRing))
|
||||
|
||||
@JvmStatic
|
||||
fun and(vararg filters: SelectUserId) =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue