Skip to content

Commit 535e1cf

Browse files
committed
Apply ktlint.
1 parent 641849c commit 535e1cf

49 files changed

Lines changed: 637 additions & 479 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.gradle.kts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ plugins {
77
`version-catalog`
88

99
alias(libs.plugins.kotlin.jvm)
10-
alias(libs.plugins.versions)
11-
alias(libs.plugins.versions.filter)
10+
alias(libs.plugins.kotlinter)
11+
alias(libs.plugins.gradleVersions)
12+
alias(libs.plugins.gradleVersions.filter)
13+
alias(libs.plugins.gradleVersions.update)
1214
}
1315

1416
repositories {
@@ -18,6 +20,7 @@ repositories {
1820

1921
allprojects {
2022
apply(plugin = "java")
23+
apply(plugin = "org.jmailen.kotlinter")
2124

2225
repositories {
2326
mavenLocal()
@@ -79,5 +82,4 @@ tasks.register<JacocoReport>("codeCoverageReport") {
7982
html.required.set(false)
8083
csv.required.set(false)
8184
}
82-
8385
}

gradle/libs.versions.toml

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
11
[versions]
2-
clikt = "5.1.0"
3-
kotlin = "2.3.0"
42
bouncycastle = "1.82"
5-
kotlinx-serialization = "1.10.0"
6-
mockk = "1.14.9"
7-
kotest = "6.1.2"
8-
junit-jupiter = "6.0.1"
9-
junit-platform = "6.0.1"
3+
clikt = "5.1.0"
4+
gradleFilterVersions = "0.1.16"
5+
gradleUpdateVersions = "1.1.0"
6+
gradleVersions = "0.53.0"
107
# @keep used manually for jacoco config, see build.gradle.kts
118
jacoco = "0.8.14"
9+
junit-jupiter = "6.0.1"
10+
junit-platform = "6.0.1"
1211
# @keep jvm target
1312
jvm = "17"
13+
kotest = "6.1.2"
14+
kotlin = "2.3.0"
15+
kotlinter = "5.4.2"
16+
kotlinx-serialization = "1.10.0"
17+
mockk = "1.14.9"
1418
nmcp = "1.4.4"
1519

1620
[libraries]
1721
bouncycastle = { module = "org.bouncycastle:bcprov-jdk18on", version.ref = "bouncycastle" }
1822
clikt = { module = "com.github.ajalt.clikt:clikt", version.ref = "clikt" }
19-
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" }
20-
mockk = { module = "io.mockk:mockk", version.ref = "mockk" }
21-
kotest-assertions-core = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" }
2223
junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit-jupiter" }
23-
junit-jupiter-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "junit-jupiter" }
2424
junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit-jupiter" }
25+
junit-jupiter-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "junit-jupiter" }
2526
junit-platform-launcher = { module = "org.junit.platform:junit-platform-launcher", version.ref = "junit-platform" }
27+
kotest-assertions-core = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" }
28+
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" }
29+
mockk = { module = "io.mockk:mockk", version.ref = "mockk" }
2630

2731
[plugins]
32+
gradleVersions = { id = "com.github.ben-manes.versions", version.ref = "gradleVersions" }
33+
gradleVersions-filter = { id = "se.ascp.gradle.gradle-versions-filter", version.ref = "gradleFilterVersions" }
34+
gradleVersions-update = { id = "nl.littlerobots.version-catalog-update", version.ref = "gradleUpdateVersions" }
2835
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
2936
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
30-
versions = { id = "com.github.ben-manes.versions", version = "0.52.0" }
31-
versions-filter = { id = "se.ascp.gradle.gradle-versions-filter", version = "0.1.16" }
37+
kotlinter = { id = "org.jmailen.kotlinter", version.ref = "kotlinter" }
3238
nmcp = { id = "com.gradleup.nmcp", version.ref = "nmcp" }
3339
nmcp-aggregation = { id = "com.gradleup.nmcp.aggregation", version.ref = "nmcp" }

justfile

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env just --justfile
2+
3+
VERSION := env_var_or_default("VERSION", "")
4+
5+
# Gradle Variables
6+
in_ci := env_var_or_default("GITHUB_ACTIONS", "")
7+
gradlew_local := justfile_directory() + '/gradlew -p ' + justfile_directory()
8+
gradlew_ci := 'TERM=dumb ' + gradlew_local + ' -q'
9+
gradlew := if in_ci == "" { gradlew_local } else { gradlew_ci }
10+
11+
# Print a list of available recipes
12+
_default:
13+
@just --justfile {{justfile()}} --list --unsorted
14+
15+
16+
# Build
17+
build:
18+
{{gradlew}} -configuration-cache build -x check --warning-mode all
19+
20+
# Deletes all build outputs & artifacts
21+
clean:
22+
{{gradlew}} -configuration-cache clean
23+
24+
# Build and publish to maven central
25+
publish version=(VERSION):
26+
VERSION="{{version}}" {{gradlew}} lintKotlin test publishAggregationToCentralPortal
27+
28+
# Build and publish to local maven repository (~/.m2)
29+
publish-local version=(VERSION):
30+
VERSION="{{version}}" {{gradlew}} lintKotlin test nmcpPublishAggregationToMavenLocal
31+
32+
# Run unit tests (when all="true" all tests will run, otherwise only outdated tests run)
33+
test all="false":
34+
{{gradlew}} -configuration-cache {{ if all == "true" { "cleanTest test" } else { "test" } }}
35+
36+
# Run Gradle checks (lint, test, complexity).
37+
check:
38+
{{gradlew}} -configuration-cache check
39+
40+
# Generate a code coverage report (via Jacoco).
41+
coverage:
42+
{{gradlew}} -configuration-cache codeCoverageReport
43+
44+
# Verify source code style.
45+
lint:
46+
{{gradlew}} -configuration-cache lintKotlin
47+
48+
# Format the source code.
49+
format:
50+
{{gradlew}} -configuration-cache versionCatalogFormat formatKotlin
51+
52+
# Calculates code complexity.
53+
complexity:
54+
{{gradlew}} -configuration-cache detekt
55+
56+
# Checks for library updates.
57+
update-check:
58+
{{gradlew}} dependencyUpdates -Drevision=release
59+
60+
# Automatically updates all dependencies in the version catalog.
61+
update-apply:
62+
{{gradlew}} versionCatalogUpdate

paseto/src/main/kotlin/net/aholbrook/paseto/Claims.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ sealed interface ClaimElement {
2626
val doubleOrNull: Double? get() = null
2727
}
2828

29-
inline fun <reified T> ClaimElement.asType(): T? = when(T::class) {
29+
inline fun <reified T> ClaimElement.asType(): T? = when (T::class) {
3030
String::class -> primitiveOrNull?.stringOrNull as? T
3131
Boolean::class -> primitiveOrNull?.booleanOrNull as? T
3232
Int::class -> primitiveOrNull?.intOrNull as? T
@@ -42,18 +42,20 @@ object ClaimNull : ClaimElement
4242
@JvmInline
4343
@Suppress("JavaDefaultMethodsNotOverriddenByDelegation")
4444
value class ClaimArray internal constructor(private val content: List<ClaimElement>) :
45-
ClaimElement, List<ClaimElement> by content {
45+
ClaimElement,
46+
List<ClaimElement> by content {
4647

4748
internal constructor(jsonArray: JsonArray) : this(jsonArray.map { it.toClaim() })
4849
}
4950

5051
@JvmInline
5152
value class ClaimObject internal constructor(private val content: Map<String, ClaimElement>) :
52-
ClaimElement, Map<String, ClaimElement> by content {
53+
ClaimElement,
54+
Map<String, ClaimElement> by content {
5355

5456
internal constructor() : this(emptyMap())
5557
internal constructor(jsonObject: JsonObject) : this(
56-
content = jsonObject.mapValues { it.value.toClaim() }
58+
content = jsonObject.mapValues { it.value.toClaim() },
5759
)
5860
}
5961

paseto/src/main/kotlin/net/aholbrook/paseto/Serde.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ internal object PasetoTokenSerializer : KSerializer<PasetoToken> {
3030

3131
fun take(name: String) = obj[name]?.jsonPrimitive?.contentOrNull
3232

33-
fun takeInstant(name: String): Instant? =
34-
obj[name]?.jsonPrimitive?.contentOrNull?.let { Instant.parse(it) }
33+
fun takeInstant(name: String): Instant? = obj[name]?.jsonPrimitive?.contentOrNull?.let { Instant.parse(it) }
3534

3635
val claims = buildJsonObject {
3736
obj.filterNot { it.key in reserved }.forEach { put(it.key, it.value) }

paseto/src/main/kotlin/net/aholbrook/paseto/Token.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ inline fun pasetoToken(clock: Clock = Clock.systemUTC(), init: PasetoTokenBuilde
5353
}
5454

5555
sealed interface PasetoFooter
56+
5657
@JvmInline
5758
value class StringFooter internal constructor(val value: String) : PasetoFooter
5859

@@ -77,6 +78,7 @@ class ClaimFooterBuilder @PublishedApi internal constructor() {
7778
}
7879

7980
fun pasetoFooter(footer: String) = StringFooter(footer)
81+
8082
@OptIn(ExperimentalContracts::class)
8183
inline fun pasetoFooter(init: ClaimFooterBuilder.() -> Unit): ClaimFooter {
8284
contract { callsInPlace(init, InvocationKind.EXACTLY_ONCE) }

paseto/src/main/kotlin/net/aholbrook/paseto/TokenService.kt

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,7 @@ internal class LocalTokenService internal constructor(
8888
return paseto.encrypt(encoded, keyProvider(), encodedFooter, implicitAssertion)
8989
}
9090

91-
override fun decode(
92-
token: String,
93-
footer: PasetoFooter?,
94-
implicitAssertion: String?
95-
): PasetoToken {
91+
override fun decode(token: String, footer: PasetoFooter?, implicitAssertion: String?): PasetoToken {
9692
if (!implicitAssertion.isNullOrEmpty() && !paseto.supportsImplicitAssertion) {
9793
throw ImplicitAssertionsNotSupportedException(paseto.version)
9894
}
@@ -105,7 +101,8 @@ internal class LocalTokenService internal constructor(
105101
return decoded
106102
}
107103

108-
override fun insecureGetFooter(token: String): TaintedPasetoFooter? = json.decodeFooter(extractFooter(token)).taint()
104+
override fun insecureGetFooter(token: String): TaintedPasetoFooter? =
105+
json.decodeFooter(extractFooter(token)).taint()
109106
}
110107

111108
internal class PublicTokenService internal constructor(
@@ -124,15 +121,13 @@ internal class PublicTokenService internal constructor(
124121
val encoded = json.encodeToString(PasetoTokenSerializer, token)
125122
val encodedFooter = json.encodeFooter(token.footer)
126123
val keyPair = keyProvider()
127-
if (keyPair.secretKey == null) { throw CannotSignWithoutSecretKey() }
124+
if (keyPair.secretKey == null) {
125+
throw CannotSignWithoutSecretKey()
126+
}
128127
return paseto.sign(encoded, keyPair.secretKey, encodedFooter, implicitAssertion)
129128
}
130129

131-
override fun decode(
132-
token: String,
133-
footer: PasetoFooter?,
134-
implicitAssertion: String?
135-
): PasetoToken {
130+
override fun decode(token: String, footer: PasetoFooter?, implicitAssertion: String?): PasetoToken {
136131
// TODO expand service-test-vectors for v4 with implicit assertions
137132
if (!implicitAssertion.isNullOrEmpty() && !paseto.supportsImplicitAssertion) {
138133
throw ImplicitAssertionsNotSupportedException(paseto.version)
@@ -146,7 +141,8 @@ internal class PublicTokenService internal constructor(
146141
return decoded
147142
}
148143

149-
override fun insecureGetFooter(token: String): TaintedPasetoFooter? = json.decodeFooter(extractFooter(token)).taint()
144+
override fun insecureGetFooter(token: String): TaintedPasetoFooter? =
145+
json.decodeFooter(extractFooter(token)).taint()
150146
}
151147

152148
private fun Json.encodeFooter(footer: PasetoFooter?): String? = footer?.let { footer ->

paseto/src/main/kotlin/net/aholbrook/paseto/crypto/ConstantTimeEquals.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal fun ByteArray.constantTimeEquals(expected: ByteArray): Boolean {
2727
for (i in indices) {
2828
result = result or (this[i].toInt() xor expected[i].toInt())
2929
}
30-
return result==0
30+
return result == 0
3131
}
3232
}
3333

0 commit comments

Comments
 (0)