1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-24 11:57:59 +01:00

Improve image attribute test

This commit is contained in:
Paul Schaub 2024-02-02 16:39:19 +01:00
parent 0d3fb446a8
commit 05c203177e
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -4,8 +4,11 @@
package org.pgpainless.key.generation
import java.io.InputStream
import org.bouncycastle.bcpg.attr.ImageAttribute
import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVectorGenerator
import org.bouncycastle.util.io.Streams
import org.junit.jupiter.api.Assertions.assertArrayEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
@ -20,7 +23,6 @@ import org.pgpainless.key.generation.type.xdh.XDHSpec
import org.pgpainless.key.protection.SecretKeyRingProtector
import org.pgpainless.policy.Policy
import org.pgpainless.util.DateUtil
import java.io.InputStream
class GenerateOpenPgpKeyTest {
@ -67,7 +69,7 @@ class GenerateOpenPgpKeyTest {
val policy =
Policy(
publicKeyAlgorithmPolicy =
Policy.PublicKeyAlgorithmPolicy(mapOf(PublicKeyAlgorithm.RSA_GENERAL to 4096)),
Policy.PublicKeyAlgorithmPolicy(mapOf(PublicKeyAlgorithm.RSA_GENERAL to 4096)),
)
val builder = GenerateOpenPgpKey(policy)
@ -83,12 +85,16 @@ class GenerateOpenPgpKeyTest {
@Test
fun testKeyGenerationWithJPEGAttribute() {
val key = GenerateOpenPgpKey(Policy.getInstance())
.buildV4Key(KeyType.EDDSA(EdDSACurve._Ed25519))
.addJpegImage(requireResource("suzanne.jpg"))
.build()
val key =
GenerateOpenPgpKey(Policy.getInstance())
.buildV4Key(KeyType.EDDSA(EdDSACurve._Ed25519))
.addJpegImage(requireResource("suzanne.jpg"))
.build()
assertTrue(key.publicKey.userAttributes.hasNext())
assertArrayEquals(
Streams.readAll(requireResource("suzanne.jpg")),
key.publicKey.userAttributes.next().imageAttribute.imageData)
}
private fun requireResource(resourceName: String): InputStream {