mirror of
https://github.com/corda/corda.git
synced 2024-12-19 04:57:58 +00:00
core: add serialization test for keypairs
This commit is contained in:
parent
af3d87803d
commit
cd91c6a0e7
@ -1,7 +1,11 @@
|
||||
package com.r3corda.core.serialization
|
||||
|
||||
import com.google.common.primitives.Ints
|
||||
import com.r3corda.core.crypto.generateKeyPair
|
||||
import com.r3corda.core.crypto.signWithECDSA
|
||||
import com.r3corda.core.crypto.verifyWithECDSA
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.assertj.core.api.Assertions.assertThatThrownBy
|
||||
import org.junit.Test
|
||||
import java.time.Instant
|
||||
import java.util.*
|
||||
@ -54,6 +58,21 @@ class KryoTests {
|
||||
assertThat(bits.deserialize(kryo)).isEqualTo(cyclic)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `deserialised keypair functions the same as serialised one`() {
|
||||
val keyPair = generateKeyPair()
|
||||
val bitsToSign: ByteArray = Ints.toByteArray(0x01234567)
|
||||
val wrongBits: ByteArray = Ints.toByteArray(0x76543210)
|
||||
val signature = keyPair.signWithECDSA(bitsToSign)
|
||||
signature.verifyWithECDSA(bitsToSign)
|
||||
assertThatThrownBy { signature.verifyWithECDSA(wrongBits) }
|
||||
|
||||
val deserialisedKeyPair = keyPair.serialize(kryo).deserialize(kryo)
|
||||
val deserialisedSignature = deserialisedKeyPair.signWithECDSA(bitsToSign)
|
||||
assertThat(deserialisedSignature).isEqualTo(signature)
|
||||
deserialisedSignature.verifyWithECDSA(bitsToSign)
|
||||
assertThatThrownBy { deserialisedSignature.verifyWithECDSA(wrongBits) }
|
||||
}
|
||||
|
||||
private data class Person(val name: String, val birthday: Instant?)
|
||||
|
||||
@ -65,4 +84,4 @@ class KryoTests {
|
||||
override fun toString(): String = "Cyclic($value)"
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user