Open-source multiplayer game server compatible with the RuneScape client
https://www.openrs2.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.3 KiB
39 lines
1.3 KiB
package org.openrs2.archive.key
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper
|
|
import com.fasterxml.jackson.module.kotlin.treeToValue
|
|
import jakarta.inject.Inject
|
|
import jakarta.inject.Singleton
|
|
import org.openrs2.crypto.SymmetricKey
|
|
import org.openrs2.json.Json
|
|
import java.io.IOException
|
|
import java.io.InputStream
|
|
|
|
@Singleton
|
|
public class JsonKeyReader @Inject constructor(
|
|
@Json private val mapper: ObjectMapper
|
|
) : KeyReader {
|
|
override fun read(input: InputStream): Sequence<SymmetricKey> {
|
|
val keys = mutableSetOf<SymmetricKey>()
|
|
val root = mapper.readTree(input)
|
|
|
|
when {
|
|
root.isArray -> {
|
|
for (entry in root) {
|
|
val key = entry["key"] ?: entry["keys"] ?: throw IOException("Missing 'key' or 'keys' field")
|
|
keys += mapper.treeToValue<SymmetricKey?>(key) ?: throw IOException("Key must be non-null")
|
|
}
|
|
}
|
|
|
|
root.isObject -> {
|
|
for (entry in root.fields()) {
|
|
keys += mapper.treeToValue<SymmetricKey?>(entry.value) ?: throw IOException("Key must be non-null")
|
|
}
|
|
}
|
|
|
|
else -> throw IOException("Root element must be an array or object")
|
|
}
|
|
|
|
return keys.asSequence()
|
|
}
|
|
}
|
|
|