mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-25 04:17:59 +01:00
Add method for adding user attribute
This commit is contained in:
parent
35a68823bd
commit
699a5eabfc
2 changed files with 15 additions and 0 deletions
|
@ -3,6 +3,7 @@ package org.pgpainless.key.generation
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import org.bouncycastle.openpgp.PGPSecretKey
|
import org.bouncycastle.openpgp.PGPSecretKey
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing
|
import org.bouncycastle.openpgp.PGPSecretKeyRing
|
||||||
|
import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVector
|
||||||
import org.pgpainless.algorithm.AlgorithmSuite
|
import org.pgpainless.algorithm.AlgorithmSuite
|
||||||
import org.pgpainless.algorithm.KeyFlag
|
import org.pgpainless.algorithm.KeyFlag
|
||||||
import org.pgpainless.implementation.ImplementationFactory
|
import org.pgpainless.implementation.ImplementationFactory
|
||||||
|
@ -27,6 +28,14 @@ class OpenPgpV4KeyGenerator(
|
||||||
SelfSignatureSubpackets.defaultCallback()
|
SelfSignatureSubpackets.defaultCallback()
|
||||||
) = apply { primaryKey.userId(userId, subpacketsCallback = subpacketsCallback) }
|
) = apply { primaryKey.userId(userId, subpacketsCallback = subpacketsCallback) }
|
||||||
|
|
||||||
|
fun addUserAttribute(
|
||||||
|
attribute: PGPUserAttributeSubpacketVector,
|
||||||
|
subpacketsCallback: SelfSignatureSubpackets.Callback =
|
||||||
|
SelfSignatureSubpackets.defaultCallback()
|
||||||
|
) = apply {
|
||||||
|
primaryKey.userAttribute(attribute, subpacketsCallback = subpacketsCallback)
|
||||||
|
}
|
||||||
|
|
||||||
fun addSubkey(
|
fun addSubkey(
|
||||||
keyType: KeyType,
|
keyType: KeyType,
|
||||||
creationTime: Date = referenceTime,
|
creationTime: Date = referenceTime,
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.pgpainless.key.generation
|
package org.pgpainless.key.generation
|
||||||
|
|
||||||
|
import org.bouncycastle.bcpg.attr.ImageAttribute
|
||||||
|
import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVectorGenerator
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.pgpainless.PGPainless
|
import org.pgpainless.PGPainless
|
||||||
import org.pgpainless.key.generation.type.KeyType
|
import org.pgpainless.key.generation.type.KeyType
|
||||||
|
@ -18,6 +20,10 @@ class OpenPgpV4KeyGeneratorTest {
|
||||||
OpenPgpV4KeyGenerator(
|
OpenPgpV4KeyGenerator(
|
||||||
KeyType.EDDSA(EdDSACurve._Ed25519), Policy.getInstance(), referenceTime = date)
|
KeyType.EDDSA(EdDSACurve._Ed25519), Policy.getInstance(), referenceTime = date)
|
||||||
.addUserId("Alice")
|
.addUserId("Alice")
|
||||||
|
.addUserAttribute(
|
||||||
|
PGPUserAttributeSubpacketVectorGenerator().apply {
|
||||||
|
setImageAttribute(ImageAttribute.JPEG, byteArrayOf())
|
||||||
|
}.generate())
|
||||||
.addEncryptionSubkey(KeyType.XDH(XDHSpec._X25519))
|
.addEncryptionSubkey(KeyType.XDH(XDHSpec._X25519))
|
||||||
.addSigningSubkey(KeyType.EDDSA(EdDSACurve._Ed25519))
|
.addSigningSubkey(KeyType.EDDSA(EdDSACurve._Ed25519))
|
||||||
.build(SecretKeyRingProtector.unprotectedKeys())
|
.build(SecretKeyRingProtector.unprotectedKeys())
|
||||||
|
|
Loading…
Reference in a new issue