mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-01-08 19:27:57 +01:00
Spotless apply
This commit is contained in:
parent
c2abc89d5e
commit
cbbd980554
4 changed files with 33 additions and 61 deletions
|
@ -37,36 +37,20 @@ class PGPKeyRingExtensionsTest {
|
|||
@Test
|
||||
fun `test requirePublicKey on secret key ring`() {
|
||||
val key = TestKeys.getJulietSecretKeyRing()
|
||||
assertNotNull(assertDoesNotThrow {
|
||||
key.requirePublicKey(TestKeys.JULIET_KEY_ID)
|
||||
})
|
||||
assertNotNull(assertDoesNotThrow {
|
||||
key.requirePublicKey(TestKeys.JULIET_FINGERPRINT)
|
||||
})
|
||||
assertNotNull(assertDoesNotThrow { key.requirePublicKey(TestKeys.JULIET_KEY_ID) })
|
||||
assertNotNull(assertDoesNotThrow { key.requirePublicKey(TestKeys.JULIET_FINGERPRINT) })
|
||||
|
||||
assertThrows<NoSuchElementException> {
|
||||
key.requirePublicKey(TestKeys.ROMEO_KEY_ID)
|
||||
}
|
||||
assertThrows<NoSuchElementException> {
|
||||
key.requirePublicKey(TestKeys.ROMEO_FINGERPRINT)
|
||||
}
|
||||
assertThrows<NoSuchElementException> { key.requirePublicKey(TestKeys.ROMEO_KEY_ID) }
|
||||
assertThrows<NoSuchElementException> { key.requirePublicKey(TestKeys.ROMEO_FINGERPRINT) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test requirePublicKey on public key ring`() {
|
||||
val key = TestKeys.getJulietPublicKeyRing()
|
||||
assertNotNull(assertDoesNotThrow {
|
||||
key.requirePublicKey(TestKeys.JULIET_KEY_ID)
|
||||
})
|
||||
assertNotNull(assertDoesNotThrow {
|
||||
key.requirePublicKey(TestKeys.JULIET_FINGERPRINT)
|
||||
})
|
||||
assertNotNull(assertDoesNotThrow { key.requirePublicKey(TestKeys.JULIET_KEY_ID) })
|
||||
assertNotNull(assertDoesNotThrow { key.requirePublicKey(TestKeys.JULIET_FINGERPRINT) })
|
||||
|
||||
assertThrows<NoSuchElementException> {
|
||||
key.requirePublicKey(TestKeys.ROMEO_KEY_ID)
|
||||
}
|
||||
assertThrows<NoSuchElementException> {
|
||||
key.requirePublicKey(TestKeys.ROMEO_FINGERPRINT)
|
||||
}
|
||||
assertThrows<NoSuchElementException> { key.requirePublicKey(TestKeys.ROMEO_KEY_ID) }
|
||||
assertThrows<NoSuchElementException> { key.requirePublicKey(TestKeys.ROMEO_FINGERPRINT) }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,10 +20,11 @@ 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
|
||||
val key =
|
||||
PGPainless.buildKeyRing()
|
||||
.setPrimaryKey(KeySpec.getBuilder(KeyType.ECDSA(curve)))
|
||||
.build()
|
||||
.publicKey
|
||||
|
||||
assertEquals(curve.curveName, key.getCurveName())
|
||||
}
|
||||
|
@ -32,10 +33,11 @@ class PGPPublicKeyExtensionsTest {
|
|||
@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
|
||||
val key =
|
||||
PGPainless.buildKeyRing()
|
||||
.setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA(curve)))
|
||||
.build()
|
||||
.publicKey
|
||||
|
||||
assertEquals(curve.curveName, key.getCurveName())
|
||||
}
|
||||
|
@ -47,9 +49,7 @@ class PGPPublicKeyExtensionsTest {
|
|||
val key = TestKeys.getJulietPublicKeyRing()
|
||||
assertEquals(PublicKeyAlgorithm.RSA_GENERAL, key.publicKey.publicKeyAlgorithm)
|
||||
|
||||
assertThrows<IllegalArgumentException> {
|
||||
key.publicKey.getCurveName()
|
||||
}
|
||||
assertThrows<IllegalArgumentException> { key.publicKey.getCurveName() }
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -21,9 +21,7 @@ class PGPSecretKeyExtensionsTest {
|
|||
val key = TestKeys.getCryptieSecretKeyRing()
|
||||
val secKey = key.secretKey
|
||||
|
||||
val privKey = assertDoesNotThrow {
|
||||
secKey.unlock(TestKeys.CRYPTIE_PASSPHRASE)
|
||||
}
|
||||
val privKey = assertDoesNotThrow { secKey.unlock(TestKeys.CRYPTIE_PASSPHRASE) }
|
||||
assertNotNull(privKey)
|
||||
}
|
||||
|
||||
|
@ -32,9 +30,7 @@ class PGPSecretKeyExtensionsTest {
|
|||
val key = TestKeys.getCryptieSecretKeyRing()
|
||||
val secKey = key.secretKey
|
||||
|
||||
assertThrows<WrongPassphraseException> {
|
||||
secKey.unlock(Passphrase.emptyPassphrase())
|
||||
}
|
||||
assertThrows<WrongPassphraseException> { secKey.unlock(Passphrase.emptyPassphrase()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -42,9 +38,7 @@ class PGPSecretKeyExtensionsTest {
|
|||
val key = TestKeys.getEmilSecretKeyRing()
|
||||
val secKey = key.secretKey
|
||||
|
||||
val privKey = assertDoesNotThrow {
|
||||
secKey.unlock()
|
||||
}
|
||||
val privKey = assertDoesNotThrow { secKey.unlock() }
|
||||
assertNotNull(privKey)
|
||||
}
|
||||
|
||||
|
@ -53,9 +47,7 @@ class PGPSecretKeyExtensionsTest {
|
|||
val key = TestKeys.getEmilSecretKeyRing()
|
||||
val secKey = key.secretKey
|
||||
|
||||
val privKey = assertDoesNotThrow {
|
||||
secKey.unlock(Passphrase.emptyPassphrase())
|
||||
}
|
||||
val privKey = assertDoesNotThrow { secKey.unlock(Passphrase.emptyPassphrase()) }
|
||||
assertNotNull(privKey)
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
package org.pgpainless.bouncycastle.extensions
|
||||
|
||||
import java.io.ByteArrayOutputStream
|
||||
import org.junit.jupiter.api.Assertions.assertFalse
|
||||
import org.junit.jupiter.api.Assertions.assertNotNull
|
||||
import org.junit.jupiter.api.Assertions.assertNull
|
||||
|
@ -15,7 +16,6 @@ import org.pgpainless.encryption_signing.ProducerOptions
|
|||
import org.pgpainless.encryption_signing.SigningOptions
|
||||
import org.pgpainless.key.TestKeys
|
||||
import org.pgpainless.key.protection.SecretKeyRingProtector
|
||||
import java.io.ByteArrayOutputStream
|
||||
|
||||
class PGPSecretKeyRingExtensionsTest {
|
||||
|
||||
|
@ -35,24 +35,20 @@ class PGPSecretKeyRingExtensionsTest {
|
|||
assertNotNull(key.requireSecretKey(TestKeys.EMIL_KEY_ID))
|
||||
assertNotNull(key.requireSecretKey(TestKeys.EMIL_FINGERPRINT))
|
||||
|
||||
assertThrows<NoSuchElementException> {
|
||||
key.requireSecretKey(TestKeys.ROMEO_KEY_ID)
|
||||
}
|
||||
assertThrows<NoSuchElementException> {
|
||||
key.requireSecretKey(TestKeys.ROMEO_FINGERPRINT)
|
||||
}
|
||||
assertThrows<NoSuchElementException> { key.requireSecretKey(TestKeys.ROMEO_KEY_ID) }
|
||||
assertThrows<NoSuchElementException> { key.requireSecretKey(TestKeys.ROMEO_FINGERPRINT) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetSecretKeyForSignature() {
|
||||
val key = TestKeys.getEmilSecretKeyRing()
|
||||
val signer = PGPainless.encryptAndOrSign()
|
||||
.onOutputStream(ByteArrayOutputStream())
|
||||
.withOptions(
|
||||
ProducerOptions.sign(SigningOptions.get()
|
||||
.addDetachedSignature(SecretKeyRingProtector.unprotectedKeys(), key)
|
||||
)
|
||||
)
|
||||
val signer =
|
||||
PGPainless.encryptAndOrSign()
|
||||
.onOutputStream(ByteArrayOutputStream())
|
||||
.withOptions(
|
||||
ProducerOptions.sign(
|
||||
SigningOptions.get()
|
||||
.addDetachedSignature(SecretKeyRingProtector.unprotectedKeys(), key)))
|
||||
signer.write("Hello, World!\n".toByteArray())
|
||||
signer.close()
|
||||
val sig = signer.result.detachedSignatures.first().value.first()
|
||||
|
|
Loading…
Reference in a new issue