core: switch to static size bytearray serialization of keypairs

This commit is contained in:
Andras Slemmer 2016-06-09 15:30:02 +01:00
parent 22567d11b5
commit 376b73b823

View File

@ -260,14 +260,16 @@ object WireTransactionSerializer : Serializer<WireTransaction>() {
@ThreadSafe
object Ed25519PrivateKeySerializer : Serializer<EdDSAPrivateKey>() {
val ed25519Curve = EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.CURVE_ED25519_SHA512)
val seedSize = 64
override fun write(kryo: Kryo, output: Output, obj: EdDSAPrivateKey) {
check(obj.params.equals(ed25519Curve))
kryo.writeClassAndObject(output, obj.seed)
check(obj.seed.size == seedSize)
output.writeBytes(obj.seed)
}
override fun read(kryo: Kryo, input: Input, type: Class<EdDSAPrivateKey>): EdDSAPrivateKey {
val seed = kryo.readClassAndObject(input) as ByteArray
val seed = input.readBytes(seedSize)
return EdDSAPrivateKey(EdDSAPrivateKeySpec(seed, ed25519Curve))
}
}
@ -276,14 +278,16 @@ object Ed25519PrivateKeySerializer : Serializer<EdDSAPrivateKey>() {
@ThreadSafe
object Ed25519PublicKeySerializer : Serializer<EdDSAPublicKey>() {
val ed25519Curve = EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.CURVE_ED25519_SHA512)
val ASize = 32
override fun write(kryo: Kryo, output: Output, obj: EdDSAPublicKey) {
check(obj.params.equals(ed25519Curve))
kryo.writeClassAndObject(output, obj.abyte)
check(obj.abyte.size == ASize)
output.writeBytes(obj.abyte)
}
override fun read(kryo: Kryo, input: Input, type: Class<EdDSAPublicKey>): EdDSAPublicKey {
val A = kryo.readClassAndObject(input) as ByteArray
val A = input.readBytes(ASize)
return EdDSAPublicKey(EdDSAPublicKeySpec(A, ed25519Curve))
}
}