mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-10 02:39:39 +02:00
Replace deprecated method usage and make policy injectable in UnlockSecretKey utility class
This commit is contained in:
parent
2f6e9abf23
commit
b543c2ed2a
1 changed files with 10 additions and 5 deletions
|
@ -18,6 +18,7 @@ import org.pgpainless.bouncycastle.extensions.isEncrypted
|
||||||
import org.pgpainless.exception.KeyIntegrityException
|
import org.pgpainless.exception.KeyIntegrityException
|
||||||
import org.pgpainless.exception.WrongPassphraseException
|
import org.pgpainless.exception.WrongPassphraseException
|
||||||
import org.pgpainless.key.util.PublicKeyParameterValidationUtil
|
import org.pgpainless.key.util.PublicKeyParameterValidationUtil
|
||||||
|
import org.pgpainless.policy.Policy
|
||||||
import org.pgpainless.util.Passphrase
|
import org.pgpainless.util.Passphrase
|
||||||
|
|
||||||
class UnlockSecretKey {
|
class UnlockSecretKey {
|
||||||
|
@ -31,17 +32,19 @@ class UnlockSecretKey {
|
||||||
protector: SecretKeyRingProtector
|
protector: SecretKeyRingProtector
|
||||||
): PGPPrivateKey {
|
): PGPPrivateKey {
|
||||||
return if (secretKey.isEncrypted()) {
|
return if (secretKey.isEncrypted()) {
|
||||||
unlockSecretKey(secretKey, protector.getDecryptor(secretKey.keyID))
|
unlockSecretKey(secretKey, protector.getDecryptor(secretKey.keyIdentifier))
|
||||||
} else {
|
} else {
|
||||||
unlockSecretKey(secretKey, null as PBESecretKeyDecryptor?)
|
unlockSecretKey(secretKey, null as PBESecretKeyDecryptor?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
@JvmOverloads
|
||||||
@Throws(PGPException::class)
|
@Throws(PGPException::class)
|
||||||
fun unlockSecretKey(
|
fun unlockSecretKey(
|
||||||
secretKey: OpenPGPSecretKey,
|
secretKey: OpenPGPSecretKey,
|
||||||
protector: SecretKeyRingProtector
|
protector: SecretKeyRingProtector,
|
||||||
|
policy: Policy = PGPainless.getInstance().algorithmPolicy
|
||||||
): OpenPGPPrivateKey {
|
): OpenPGPPrivateKey {
|
||||||
val privateKey =
|
val privateKey =
|
||||||
try {
|
try {
|
||||||
|
@ -59,7 +62,7 @@ class UnlockSecretKey {
|
||||||
throw PGPException("Cannot decrypt secret key.")
|
throw PGPException("Cannot decrypt secret key.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PGPainless.getPolicy().isEnableKeyParameterValidation()) {
|
if (policy.isEnableKeyParameterValidation()) {
|
||||||
PublicKeyParameterValidationUtil.verifyPublicKeyParameterIntegrity(
|
PublicKeyParameterValidationUtil.verifyPublicKeyParameterIntegrity(
|
||||||
privateKey.keyPair.privateKey, privateKey.keyPair.publicKey)
|
privateKey.keyPair.privateKey, privateKey.keyPair.publicKey)
|
||||||
}
|
}
|
||||||
|
@ -68,10 +71,12 @@ class UnlockSecretKey {
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
@JvmOverloads
|
||||||
@Throws(PGPException::class)
|
@Throws(PGPException::class)
|
||||||
fun unlockSecretKey(
|
fun unlockSecretKey(
|
||||||
secretKey: PGPSecretKey,
|
secretKey: PGPSecretKey,
|
||||||
decryptor: PBESecretKeyDecryptor?
|
decryptor: PBESecretKeyDecryptor?,
|
||||||
|
policy: Policy = PGPainless.getInstance().algorithmPolicy
|
||||||
): PGPPrivateKey {
|
): PGPPrivateKey {
|
||||||
val privateKey =
|
val privateKey =
|
||||||
try {
|
try {
|
||||||
|
@ -89,7 +94,7 @@ class UnlockSecretKey {
|
||||||
throw PGPException("Cannot decrypt secret key.")
|
throw PGPException("Cannot decrypt secret key.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PGPainless.getPolicy().isEnableKeyParameterValidation()) {
|
if (policy.isEnableKeyParameterValidation()) {
|
||||||
PublicKeyParameterValidationUtil.verifyPublicKeyParameterIntegrity(
|
PublicKeyParameterValidationUtil.verifyPublicKeyParameterIntegrity(
|
||||||
privateKey, secretKey.publicKey)
|
privateKey, secretKey.publicKey)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue