mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-24 11:57:59 +01:00
Improve tests with extension functions
This commit is contained in:
parent
e7784b10a4
commit
b27a8b71ec
2 changed files with 28 additions and 8 deletions
|
@ -10,6 +10,7 @@ import org.bouncycastle.bcpg.ECDSAPublicBCPGKey
|
|||
import org.bouncycastle.bcpg.EdDSAPublicBCPGKey
|
||||
import org.bouncycastle.jcajce.provider.asymmetric.util.ECUtil
|
||||
import org.bouncycastle.openpgp.PGPPublicKey
|
||||
import org.bouncycastle.openpgp.PGPSignature
|
||||
import org.pgpainless.algorithm.PublicKeyAlgorithm
|
||||
import org.pgpainless.key.OpenPgpFingerprint
|
||||
import org.pgpainless.key.generation.type.eddsa.EdDSACurve
|
||||
|
@ -50,3 +51,21 @@ val PGPPublicKey.publicKeyAlgorithm: PublicKeyAlgorithm
|
|||
/** Return the [OpenPgpFingerprint] of this key. */
|
||||
val PGPPublicKey.openPgpFingerprint: OpenPgpFingerprint
|
||||
get() = OpenPgpFingerprint.of(this)
|
||||
|
||||
val PGPPublicKey.directKeySignatures: Sequence<PGPSignature>
|
||||
get() = signatures.asSequence().filter { it.signatureType == PGPSignature.DIRECT_KEY }
|
||||
|
||||
val PGPPublicKey.directKeySelfSignatures: Sequence<PGPSignature>
|
||||
get() = directKeySignatures.filter { it.issuerKeyId == keyID }
|
||||
|
||||
val PGPPublicKey.keyRevocationSignatures: Sequence<PGPSignature>
|
||||
get() = signatures.asSequence().filter { it.signatureType == PGPSignature.KEY_REVOCATION }
|
||||
|
||||
val PGPPublicKey.keyRevocationSelfSignatures: Sequence<PGPSignature>
|
||||
get() = keyRevocationSignatures.filter { it.issuerKeyId == keyID }
|
||||
|
||||
val PGPPublicKey.subkeyBindingSignatures: Sequence<PGPSignature>
|
||||
get() = signatures.asSequence().filter { it.signatureType == PGPSignature.SUBKEY_BINDING }
|
||||
|
||||
val PGPPublicKey.subkeyRevocationSignatures: Sequence<PGPSignature>
|
||||
get() = signatures.asSequence().filter { it.signatureType == PGPSignature.SUBKEY_REVOCATION }
|
||||
|
|
|
@ -10,12 +10,15 @@ 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.assertTrue
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import org.pgpainless.PGPainless
|
||||
import org.pgpainless.algorithm.HashAlgorithm
|
||||
import org.pgpainless.algorithm.KeyFlag
|
||||
import org.pgpainless.algorithm.PublicKeyAlgorithm
|
||||
import org.pgpainless.bouncycastle.extensions.directKeySignatures
|
||||
import org.pgpainless.bouncycastle.extensions.subkeyBindingSignatures
|
||||
import org.pgpainless.bouncycastle.extensions.toAsciiArmor
|
||||
import org.pgpainless.key.generation.type.KeyType
|
||||
import org.pgpainless.key.generation.type.eddsa.EdDSACurve
|
||||
|
@ -36,9 +39,7 @@ class OpenPgpKeyGeneratorTest {
|
|||
|
||||
assertFalse(key.publicKey.userIDs.hasNext(), "Key MUST NOT have a UserID")
|
||||
assertFalse(key.publicKey.userAttributes.hasNext(), "Key MUST NOT have a UserAttribute")
|
||||
assertEquals(
|
||||
1,
|
||||
key.publicKey.keySignatures.asSequence().toList().size,
|
||||
assertEquals(1, key.publicKey.directKeySignatures.count(),
|
||||
"Opinionated builder adds exactly one DirectKey signature")
|
||||
|
||||
println(key.toAsciiArmor())
|
||||
|
@ -52,7 +53,7 @@ class OpenPgpKeyGeneratorTest {
|
|||
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519))
|
||||
.build()
|
||||
|
||||
assertFalse(key.publicKey.keySignatures.hasNext())
|
||||
assertTrue(key.publicKey.directKeySignatures.none())
|
||||
|
||||
println(key.toAsciiArmor())
|
||||
}
|
||||
|
@ -66,7 +67,7 @@ class OpenPgpKeyGeneratorTest {
|
|||
}
|
||||
.build()
|
||||
|
||||
assertEquals(1, key.publicKey.keySignatures.asSequence().toList().size)
|
||||
assertEquals(1, key.publicKey.directKeySignatures.count())
|
||||
|
||||
println(key.toAsciiArmor())
|
||||
}
|
||||
|
@ -116,8 +117,8 @@ class OpenPgpKeyGeneratorTest {
|
|||
key.publicKeys
|
||||
.asSequence()
|
||||
.last()
|
||||
.signatures
|
||||
.next()
|
||||
.subkeyBindingSignatures
|
||||
.single()
|
||||
.hashedSubPackets
|
||||
.embeddedSignatures
|
||||
.isEmpty)
|
||||
|
@ -212,7 +213,7 @@ class OpenPgpKeyGeneratorTest {
|
|||
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519)) { skipDefaultSignature() }
|
||||
.build()
|
||||
|
||||
assertFalse(key.publicKey.keySignatures.hasNext())
|
||||
assertTrue(key.publicKey.directKeySignatures.none())
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in a new issue