Fix comments and add test

This commit is contained in:
Paul Schaub 2024-02-26 13:10:47 +01:00
parent 838ff9c499
commit 214a36ab34
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
2 changed files with 15 additions and 2 deletions

View File

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

View File

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