calidion
01/28/2025, 11:52 AMval <T> T.key: String
get() = ""
inside function it is used:
@OptIn(ExperimentalStdlibApi::class)
inline fun <reified T> verify(json: String, publicKey: PublicKey? = null): T {
val signJSON = Json.decodeFromString<SignJSON>(json)
val resJson = Json.decodeFromString<T>(signJSON.json)
var key = publicKey
if (key == null) {
key = fromHexString(resJson.key)
}
assert(
verify(
signJSON.json.toByteArray(),
signJSON.signature.hexToByteArray(),
key
)
)
return resJson
}
as I debug into this line to find resJson.key have value , but the access to resJson.key result in empty string `""`
Klitos Kyriacou
01/28/2025, 2:28 PMT.key get()
for any type T
to return an empty string, so resJson.key
is therefore empty. Perhaps I've misunderstood your post?calidion
01/28/2025, 2:52 PMcalidion
01/28/2025, 2:52 PMKlitos Kyriacou
01/29/2025, 11:35 AMresJson
? If this type has a property called key
, your verify
method doesn't know about it, because you haven't told it what type resJson
is. If you want it to be generic, it still has to know that it only works on types that have a key
property. One way to do that is to make whatever the type of resJson
is, to implement an interface (let's call it interface HasKey
) and declare your method as inline fun <reified T: HasKey>
. You should then get rid of your val <T> T.key
external property as that is unrelated to `resJson`'s type.calidion
01/29/2025, 12:29 PM