mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-09 18:29:39 +02:00
KeyRingUtils: Replace deprecated method usage
This commit is contained in:
parent
b543c2ed2a
commit
e7954ff6f1
1 changed files with 30 additions and 20 deletions
|
@ -52,13 +52,7 @@ class KeyRingUtils {
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun getPrimarySecretKeyFrom(secretKeys: PGPSecretKeyRing): PGPSecretKey? {
|
fun getPrimarySecretKeyFrom(secretKeys: PGPSecretKeyRing): PGPSecretKey? {
|
||||||
return secretKeys.secretKey.let {
|
return if (secretKeys.secretKey.isMasterKey) secretKeys.secretKey else null
|
||||||
if (it.isMasterKey) {
|
|
||||||
it
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -82,13 +76,7 @@ class KeyRingUtils {
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun getPrimaryPublicKey(keyRing: PGPKeyRing): PGPPublicKey? {
|
fun getPrimaryPublicKey(keyRing: PGPKeyRing): PGPPublicKey? {
|
||||||
return keyRing.publicKey.let {
|
return if (keyRing.publicKey.isMasterKey) keyRing.publicKey else null
|
||||||
if (it.isMasterKey) {
|
|
||||||
it
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -245,7 +233,7 @@ class KeyRingUtils {
|
||||||
certificate.publicKeys
|
certificate.publicKeys
|
||||||
.asSequence()
|
.asSequence()
|
||||||
.map {
|
.map {
|
||||||
if (it.keyID == certifiedKey.keyID) {
|
if (it.keyIdentifier == certifiedKey.keyIdentifier) {
|
||||||
PGPPublicKey.addCertification(it, certification)
|
PGPPublicKey.addCertification(it, certification)
|
||||||
} else {
|
} else {
|
||||||
it
|
it
|
||||||
|
@ -415,18 +403,40 @@ class KeyRingUtils {
|
||||||
* @throws PGPException in case of a broken key
|
* @throws PGPException in case of a broken key
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun stripSecretKey(secretKeys: PGPSecretKeyRing, keyId: Long): PGPSecretKeyRing {
|
@Deprecated("Pass in a KeyIdentifier instead.")
|
||||||
require(keyId != secretKeys.publicKey.keyID) {
|
fun stripSecretKey(secretKeys: PGPSecretKeyRing, keyId: Long): PGPSecretKeyRing =
|
||||||
|
stripSecretKey(secretKeys, KeyIdentifier(keyId))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the secret key of the subkey identified by the given [keyIdentifier] from the key
|
||||||
|
* ring. The public part stays attached to the key ring, so that it can still be used for
|
||||||
|
* encryption / verification of signatures.
|
||||||
|
*
|
||||||
|
* This method is intended to be used to remove secret primary keys from live keys when
|
||||||
|
* those are kept in offline storage.
|
||||||
|
*
|
||||||
|
* @param secretKeys secret key ring
|
||||||
|
* @param keyIdentifier identifier of the secret key to remove
|
||||||
|
* @return secret key ring with removed secret key
|
||||||
|
* @throws IOException in case of an error during serialization / deserialization of the key
|
||||||
|
* @throws PGPException in case of a broken key
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun stripSecretKey(
|
||||||
|
secretKeys: PGPSecretKeyRing,
|
||||||
|
keyIdentifier: KeyIdentifier
|
||||||
|
): PGPSecretKeyRing {
|
||||||
|
require(keyIdentifier != secretKeys.publicKey.keyIdentifier) {
|
||||||
"Bouncy Castle currently cannot deal with stripped primary secret keys."
|
"Bouncy Castle currently cannot deal with stripped primary secret keys."
|
||||||
}
|
}
|
||||||
if (secretKeys.getSecretKey(keyId) == null) {
|
if (secretKeys.getSecretKey(keyIdentifier) == null) {
|
||||||
throw NoSuchElementException(
|
throw NoSuchElementException(
|
||||||
"PGPSecretKeyRing does not contain secret key ${keyId.openPgpKeyId()}.")
|
"PGPSecretKeyRing does not contain secret key ${keyIdentifier}.")
|
||||||
}
|
}
|
||||||
|
|
||||||
val out = ByteArrayOutputStream()
|
val out = ByteArrayOutputStream()
|
||||||
secretKeys.forEach {
|
secretKeys.forEach {
|
||||||
if (it.keyID == keyId) {
|
if (it.keyIdentifier == keyIdentifier) {
|
||||||
// only encode the public key
|
// only encode the public key
|
||||||
it.publicKey.encode(out)
|
it.publicKey.encode(out)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue