diff --git a/pgpainless-core/src/main/kotlin/org/pgpainless/key/generation/KeyRingBuilder.kt b/pgpainless-core/src/main/kotlin/org/pgpainless/key/generation/KeyRingBuilder.kt index 16b25bd3..a63c00aa 100644 --- a/pgpainless-core/src/main/kotlin/org/pgpainless/key/generation/KeyRingBuilder.kt +++ b/pgpainless-core/src/main/kotlin/org/pgpainless/key/generation/KeyRingBuilder.kt @@ -97,7 +97,7 @@ class KeyRingBuilder : KeyRingBuilderInterface { val signatureGenerator = PGPSignatureGenerator(signer, certKey.publicKey) val hashedSubPacketGenerator = primaryKeySpec!!.subpacketGenerator - hashedSubPacketGenerator.setIssuerFingerprintAndKeyId(certKey.publicKey) + hashedSubPacketGenerator.setIssuer(certKey.publicKey) expirationDate?.let { hashedSubPacketGenerator.setKeyExpirationTime(certKey.publicKey, it) } if (userIds.isNotEmpty()) { hashedSubPacketGenerator.setPrimaryUserId() diff --git a/pgpainless-core/src/main/kotlin/org/pgpainless/signature/subpackets/BaseSignatureSubpackets.kt b/pgpainless-core/src/main/kotlin/org/pgpainless/signature/subpackets/BaseSignatureSubpackets.kt index b9d7fb3f..bcb86182 100644 --- a/pgpainless-core/src/main/kotlin/org/pgpainless/signature/subpackets/BaseSignatureSubpackets.kt +++ b/pgpainless-core/src/main/kotlin/org/pgpainless/signature/subpackets/BaseSignatureSubpackets.kt @@ -17,6 +17,15 @@ interface BaseSignatureSubpackets { interface Callback : SignatureSubpacketCallback + /** + * Depending on the key version, set appropriate issuer information (issuer key-id / issuer + * fingerprint). + * + * @param key issuer key + * @return signature subpackets + */ + fun setIssuer(key: PGPPublicKey): BaseSignatureSubpackets + /** * Add both an [IssuerKeyID] and [IssuerFingerprint] subpacket pointing to the given key. * diff --git a/pgpainless-core/src/main/kotlin/org/pgpainless/signature/subpackets/SignatureSubpackets.kt b/pgpainless-core/src/main/kotlin/org/pgpainless/signature/subpackets/SignatureSubpackets.kt index 886cedb6..dc48d1cc 100644 --- a/pgpainless-core/src/main/kotlin/org/pgpainless/signature/subpackets/SignatureSubpackets.kt +++ b/pgpainless-core/src/main/kotlin/org/pgpainless/signature/subpackets/SignatureSubpackets.kt @@ -72,7 +72,7 @@ class SignatureSubpackets : issuer: PGPPublicKey, base: PGPSignatureSubpacketVector ): SignatureSubpackets { - return createSubpacketsFrom(base).apply { setIssuerFingerprintAndKeyId(issuer) } + return createSubpacketsFrom(base).apply { setIssuer(issuer) } } @JvmStatic @@ -82,7 +82,7 @@ class SignatureSubpackets : @JvmStatic fun createHashedSubpackets(issuer: PGPPublicKey): SignatureSubpackets { - return createEmptySubpackets().setIssuerFingerprintAndKeyId(issuer) + return createEmptySubpackets().setIssuer(issuer) } @JvmStatic @@ -352,6 +352,14 @@ class SignatureSubpackets : this.featuresSubpacket = features } + override fun setIssuer(key: PGPPublicKey): SignatureSubpackets = apply { + if (key.version == 6) { + setIssuerFingerprint(key) + } else { + setIssuerFingerprintAndKeyId(key) + } + } + override fun setIssuerFingerprintAndKeyId(key: PGPPublicKey): SignatureSubpackets = apply { setIssuerKeyId(key.keyID) setIssuerFingerprint(key)