Skip to content

Commit

Permalink
chore: reformat with ktfmt 0.47
Browse files Browse the repository at this point in the history
  • Loading branch information
msfjarvis committed Jan 17, 2024
1 parent 8379de6 commit 1560ff7
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 115 deletions.
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions src/kotlin/kage/Age.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public object Age {
recipients: List<Recipient>,
inputStream: InputStream,
outputStream: OutputStream,
generateArmor: Boolean = false
generateArmor: Boolean = false,
) {
val dstStream = if (generateArmor) ArmorOutputStream(outputStream) else outputStream

Expand All @@ -60,7 +60,7 @@ public object Age {
public fun decryptStream(
identities: List<Identity>,
srcStream: InputStream,
dstStream: OutputStream
dstStream: OutputStream,
) {

val markSupportedStream =
Expand Down Expand Up @@ -97,7 +97,7 @@ public object Age {
private fun encryptInternal(
recipients: List<Recipient>,
dst: OutputStream,
writeHeaders: Boolean = true
writeHeaders: Boolean = true,
): Pair<AgeHeader, OutputStream> {
if (recipients.isEmpty()) {
throw NoRecipientsException("No recipients specified")
Expand Down
2 changes: 1 addition & 1 deletion src/kotlin/kage/crypto/scrypt/ScryptIdentity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/kotlin/kage/crypto/scrypt/ScryptRecipient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<AgeStanza> {
Expand Down
2 changes: 1 addition & 1 deletion src/kotlin/kage/crypto/stream/ChaCha20Poly1305.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions src/kotlin/kage/errors/Bech32Exception.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
88 changes: 30 additions & 58 deletions src/kotlin/kage/errors/CryptoException.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,100 +6,72 @@
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.
*
* 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)
42 changes: 14 additions & 28 deletions src/kotlin/kage/errors/ParseException.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion src/kotlin/kage/format/AgeKeyFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/kotlin/kage/format/AgeStanza.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import kage.utils.writeSpace
public class AgeStanza(
public val type: String,
public val args: List<String>,
public val body: ByteArray
public val body: ByteArray,
) {

override fun equals(other: Any?): Boolean {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/kotlin/kage/format/Bech32.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ internal object Bech32 {
data: ByteArray,
frombits: Byte,
tobits: Byte,
pad: Boolean
pad: Boolean,
): Bech32Result<ByteArray> {
val ret = mutableListOf<Byte>()
var acc = 0u
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/AgeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class AgeTest {
Age.encryptStream(
listOf(agePublicKey),
ByteArrayInputStream(payload.toByteArray()),
ciphertextStream
ciphertextStream,
)

val ciphertext = Base64.toBase64String(ciphertextStream.toByteArray())
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/kage/ArmorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class ArmorTest {
listOf(recipient),
payload.byteInputStream(),
encryptedOutput,
generateArmor = true
generateArmor = true,
)

val decryptedOutput = ByteArrayOutputStream()
Expand Down
4 changes: 1 addition & 3 deletions src/test/kotlin/kage/format/AgeKeyFileTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/test/kotlin/kage/format/Bech32Test.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ class Bech32Test {
T("a12uel5l", true),
T(
"an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1tt5tgs",
true
true,
),
T("abcdef1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw", true),
T(
"11qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc8247j",
true
true,
),
T("split1checkupstagehandshakeupstreamerranterredcaperred2y9e3w", true),

Expand All @@ -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),
Expand Down
5 changes: 1 addition & 4 deletions src/test/kotlin/kage/test/utils/Bytes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 1560ff7

Please sign in to comment.