Skip to content

Commit 086ae8d

Browse files
committed
fix(Hash.update): add check for string type when Value type argument is passed.
- Expand test coverage on digest method - Validate string check with Value type argument is working as expected in both host and guest
1 parent bb26e5e commit 086ae8d

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

packages/graalvm/src/main/kotlin/elide/runtime/node/crypto/NodeCryptoHash.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public class NodeHash(
7676
}
7777
arr
7878
}
79-
else -> data.asString().toByteArray(Charsets.UTF_8)
79+
data.isString -> data.asString().toByteArray(Charsets.UTF_8)
80+
else -> throw IllegalArgumentException("Unsupported item type, must be of type string or an instance of Buffer, TypedArray, or Dataview. Received: ${data.javaClass.name}")
8081
}
8182
}
8283
is Iterable<*> -> { // @TODO(elijahkotyluk) Handle Polyglot lists as an iterable, may need to revisit

packages/graalvm/src/test/kotlin/elide/runtime/node/NodeCryptoTest.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
package elide.runtime.node
1414

15+
import org.graalvm.polyglot.Value
1516
import org.junit.jupiter.api.assertThrows
1617
import kotlin.test.Test
1718
import kotlin.test.assertEquals
@@ -388,7 +389,7 @@ import elide.testing.annotations.TestCase
388389

389390
@Test fun `createHash should allow chainable updates`() = conforms {
390391
val hash = crypto.provide().createHash("sha256")
391-
hash.update("hello").update(" ").update("world")
392+
hash.update("hello").update(" ").update(Value.asValue("world"))
392393
val digest = hash.digest("hex")
393394

394395
assertEquals(
@@ -576,6 +577,9 @@ import elide.testing.annotations.TestCase
576577
assertThrows<IllegalArgumentException> {
577578
hash.update({ str: String -> str })
578579
}
580+
assertThrows<IllegalArgumentException> {
581+
hash.update(Value.asValue(12345))
582+
}
579583
}.guest {
580584
//language=javascript
581585
"""

0 commit comments

Comments
 (0)