1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-06-25 21:14:49 +02:00

Add method for adding user attribute

This commit is contained in:
Paul Schaub 2024-01-20 19:11:47 +01:00
parent 35a68823bd
commit 699a5eabfc
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 15 additions and 0 deletions

View file

@ -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,

View file

@ -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())