From 214a36ab3482c41ff7fb0ef66a1f6bc50a4c8d16 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Mon, 26 Feb 2024 13:10:47 +0100 Subject: [PATCH] Fix comments and add test --- .../key/generation/OpenPgpKeyGenerator.kt | 4 ++-- .../key/generation/OpenPgpKeyGeneratorTest.kt | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pgpainless-core/src/main/kotlin/org/pgpainless/key/generation/OpenPgpKeyGenerator.kt b/pgpainless-core/src/main/kotlin/org/pgpainless/key/generation/OpenPgpKeyGenerator.kt index e66fbe7a..bed88d69 100644 --- a/pgpainless-core/src/main/kotlin/org/pgpainless/key/generation/OpenPgpKeyGenerator.kt +++ b/pgpainless-core/src/main/kotlin/org/pgpainless/key/generation/OpenPgpKeyGenerator.kt @@ -727,7 +727,7 @@ internal constructor(policy: Policy, creationTime: Date, preferences: AlgorithmS override fun userAttributeSubpackets(primaryKey: PGPKeyPair): SelfSignatureSubpackets.Callback { return preferencesSubpackets() .then( - // if key has primary User-IDs already, do nothing + // if key has primary user-attributes already, do nothing if (primaryKey.publicKey.userAttributes.asSequence().any { attr -> primaryKey.publicKey.getSignaturesForUserAttribute(attr).asSequence().any { sig -> @@ -736,7 +736,7 @@ internal constructor(policy: Policy, creationTime: Date, preferences: AlgorithmS }) { SelfSignatureSubpackets.nop() } else { - // else set this user-id as primary + // else set this user-attribute as primary SelfSignatureSubpackets.applyHashed { setPrimaryUserId() } }) } diff --git a/pgpainless-core/src/test/kotlin/org/pgpainless/key/generation/OpenPgpKeyGeneratorTest.kt b/pgpainless-core/src/test/kotlin/org/pgpainless/key/generation/OpenPgpKeyGeneratorTest.kt index 342c34b2..903580ab 100644 --- a/pgpainless-core/src/test/kotlin/org/pgpainless/key/generation/OpenPgpKeyGeneratorTest.kt +++ b/pgpainless-core/src/test/kotlin/org/pgpainless/key/generation/OpenPgpKeyGeneratorTest.kt @@ -12,6 +12,7 @@ import org.bouncycastle.util.encoders.Hex import org.junit.jupiter.api.Assertions.assertArrayEquals import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertNull import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows @@ -28,6 +29,7 @@ import org.pgpainless.key.generation.type.rsa.RsaLength import org.pgpainless.key.generation.type.xdh.XDHSpec import org.pgpainless.policy.Policy import org.pgpainless.signature.subpackets.SelfSignatureSubpackets +import org.pgpainless.signature.subpackets.SignatureSubpacketsUtil import org.pgpainless.util.DateUtil class OpenPgpKeyGeneratorTest { @@ -477,6 +479,17 @@ class OpenPgpKeyGeneratorTest { listOf(KeyFlag.CERTIFY_OTHER, KeyFlag.ENCRYPT_STORAGE)) } + @Test + fun `opinionated set primary key without any key flags is okay`() { + val policy = Policy() + + val key = OpenPgpKeyGenerator.buildV4Key(policy) + .setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519), keyFlags = null) + .build() + + assertNull(SignatureSubpacketsUtil.getKeyFlags(key.publicKey.signatures.next())) + } + @Test fun `opinionated add encryption-only subkey with additional sign flag fails`() { val policy = Policy()