mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-05 03:55:58 +01:00
Fix comments and add test
This commit is contained in:
parent
838ff9c499
commit
214a36ab34
2 changed files with 15 additions and 2 deletions
|
@ -727,7 +727,7 @@ internal constructor(policy: Policy, creationTime: Date, preferences: AlgorithmS
|
||||||
override fun userAttributeSubpackets(primaryKey: PGPKeyPair): SelfSignatureSubpackets.Callback {
|
override fun userAttributeSubpackets(primaryKey: PGPKeyPair): SelfSignatureSubpackets.Callback {
|
||||||
return preferencesSubpackets()
|
return preferencesSubpackets()
|
||||||
.then(
|
.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 ->
|
if (primaryKey.publicKey.userAttributes.asSequence().any { attr ->
|
||||||
primaryKey.publicKey.getSignaturesForUserAttribute(attr).asSequence().any { sig
|
primaryKey.publicKey.getSignaturesForUserAttribute(attr).asSequence().any { sig
|
||||||
->
|
->
|
||||||
|
@ -736,7 +736,7 @@ internal constructor(policy: Policy, creationTime: Date, preferences: AlgorithmS
|
||||||
}) {
|
}) {
|
||||||
SelfSignatureSubpackets.nop()
|
SelfSignatureSubpackets.nop()
|
||||||
} else {
|
} else {
|
||||||
// else set this user-id as primary
|
// else set this user-attribute as primary
|
||||||
SelfSignatureSubpackets.applyHashed { setPrimaryUserId() }
|
SelfSignatureSubpackets.applyHashed { setPrimaryUserId() }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import org.bouncycastle.util.encoders.Hex
|
||||||
import org.junit.jupiter.api.Assertions.assertArrayEquals
|
import org.junit.jupiter.api.Assertions.assertArrayEquals
|
||||||
import org.junit.jupiter.api.Assertions.assertEquals
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
import org.junit.jupiter.api.Assertions.assertFalse
|
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.Assertions.assertTrue
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.assertThrows
|
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.key.generation.type.xdh.XDHSpec
|
||||||
import org.pgpainless.policy.Policy
|
import org.pgpainless.policy.Policy
|
||||||
import org.pgpainless.signature.subpackets.SelfSignatureSubpackets
|
import org.pgpainless.signature.subpackets.SelfSignatureSubpackets
|
||||||
|
import org.pgpainless.signature.subpackets.SignatureSubpacketsUtil
|
||||||
import org.pgpainless.util.DateUtil
|
import org.pgpainless.util.DateUtil
|
||||||
|
|
||||||
class OpenPgpKeyGeneratorTest {
|
class OpenPgpKeyGeneratorTest {
|
||||||
|
@ -477,6 +479,17 @@ class OpenPgpKeyGeneratorTest {
|
||||||
listOf(KeyFlag.CERTIFY_OTHER, KeyFlag.ENCRYPT_STORAGE))
|
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
|
@Test
|
||||||
fun `opinionated add encryption-only subkey with additional sign flag fails`() {
|
fun `opinionated add encryption-only subkey with additional sign flag fails`() {
|
||||||
val policy = Policy()
|
val policy = Policy()
|
||||||
|
|
Loading…
Reference in a new issue