mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-23 03:17:58 +01:00
Add tests for PGPPublicKeyExtensions
This commit is contained in:
parent
e561d58562
commit
c89c47c491
1 changed files with 60 additions and 0 deletions
|
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue