diff --git a/settings.gradle.kts b/settings.gradle.kts index 1d7527a..da5c0ac 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -16,7 +16,7 @@ pluginManagement { "ru.vyarus.animalsniffer", "org.jetbrains.kotlin.jvm", "com.diffplug.spotless", - "com.github.ben-manes.versions" + "com.github.ben-manes.versions", ) .forEach { plugin -> includeModule(plugin, "${plugin}.gradle.plugin") } includeModule("com.github.ben-manes", "gradle-versions-plugin") diff --git a/src/kotlin/kage/Age.kt b/src/kotlin/kage/Age.kt index 2ddb478..c8694a3 100644 --- a/src/kotlin/kage/Age.kt +++ b/src/kotlin/kage/Age.kt @@ -36,7 +36,7 @@ public object Age { recipients: List, inputStream: InputStream, outputStream: OutputStream, - generateArmor: Boolean = false + generateArmor: Boolean = false, ) { val dstStream = if (generateArmor) ArmorOutputStream(outputStream) else outputStream @@ -60,7 +60,7 @@ public object Age { public fun decryptStream( identities: List, srcStream: InputStream, - dstStream: OutputStream + dstStream: OutputStream, ) { val markSupportedStream = @@ -97,7 +97,7 @@ public object Age { private fun encryptInternal( recipients: List, dst: OutputStream, - writeHeaders: Boolean = true + writeHeaders: Boolean = true, ): Pair { if (recipients.isEmpty()) { throw NoRecipientsException("No recipients specified") diff --git a/src/kotlin/kage/crypto/scrypt/ScryptIdentity.kt b/src/kotlin/kage/crypto/scrypt/ScryptIdentity.kt index 7cc0617..0046664 100644 --- a/src/kotlin/kage/crypto/scrypt/ScryptIdentity.kt +++ b/src/kotlin/kage/crypto/scrypt/ScryptIdentity.kt @@ -18,7 +18,7 @@ import org.bouncycastle.crypto.generators.SCrypt public class ScryptIdentity( private val password: ByteArray, - private val maxWorkFactor: Int = DEFAULT_WORK_FACTOR + private val maxWorkFactor: Int = DEFAULT_WORK_FACTOR, ) : Identity { init { diff --git a/src/kotlin/kage/crypto/scrypt/ScryptRecipient.kt b/src/kotlin/kage/crypto/scrypt/ScryptRecipient.kt index b34fb4b..df3f1ef 100644 --- a/src/kotlin/kage/crypto/scrypt/ScryptRecipient.kt +++ b/src/kotlin/kage/crypto/scrypt/ScryptRecipient.kt @@ -15,7 +15,7 @@ import org.bouncycastle.crypto.generators.SCrypt public class ScryptRecipient( private val password: ByteArray, - private val workFactor: Int = DEFAULT_WORK_FACTOR + private val workFactor: Int = DEFAULT_WORK_FACTOR, ) : Recipient { override fun wrap(fileKey: ByteArray): List { diff --git a/src/kotlin/kage/crypto/stream/ChaCha20Poly1305.kt b/src/kotlin/kage/crypto/stream/ChaCha20Poly1305.kt index 34c8c6f..d721878 100644 --- a/src/kotlin/kage/crypto/stream/ChaCha20Poly1305.kt +++ b/src/kotlin/kage/crypto/stream/ChaCha20Poly1305.kt @@ -52,7 +52,7 @@ internal object ChaCha20Poly1305 { inOff: Int, inLen: Int, out: ByteArray, - outOff: Int + outOff: Int, ): Int { val cipher = ChaCha20Poly1305() val secKey = KeyParameter(key) diff --git a/src/kotlin/kage/errors/Bech32Exception.kt b/src/kotlin/kage/errors/Bech32Exception.kt index 63ca569..47d0d22 100644 --- a/src/kotlin/kage/errors/Bech32Exception.kt +++ b/src/kotlin/kage/errors/Bech32Exception.kt @@ -6,7 +6,5 @@ package kage.errors /** Thrown when encoding or decoding Bech32 */ -public class Bech32Exception( - message: String? = null, - cause: Throwable? = null, -) : Exception(message, cause) +public class Bech32Exception(message: String? = null, cause: Throwable? = null) : + Exception(message, cause) diff --git a/src/kotlin/kage/errors/CryptoException.kt b/src/kotlin/kage/errors/CryptoException.kt index e38aa93..0a2e6f0 100644 --- a/src/kotlin/kage/errors/CryptoException.kt +++ b/src/kotlin/kage/errors/CryptoException.kt @@ -6,63 +6,46 @@ package kage.errors /** Wrapper class for errors raised during a cryptographic operation. */ -public sealed class CryptoException( - message: String? = null, - cause: Throwable? = null, -) : Exception(message, cause) +public sealed class CryptoException(message: String? = null, cause: Throwable? = null) : + Exception(message, cause) /** Raised when no [kage.Recipient] is available in the ciphertext. */ -public class NoRecipientsException( - message: String? = null, - cause: Throwable? = null, -) : CryptoException(message, cause) +public class NoRecipientsException(message: String? = null, cause: Throwable? = null) : + CryptoException(message, cause) /** * Raised when there are more than one [kage.Recipient]s and one is an * [kage.crypto.scrypt.ScryptRecipient]. This is a specially cased situation from the spec which * requires that there only be one [kage.Recipient] if it is a [kage.crypto.scrypt.ScryptRecipient]. */ -public class InvalidScryptRecipientException( - message: String? = null, - cause: Throwable? = null, -) : CryptoException(message, cause) +public class InvalidScryptRecipientException(message: String? = null, cause: Throwable? = null) : + CryptoException(message, cause) /** Raised when an incompatible stanza is provided to [kage.Identity.unwrap] */ -public sealed class InvalidIdentityException( - message: String? = null, - cause: Throwable? = null, -) : CryptoException(message, cause) +public sealed class InvalidIdentityException(message: String? = null, cause: Throwable? = null) : + CryptoException(message, cause) /** Raised when an error occurs when unwrapping an scrypt stanza from an [kage.Identity]. */ -public class ScryptIdentityException( - message: String? = null, - cause: Throwable? = null, -) : InvalidIdentityException(message, cause) +public class ScryptIdentityException(message: String? = null, cause: Throwable? = null) : + InvalidIdentityException(message, cause) /** Raised when an error occurs when unwrapping a X25519 stanza from an [kage.Identity]. */ -public class X25519IdentityException( - message: String? = null, - cause: Throwable? = null, -) : InvalidIdentityException(message, cause) +public class X25519IdentityException(message: String? = null, cause: Throwable? = null) : + InvalidIdentityException(message, cause) /** * Raised when an error occurs while calculating the X25519 shared secret. If the X25519 share is a * low order point, the shared secret is the disallowed all-zero value. */ -public class X25519LowOrderPointException( - message: String? = null, - cause: Throwable? = null, -) : InvalidIdentityException(message, cause) +public class X25519LowOrderPointException(message: String? = null, cause: Throwable? = null) : + InvalidIdentityException(message, cause) /** Raised when there are no [kage.Identity]s when decrypting a ciphertext */ -public class NoIdentitiesException( - message: String? = null, - cause: Throwable? = null, -) : InvalidIdentityException(message, cause) +public class NoIdentitiesException(message: String? = null, cause: Throwable? = null) : + InvalidIdentityException(message, cause) -public class IncorrectCipherTextSizeException( - cause: Throwable? = null, -) : CryptoException("Incorrect cipher text size", cause) +public class IncorrectCipherTextSizeException(cause: Throwable? = null) : + CryptoException("Incorrect cipher text size", cause) /** * Raised when an identity is not suitable to decrypt a specific recipient block. @@ -70,36 +53,25 @@ public class IncorrectCipherTextSizeException( * This is not a fatal exception, kage code should catch this exception and try a different * identity, or fail if other identity does not exist */ -public class IncorrectIdentityException( - cause: Throwable? = null, -) : CryptoException("incorrect identity for recipient block", cause) +public class IncorrectIdentityException(cause: Throwable? = null) : + CryptoException("incorrect identity for recipient block", cause) /** Thrown when an error occurs while streaming encrypted or decrypted data */ -public class StreamException( - message: String? = null, - cause: Throwable? = null, -) : CryptoException(message, cause) +public class StreamException(message: String? = null, cause: Throwable? = null) : + CryptoException(message, cause) /** Raised when the Base64 string is not canonical according to RFC 4648 section 3.5 */ -public class InvalidBase64StringException( - message: String? = null, - cause: Throwable? = null, -) : CryptoException(message, cause) +public class InvalidBase64StringException(message: String? = null, cause: Throwable? = null) : + CryptoException(message, cause) /** Raised when the mac is incorrect */ -public class IncorrectHMACException( - message: String? = null, - cause: Throwable? = null, -) : CryptoException(message, cause) +public class IncorrectHMACException(message: String? = null, cause: Throwable? = null) : + CryptoException(message, cause) /** Raised when the mac is invalid (truncated or the wrong size) */ -public class InvalidHMACHeaderException( - message: String? = null, - cause: Throwable? = null, -) : CryptoException(message, cause) +public class InvalidHMACHeaderException(message: String? = null, cause: Throwable? = null) : + CryptoException(message, cause) /** Thrown when an error occurs while encoding/decoding armor data */ -public class ArmorCodingException( - message: String? = null, - cause: Throwable? = null, -) : CryptoException(message, cause) +public class ArmorCodingException(message: String? = null, cause: Throwable? = null) : + CryptoException(message, cause) diff --git a/src/kotlin/kage/errors/ParseException.kt b/src/kotlin/kage/errors/ParseException.kt index a7067a1..4571375 100644 --- a/src/kotlin/kage/errors/ParseException.kt +++ b/src/kotlin/kage/errors/ParseException.kt @@ -6,46 +6,32 @@ package kage.errors /** Wrapper type for errors triggered while parsing an [kage.format.AgeStanza] */ -public sealed class ParseException( - message: String? = null, - cause: Throwable? = null, -) : Exception(message, cause) +public sealed class ParseException(message: String? = null, cause: Throwable? = null) : + Exception(message, cause) /** Raised when a non-ASCII string is encountered when parsing an [kage.format.AgeHeader]. */ -public class InvalidArbitraryStringException( - message: String? = null, - cause: Throwable? = null, -) : ParseException(message, cause) +public class InvalidArbitraryStringException(message: String? = null, cause: Throwable? = null) : + ParseException(message, cause) /** Raised when the parsed version is not an expected one. */ -public class InvalidVersionException( - message: String? = null, - cause: Throwable? = null, -) : ParseException(message, cause) +public class InvalidVersionException(message: String? = null, cause: Throwable? = null) : + ParseException(message, cause) /** Raised when a failure occurs while parsing [kage.format.AgeStanza] for [kage.Recipient]s. */ -public class InvalidRecipientException( - message: String? = null, - cause: Throwable? = null, -) : ParseException(message, cause) +public class InvalidRecipientException(message: String? = null, cause: Throwable? = null) : + ParseException(message, cause) /** Raised when the footer for a [kage.format.AgeHeader] is incorrect. */ -public class InvalidFooterException( - message: String? = null, - cause: Throwable? = null, -) : ParseException(message, cause) +public class InvalidFooterException(message: String? = null, cause: Throwable? = null) : + ParseException(message, cause) /** Raised when the [kage.format.AgeHeader.mac] is empty when writing a [kage.format.AgeHeader]. */ -public class InvalidHMACException( - message: String? = null, - cause: Throwable? = null, -) : ParseException(message, cause) +public class InvalidHMACException(message: String? = null, cause: Throwable? = null) : + ParseException(message, cause) /** * Raised when the [kage.format.AgeKeyFile.privateKey] is empty when parsing a * [kage.format.AgeKeyFile]. */ -public class InvalidAgeKeyException( - message: String? = null, - cause: Throwable? = null, -) : ParseException(message, cause) +public class InvalidAgeKeyException(message: String? = null, cause: Throwable? = null) : + ParseException(message, cause) diff --git a/src/kotlin/kage/format/AgeKeyFile.kt b/src/kotlin/kage/format/AgeKeyFile.kt index 0945625..9c5bc37 100644 --- a/src/kotlin/kage/format/AgeKeyFile.kt +++ b/src/kotlin/kage/format/AgeKeyFile.kt @@ -15,7 +15,7 @@ import kage.utils.writeNewLine public class AgeKeyFile( public val created: String, public val publicKey: X25519Recipient?, - public val privateKey: X25519Identity + public val privateKey: X25519Identity, ) { override fun equals(other: Any?): Boolean { if (other == null) return false diff --git a/src/kotlin/kage/format/AgeStanza.kt b/src/kotlin/kage/format/AgeStanza.kt index 937c534..eb3d8f4 100644 --- a/src/kotlin/kage/format/AgeStanza.kt +++ b/src/kotlin/kage/format/AgeStanza.kt @@ -27,7 +27,7 @@ import kage.utils.writeSpace public class AgeStanza( public val type: String, public val args: List, - public val body: ByteArray + public val body: ByteArray, ) { override fun equals(other: Any?): Boolean { @@ -86,7 +86,7 @@ public class AgeStanza( encodedBody.windowed( size = COLUMNS_PER_LINE, step = COLUMNS_PER_LINE, - partialWindows = true + partialWindows = true, ) lines.forEach { writer.write(it) diff --git a/src/kotlin/kage/format/Bech32.kt b/src/kotlin/kage/format/Bech32.kt index c678af5..46e41e3 100644 --- a/src/kotlin/kage/format/Bech32.kt +++ b/src/kotlin/kage/format/Bech32.kt @@ -72,7 +72,7 @@ internal object Bech32 { data: ByteArray, frombits: Byte, tobits: Byte, - pad: Boolean + pad: Boolean, ): Bech32Result { val ret = mutableListOf() var acc = 0u diff --git a/src/test/kotlin/AgeTest.kt b/src/test/kotlin/AgeTest.kt index b1f7d3a..30985ff 100644 --- a/src/test/kotlin/AgeTest.kt +++ b/src/test/kotlin/AgeTest.kt @@ -247,7 +247,7 @@ class AgeTest { Age.encryptStream( listOf(agePublicKey), ByteArrayInputStream(payload.toByteArray()), - ciphertextStream + ciphertextStream, ) val ciphertext = Base64.toBase64String(ciphertextStream.toByteArray()) diff --git a/src/test/kotlin/kage/ArmorTest.kt b/src/test/kotlin/kage/ArmorTest.kt index 39afe3d..18a7cd1 100644 --- a/src/test/kotlin/kage/ArmorTest.kt +++ b/src/test/kotlin/kage/ArmorTest.kt @@ -182,7 +182,7 @@ class ArmorTest { listOf(recipient), payload.byteInputStream(), encryptedOutput, - generateArmor = true + generateArmor = true, ) val decryptedOutput = ByteArrayOutputStream() diff --git a/src/test/kotlin/kage/format/AgeKeyFileTest.kt b/src/test/kotlin/kage/format/AgeKeyFileTest.kt index 39b66ce..2fde076 100644 --- a/src/test/kotlin/kage/format/AgeKeyFileTest.kt +++ b/src/test/kotlin/kage/format/AgeKeyFileTest.kt @@ -32,9 +32,7 @@ class AgeKeyFileTest { assertThat(key.publicKey?.encodeToString()) .isEqualTo("age1mrmfnwhtlprn4jquex0ukmwcm7y2nxlphuzgsgv8ew2k9mewy3rs8u7su5") assertThat(key.privateKey.encodeToString()) - .isEqualTo( - "AGE-SECRET-KEY-1EKYFFCK627939WTZMTT4ZRS2PM3U2K7PZ3MVGEL2M76W3PYJMSHQMTT6SS", - ) + .isEqualTo("AGE-SECRET-KEY-1EKYFFCK627939WTZMTT4ZRS2PM3U2K7PZ3MVGEL2M76W3PYJMSHQMTT6SS") } @Test diff --git a/src/test/kotlin/kage/format/Bech32Test.kt b/src/test/kotlin/kage/format/Bech32Test.kt index c6d7a24..96b9a36 100644 --- a/src/test/kotlin/kage/format/Bech32Test.kt +++ b/src/test/kotlin/kage/format/Bech32Test.kt @@ -50,12 +50,12 @@ class Bech32Test { T("a12uel5l", true), T( "an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1tt5tgs", - true + true, ), T("abcdef1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw", true), T( "11qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc8247j", - true + true, ), T("split1checkupstagehandshakeupstreamerranterredcaperred2y9e3w", true), @@ -69,18 +69,18 @@ class Bech32Test { // invalid character (DEL) in hrp T( "spl" + (127).toChar() + "t1checkupstagehandshakeupstreamerranterredcaperred2y9e3w", - false + false, ), // too long T( "11qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqsqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc8247j", - false + false, ), // BIP 173 invalid vectors. T( "an84characterslonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1569pvx", - false + false, ), T("pzry9x0s0muk", false), T("1pzry9x0s0muk", false), diff --git a/src/test/kotlin/kage/test/utils/Bytes.kt b/src/test/kotlin/kage/test/utils/Bytes.kt index 5383a18..af03c65 100644 --- a/src/test/kotlin/kage/test/utils/Bytes.kt +++ b/src/test/kotlin/kage/test/utils/Bytes.kt @@ -45,8 +45,5 @@ class BytesTest { assertThat(rest).isNull() } - private fun check( - testString: String, - split: Char, - ) = testString.encodeToByteArray().split(split) + private fun check(testString: String, split: Char) = testString.encodeToByteArray().split(split) }