mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-25 04:17: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.bcpg.EdDSAPublicBCPGKey
|
||||||
import org.bouncycastle.jcajce.provider.asymmetric.util.ECUtil
|
import org.bouncycastle.jcajce.provider.asymmetric.util.ECUtil
|
||||||
import org.bouncycastle.openpgp.PGPPublicKey
|
import org.bouncycastle.openpgp.PGPPublicKey
|
||||||
|
import org.bouncycastle.openpgp.PGPSignature
|
||||||
import org.pgpainless.algorithm.PublicKeyAlgorithm
|
import org.pgpainless.algorithm.PublicKeyAlgorithm
|
||||||
import org.pgpainless.key.OpenPgpFingerprint
|
import org.pgpainless.key.OpenPgpFingerprint
|
||||||
import org.pgpainless.key.generation.type.eddsa.EdDSACurve
|
import org.pgpainless.key.generation.type.eddsa.EdDSACurve
|
||||||
|
@ -50,3 +51,21 @@ val PGPPublicKey.publicKeyAlgorithm: PublicKeyAlgorithm
|
||||||
/** Return the [OpenPgpFingerprint] of this key. */
|
/** Return the [OpenPgpFingerprint] of this key. */
|
||||||
val PGPPublicKey.openPgpFingerprint: OpenPgpFingerprint
|
val PGPPublicKey.openPgpFingerprint: OpenPgpFingerprint
|
||||||
get() = OpenPgpFingerprint.of(this)
|
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.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.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
|
||||||
import org.pgpainless.PGPainless
|
import org.pgpainless.PGPainless
|
||||||
import org.pgpainless.algorithm.HashAlgorithm
|
import org.pgpainless.algorithm.HashAlgorithm
|
||||||
import org.pgpainless.algorithm.KeyFlag
|
import org.pgpainless.algorithm.KeyFlag
|
||||||
import org.pgpainless.algorithm.PublicKeyAlgorithm
|
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.bouncycastle.extensions.toAsciiArmor
|
||||||
import org.pgpainless.key.generation.type.KeyType
|
import org.pgpainless.key.generation.type.KeyType
|
||||||
import org.pgpainless.key.generation.type.eddsa.EdDSACurve
|
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.userIDs.hasNext(), "Key MUST NOT have a UserID")
|
||||||
assertFalse(key.publicKey.userAttributes.hasNext(), "Key MUST NOT have a UserAttribute")
|
assertFalse(key.publicKey.userAttributes.hasNext(), "Key MUST NOT have a UserAttribute")
|
||||||
assertEquals(
|
assertEquals(1, key.publicKey.directKeySignatures.count(),
|
||||||
1,
|
|
||||||
key.publicKey.keySignatures.asSequence().toList().size,
|
|
||||||
"Opinionated builder adds exactly one DirectKey signature")
|
"Opinionated builder adds exactly one DirectKey signature")
|
||||||
|
|
||||||
println(key.toAsciiArmor())
|
println(key.toAsciiArmor())
|
||||||
|
@ -52,7 +53,7 @@ class OpenPgpKeyGeneratorTest {
|
||||||
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519))
|
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519))
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
assertFalse(key.publicKey.keySignatures.hasNext())
|
assertTrue(key.publicKey.directKeySignatures.none())
|
||||||
|
|
||||||
println(key.toAsciiArmor())
|
println(key.toAsciiArmor())
|
||||||
}
|
}
|
||||||
|
@ -66,7 +67,7 @@ class OpenPgpKeyGeneratorTest {
|
||||||
}
|
}
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
assertEquals(1, key.publicKey.keySignatures.asSequence().toList().size)
|
assertEquals(1, key.publicKey.directKeySignatures.count())
|
||||||
|
|
||||||
println(key.toAsciiArmor())
|
println(key.toAsciiArmor())
|
||||||
}
|
}
|
||||||
|
@ -116,8 +117,8 @@ class OpenPgpKeyGeneratorTest {
|
||||||
key.publicKeys
|
key.publicKeys
|
||||||
.asSequence()
|
.asSequence()
|
||||||
.last()
|
.last()
|
||||||
.signatures
|
.subkeyBindingSignatures
|
||||||
.next()
|
.single()
|
||||||
.hashedSubPackets
|
.hashedSubPackets
|
||||||
.embeddedSignatures
|
.embeddedSignatures
|
||||||
.isEmpty)
|
.isEmpty)
|
||||||
|
@ -212,7 +213,7 @@ class OpenPgpKeyGeneratorTest {
|
||||||
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519)) { skipDefaultSignature() }
|
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519)) { skipDefaultSignature() }
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
assertFalse(key.publicKey.keySignatures.hasNext())
|
assertTrue(key.publicKey.directKeySignatures.none())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in a new issue