Add XteaKey Jackson serializer

Signed-off-by: Graham <gpe@openrs2.org>
Graham 4 years ago
parent 98dcbedeaf
commit 46b311c5ad
  1. 1
      crypto/build.gradle.kts
  2. 11
      crypto/src/main/kotlin/org/openrs2/crypto/CryptoJacksonModule.kt
  3. 5
      crypto/src/main/kotlin/org/openrs2/crypto/CryptoModule.kt
  4. 16
      crypto/src/main/kotlin/org/openrs2/crypto/XteaKeySerializer.kt

@ -4,6 +4,7 @@ plugins {
} }
dependencies { dependencies {
api("com.fasterxml.jackson.core:jackson-databind:${Versions.jackson}")
api("com.google.inject:guice:${Versions.guice}") api("com.google.inject:guice:${Versions.guice}")
api("io.netty:netty-buffer:${Versions.netty}") api("io.netty:netty-buffer:${Versions.netty}")
api("org.bouncycastle:bcpkix-jdk15on:${Versions.bouncyCastlePkix}") api("org.bouncycastle:bcpkix-jdk15on:${Versions.bouncyCastlePkix}")

@ -0,0 +1,11 @@
package org.openrs2.crypto
import com.fasterxml.jackson.databind.module.SimpleModule
import javax.inject.Singleton
@Singleton
public class CryptoJacksonModule : SimpleModule() {
init {
addSerializer(XteaKey::class.java, XteaKeySerializer)
}
}

@ -1,7 +1,9 @@
package org.openrs2.crypto package org.openrs2.crypto
import com.fasterxml.jackson.databind.Module
import com.google.inject.AbstractModule import com.google.inject.AbstractModule
import com.google.inject.Scopes import com.google.inject.Scopes
import com.google.inject.multibindings.Multibinder
import org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters import org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters
public object CryptoModule : AbstractModule() { public object CryptoModule : AbstractModule() {
@ -9,5 +11,8 @@ public object CryptoModule : AbstractModule() {
bind(RSAPrivateCrtKeyParameters::class.java) bind(RSAPrivateCrtKeyParameters::class.java)
.toProvider(RsaKeyProvider::class.java) .toProvider(RsaKeyProvider::class.java)
.`in`(Scopes.SINGLETON) .`in`(Scopes.SINGLETON)
Multibinder.newSetBinder(binder(), Module::class.java)
.addBinding().to(CryptoJacksonModule::class.java)
} }
} }

@ -0,0 +1,16 @@
package org.openrs2.crypto
import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.databind.SerializerProvider
import com.fasterxml.jackson.databind.ser.std.StdSerializer
public object XteaKeySerializer : StdSerializer<XteaKey>(XteaKey::class.java) {
override fun serialize(value: XteaKey, gen: JsonGenerator, provider: SerializerProvider) {
gen.writeStartArray()
gen.writeNumber(value.k0)
gen.writeNumber(value.k1)
gen.writeNumber(value.k2)
gen.writeNumber(value.k3)
gen.writeEndArray()
}
}
Loading…
Cancel
Save