1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-19 02:42:05 +01:00

Add tests for PGPPublicKeyExtensions

This commit is contained in:
Paul Schaub 2024-03-05 21:17:03 +01:00
parent e561d58562
commit c89c47c491
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -0,0 +1,60 @@
// SPDX-FileCopyrightText: 2024 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package org.pgpainless.bouncycastle.extensions
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.pgpainless.PGPainless
import org.pgpainless.algorithm.PublicKeyAlgorithm
import org.pgpainless.key.TestKeys
import org.pgpainless.key.generation.KeySpec
import org.pgpainless.key.generation.type.KeyType
import org.pgpainless.key.generation.type.ecc.EllipticCurve
import org.pgpainless.key.generation.type.eddsa.EdDSACurve
class PGPPublicKeyExtensionsTest {
@Test
fun `test getCurveName for all ECDSA curves`() {
for (curve in EllipticCurve.values()) {
val key = PGPainless.buildKeyRing()
.setPrimaryKey(KeySpec.getBuilder(KeyType.ECDSA(curve)))
.build()
.publicKey
assertEquals(curve.curveName, key.getCurveName())
}
}
@Test
fun `test getCurveName for legacy EdDSA curves`() {
for (curve in EdDSACurve.values()) {
val key = PGPainless.buildKeyRing()
.setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA(curve)))
.build()
.publicKey
assertEquals(curve.curveName, key.getCurveName())
}
}
@Test
fun `test getCurveName fails for non-curve keys`() {
// RSA
val key = TestKeys.getJulietPublicKeyRing()
assertEquals(PublicKeyAlgorithm.RSA_GENERAL, key.publicKey.publicKeyAlgorithm)
assertThrows<IllegalArgumentException> {
key.publicKey.getCurveName()
}
}
@Test
fun `openPgpFingerprint returns fitting fingerprint`() {
val key = TestKeys.getEmilSecretKeyRing()
assertEquals(TestKeys.EMIL_FINGERPRINT, key.publicKey.openPgpFingerprint)
}
}