From d101d6a2296d315cb766591ffff39a6799182977 Mon Sep 17 00:00:00 2001 From: vityaman Date: Tue, 12 Nov 2024 16:42:43 +0300 Subject: [PATCH] #54 Fix build --- backend/foundation/build.gradle.kts | 3 ++- .../ru/ifmo/se/dating/security/auth/JwtTokenDecoder.kt | 1 - .../main/kotlin/ru/ifmo/se/dating/security/key/Keys.kt | 4 +--- .../{SpringClock.kt => SpringClockConfiguration.kt} | 0 .../kotlin/ru/ifmo/se/dating/security/key/KeysTest.kt | 9 +++++---- 5 files changed, 8 insertions(+), 9 deletions(-) rename backend/foundation/src/main/kotlin/ru/ifmo/se/dating/spring/{SpringClock.kt => SpringClockConfiguration.kt} (100%) diff --git a/backend/foundation/build.gradle.kts b/backend/foundation/build.gradle.kts index c571853..e8140ec 100644 --- a/backend/foundation/build.gradle.kts +++ b/backend/foundation/build.gradle.kts @@ -1,6 +1,7 @@ plugins { - id("buildlogic.spring-conventions") + id("buildlogic.kotlin-library-conventions") id("buildlogic.jooq-conventions") + kotlin("plugin.spring") } dependencies { diff --git a/backend/foundation/src/main/kotlin/ru/ifmo/se/dating/security/auth/JwtTokenDecoder.kt b/backend/foundation/src/main/kotlin/ru/ifmo/se/dating/security/auth/JwtTokenDecoder.kt index b273cf3..5e6db88 100644 --- a/backend/foundation/src/main/kotlin/ru/ifmo/se/dating/security/auth/JwtTokenDecoder.kt +++ b/backend/foundation/src/main/kotlin/ru/ifmo/se/dating/security/auth/JwtTokenDecoder.kt @@ -7,7 +7,6 @@ import ru.ifmo.se.dating.exception.AuthenticationException import java.security.PublicKey import java.time.Clock import java.util.* -import javax.crypto.SecretKey class JwtTokenDecoder( private val clock: Clock, diff --git a/backend/foundation/src/main/kotlin/ru/ifmo/se/dating/security/key/Keys.kt b/backend/foundation/src/main/kotlin/ru/ifmo/se/dating/security/key/Keys.kt index 785d0e5..0b675d7 100644 --- a/backend/foundation/src/main/kotlin/ru/ifmo/se/dating/security/key/Keys.kt +++ b/backend/foundation/src/main/kotlin/ru/ifmo/se/dating/security/key/Keys.kt @@ -31,9 +31,7 @@ object Keys { private fun split(string: String): Pair { val parts = string.split(":") - if (parts.size != 2) { - throw IllegalArgumentException("Invalid serialized key format") - } + require(parts.size == 2) val algorithm = parts[0] val encodedKey = parts[1] return algorithm to Base64.getDecoder().decode(encodedKey) diff --git a/backend/foundation/src/main/kotlin/ru/ifmo/se/dating/spring/SpringClock.kt b/backend/foundation/src/main/kotlin/ru/ifmo/se/dating/spring/SpringClockConfiguration.kt similarity index 100% rename from backend/foundation/src/main/kotlin/ru/ifmo/se/dating/spring/SpringClock.kt rename to backend/foundation/src/main/kotlin/ru/ifmo/se/dating/spring/SpringClockConfiguration.kt diff --git a/backend/foundation/src/test/kotlin/ru/ifmo/se/dating/security/key/KeysTest.kt b/backend/foundation/src/test/kotlin/ru/ifmo/se/dating/security/key/KeysTest.kt index 6f7e2ac..2839c8a 100644 --- a/backend/foundation/src/test/kotlin/ru/ifmo/se/dating/security/key/KeysTest.kt +++ b/backend/foundation/src/test/kotlin/ru/ifmo/se/dating/security/key/KeysTest.kt @@ -8,7 +8,7 @@ import javax.crypto.KeyGenerator class KeysTest { @Test fun secretRoundTrip() { - for (i in 0..32) { + repeat(32) { val key = KeyGenerator.getInstance("AES").generateKey() assertEquals(key, Keys.serialize(key).let { Keys.deserializeSecret(it) }) } @@ -16,10 +16,11 @@ class KeysTest { @Test fun publicRoundTrip() { - for (i in 0..8) { + repeat(8) { val pair = KeyPairGenerator.getInstance("RSA").genKeyPair() - assertEquals(pair.public, Keys.serialize(pair.public).let { Keys.deserializePublic(it) }) - assertEquals(pair.private, Keys.serialize(pair.private).let { Keys.deserializePrivate(it) }) + val (public, private) = pair.public to pair.private + assertEquals(public, Keys.deserializePublic(Keys.serialize(public))) + assertEquals(private, Keys.deserializePrivate(Keys.serialize(private))) } }