mirror of
https://github.com/corda/corda.git
synced 2024-12-19 04:57:58 +00:00
core: switch to static size bytearray serialization of keypairs
This commit is contained in:
parent
22567d11b5
commit
376b73b823
@ -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))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user