From 4c782bf75599611db25c359d4dc7403511733915 Mon Sep 17 00:00:00 2001 From: Xinsong Cui Date: Tue, 4 Mar 2025 10:15:24 -0500 Subject: [PATCH 1/4] add support for md5 checksum validation --- runtime/runtime-core/api/runtime-core.api | 1 + .../runtime/config/EnvironmentSetting.kt | 19 +++++++++++++++++++ .../aws/smithy/kotlin/runtime/hashing/Md5.kt | 1 + .../smithy/kotlin/runtime/hashing/Md5JVM.kt | 1 + .../kotlin/runtime/hashing/Md5Native.kt | 4 ++++ 5 files changed, 26 insertions(+) diff --git a/runtime/runtime-core/api/runtime-core.api b/runtime/runtime-core/api/runtime-core.api index 0d5399d430..1c36811265 100644 --- a/runtime/runtime-core/api/runtime-core.api +++ b/runtime/runtime-core/api/runtime-core.api @@ -725,6 +725,7 @@ public final class aws/smithy/kotlin/runtime/hashing/Md5 : aws/smithy/kotlin/run public fun ()V public fun digest ()[B public fun reset ()V + public final fun update (B)V public fun update ([BII)V } diff --git a/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/config/EnvironmentSetting.kt b/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/config/EnvironmentSetting.kt index e5dda44f68..16e87092d1 100644 --- a/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/config/EnvironmentSetting.kt +++ b/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/config/EnvironmentSetting.kt @@ -68,3 +68,22 @@ public inline fun > enumEnvSetting(sysProp: String, envVar: } return EnvironmentSetting(parse, sysProp, envVar) } + +@InternalApi +public inline fun > enumSetEnvSetting(sysProp: String, envVar: String): EnvironmentSetting?> { + val parse = { strValue: String -> + strValue.split(",") + .map { it.trim() } + .filter { it.isNotEmpty() } + .map { enumValue -> + enumValues() + .firstOrNull { it.name.equals(enumValue, ignoreCase = true) } + ?: throw ClientException( + "Value $enumValue is not supported, should be one of ${enumValues().joinToString(", ")}" + ) + } + .toSet() + .takeIf { it.isNotEmpty() } + } + return EnvironmentSetting(parse, sysProp, envVar) +} diff --git a/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/hashing/Md5.kt b/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/hashing/Md5.kt index 176ada4cdb..8e6b946c3f 100644 --- a/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/hashing/Md5.kt +++ b/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/hashing/Md5.kt @@ -18,6 +18,7 @@ public abstract class Md5Base : HashFunction { @InternalApi public expect class Md5() : Md5Base { override fun update(input: ByteArray, offset: Int, length: Int) + public fun update(input: Byte) override fun digest(): ByteArray override fun reset() override val blockSizeBytes: Int diff --git a/runtime/runtime-core/jvm/src/aws/smithy/kotlin/runtime/hashing/Md5JVM.kt b/runtime/runtime-core/jvm/src/aws/smithy/kotlin/runtime/hashing/Md5JVM.kt index 4a1bc6c307..4320067bb1 100644 --- a/runtime/runtime-core/jvm/src/aws/smithy/kotlin/runtime/hashing/Md5JVM.kt +++ b/runtime/runtime-core/jvm/src/aws/smithy/kotlin/runtime/hashing/Md5JVM.kt @@ -11,6 +11,7 @@ import java.security.MessageDigest public actual class Md5 : Md5Base() { private val md = MessageDigest.getInstance("MD5") actual override fun update(input: ByteArray, offset: Int, length: Int): Unit = md.update(input, offset, length) + public actual fun update(input: Byte): Unit = md.update(input) actual override fun digest(): ByteArray = md.digest() actual override fun reset(): Unit = md.reset() } diff --git a/runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/hashing/Md5Native.kt b/runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/hashing/Md5Native.kt index 9614543dad..1cd9db9ef1 100644 --- a/runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/hashing/Md5Native.kt +++ b/runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/hashing/Md5Native.kt @@ -15,6 +15,10 @@ public actual class Md5 actual constructor() : Md5Base() { TODO("Not yet implemented") } + public actual fun update(input: Byte) { + TODO("Not yet implemented") + } + actual override fun digest(): ByteArray { TODO("Not yet implemented") } From 951e07e7d688f1694afb235ca15867eb6302d895 Mon Sep 17 00:00:00 2001 From: Xinsong Cui Date: Tue, 4 Mar 2025 10:51:47 -0500 Subject: [PATCH 2/4] lint --- .../src/aws/smithy/kotlin/runtime/config/EnvironmentSetting.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/config/EnvironmentSetting.kt b/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/config/EnvironmentSetting.kt index 16e87092d1..26dc42138f 100644 --- a/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/config/EnvironmentSetting.kt +++ b/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/config/EnvironmentSetting.kt @@ -79,7 +79,7 @@ public inline fun > enumSetEnvSetting(sysProp: String, envVa enumValues() .firstOrNull { it.name.equals(enumValue, ignoreCase = true) } ?: throw ClientException( - "Value $enumValue is not supported, should be one of ${enumValues().joinToString(", ")}" + "Value $enumValue is not supported, should be one of ${enumValues().joinToString(", ")}", ) } .toSet() From 5f9b64e5d358acf1b72381fc385aaac91d5f619c Mon Sep 17 00:00:00 2001 From: Xinsong Cui Date: Tue, 4 Mar 2025 18:05:35 -0500 Subject: [PATCH 3/4] address pr feedbacks --- runtime/runtime-core/api/runtime-core.api | 1 - .../common/src/aws/smithy/kotlin/runtime/hashing/Md5.kt | 1 - .../jvm/src/aws/smithy/kotlin/runtime/hashing/Md5JVM.kt | 1 - .../native/src/aws/smithy/kotlin/runtime/hashing/Md5Native.kt | 4 ---- 4 files changed, 7 deletions(-) diff --git a/runtime/runtime-core/api/runtime-core.api b/runtime/runtime-core/api/runtime-core.api index 1c36811265..0d5399d430 100644 --- a/runtime/runtime-core/api/runtime-core.api +++ b/runtime/runtime-core/api/runtime-core.api @@ -725,7 +725,6 @@ public final class aws/smithy/kotlin/runtime/hashing/Md5 : aws/smithy/kotlin/run public fun ()V public fun digest ()[B public fun reset ()V - public final fun update (B)V public fun update ([BII)V } diff --git a/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/hashing/Md5.kt b/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/hashing/Md5.kt index 8e6b946c3f..176ada4cdb 100644 --- a/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/hashing/Md5.kt +++ b/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/hashing/Md5.kt @@ -18,7 +18,6 @@ public abstract class Md5Base : HashFunction { @InternalApi public expect class Md5() : Md5Base { override fun update(input: ByteArray, offset: Int, length: Int) - public fun update(input: Byte) override fun digest(): ByteArray override fun reset() override val blockSizeBytes: Int diff --git a/runtime/runtime-core/jvm/src/aws/smithy/kotlin/runtime/hashing/Md5JVM.kt b/runtime/runtime-core/jvm/src/aws/smithy/kotlin/runtime/hashing/Md5JVM.kt index 4320067bb1..4a1bc6c307 100644 --- a/runtime/runtime-core/jvm/src/aws/smithy/kotlin/runtime/hashing/Md5JVM.kt +++ b/runtime/runtime-core/jvm/src/aws/smithy/kotlin/runtime/hashing/Md5JVM.kt @@ -11,7 +11,6 @@ import java.security.MessageDigest public actual class Md5 : Md5Base() { private val md = MessageDigest.getInstance("MD5") actual override fun update(input: ByteArray, offset: Int, length: Int): Unit = md.update(input, offset, length) - public actual fun update(input: Byte): Unit = md.update(input) actual override fun digest(): ByteArray = md.digest() actual override fun reset(): Unit = md.reset() } diff --git a/runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/hashing/Md5Native.kt b/runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/hashing/Md5Native.kt index 1cd9db9ef1..9614543dad 100644 --- a/runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/hashing/Md5Native.kt +++ b/runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/hashing/Md5Native.kt @@ -15,10 +15,6 @@ public actual class Md5 actual constructor() : Md5Base() { TODO("Not yet implemented") } - public actual fun update(input: Byte) { - TODO("Not yet implemented") - } - actual override fun digest(): ByteArray { TODO("Not yet implemented") } From c9427d2e66018325179cc374a53b0b18653c4a4f Mon Sep 17 00:00:00 2001 From: Xinsong Cui Date: Tue, 11 Mar 2025 15:39:53 -0400 Subject: [PATCH 4/4] address feedback --- .../src/aws/smithy/kotlin/runtime/config/EnvironmentSetting.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/config/EnvironmentSetting.kt b/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/config/EnvironmentSetting.kt index 26dc42138f..a2ceeba27e 100644 --- a/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/config/EnvironmentSetting.kt +++ b/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/config/EnvironmentSetting.kt @@ -83,7 +83,6 @@ public inline fun > enumSetEnvSetting(sysProp: String, envVa ) } .toSet() - .takeIf { it.isNotEmpty() } } return EnvironmentSetting(parse, sysProp, envVar) }