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