diff --git a/pgpainless-core/src/main/kotlin/org/pgpainless/key/generation/OpenPgpV4KeyGenerator.kt b/pgpainless-core/src/main/kotlin/org/pgpainless/key/generation/OpenPgpV4KeyGenerator.kt index 85d251f7..341c3db9 100644 --- a/pgpainless-core/src/main/kotlin/org/pgpainless/key/generation/OpenPgpV4KeyGenerator.kt +++ b/pgpainless-core/src/main/kotlin/org/pgpainless/key/generation/OpenPgpV4KeyGenerator.kt @@ -3,6 +3,7 @@ package org.pgpainless.key.generation import java.util.* import org.bouncycastle.openpgp.PGPSecretKey import org.bouncycastle.openpgp.PGPSecretKeyRing +import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVector import org.pgpainless.algorithm.AlgorithmSuite import org.pgpainless.algorithm.KeyFlag import org.pgpainless.implementation.ImplementationFactory @@ -27,6 +28,14 @@ class OpenPgpV4KeyGenerator( SelfSignatureSubpackets.defaultCallback() ) = apply { primaryKey.userId(userId, subpacketsCallback = subpacketsCallback) } + fun addUserAttribute( + attribute: PGPUserAttributeSubpacketVector, + subpacketsCallback: SelfSignatureSubpackets.Callback = + SelfSignatureSubpackets.defaultCallback() + ) = apply { + primaryKey.userAttribute(attribute, subpacketsCallback = subpacketsCallback) + } + fun addSubkey( keyType: KeyType, creationTime: Date = referenceTime, diff --git a/pgpainless-core/src/test/kotlin/org/pgpainless/key/generation/OpenPgpV4KeyGeneratorTest.kt b/pgpainless-core/src/test/kotlin/org/pgpainless/key/generation/OpenPgpV4KeyGeneratorTest.kt index 2022c828..3afc0cd7 100644 --- a/pgpainless-core/src/test/kotlin/org/pgpainless/key/generation/OpenPgpV4KeyGeneratorTest.kt +++ b/pgpainless-core/src/test/kotlin/org/pgpainless/key/generation/OpenPgpV4KeyGeneratorTest.kt @@ -1,5 +1,7 @@ package org.pgpainless.key.generation +import org.bouncycastle.bcpg.attr.ImageAttribute +import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVectorGenerator import org.junit.jupiter.api.Test import org.pgpainless.PGPainless import org.pgpainless.key.generation.type.KeyType @@ -18,6 +20,10 @@ class OpenPgpV4KeyGeneratorTest { OpenPgpV4KeyGenerator( KeyType.EDDSA(EdDSACurve._Ed25519), Policy.getInstance(), referenceTime = date) .addUserId("Alice") + .addUserAttribute( + PGPUserAttributeSubpacketVectorGenerator().apply { + setImageAttribute(ImageAttribute.JPEG, byteArrayOf()) + }.generate()) .addEncryptionSubkey(KeyType.XDH(XDHSpec._X25519)) .addSigningSubkey(KeyType.EDDSA(EdDSACurve._Ed25519)) .build(SecretKeyRingProtector.unprotectedKeys())