Skip to content

Commit

Permalink
CORDA-540: AMQP Private key serializer (corda#1838)
Browse files Browse the repository at this point in the history
  • Loading branch information
vkolomeyko authored Oct 9, 2017
1 parent a425f82 commit a9508b3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ abstract class AbstractAMQPSerializationScheme : SerializationScheme {
fun registerCustomSerializers(factory: SerializerFactory) {
with(factory) {
register(net.corda.nodeapi.internal.serialization.amqp.custom.PublicKeySerializer)
register(net.corda.nodeapi.internal.serialization.amqp.custom.PrivateKeySerializer)
register(net.corda.nodeapi.internal.serialization.amqp.custom.ThrowableSerializer(this))
register(net.corda.nodeapi.internal.serialization.amqp.custom.X500NameSerializer)
register(net.corda.nodeapi.internal.serialization.amqp.custom.BigDecimalSerializer)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package net.corda.nodeapi.internal.serialization.amqp.custom

import net.corda.core.crypto.Crypto
import net.corda.core.serialization.SerializationContext.UseCase.*
import net.corda.nodeapi.internal.serialization.amqp.*
import net.corda.nodeapi.internal.serialization.checkUseCase
import org.apache.qpid.proton.codec.Data
import java.lang.reflect.Type
import java.security.PrivateKey
import java.util.*

object PrivateKeySerializer : CustomSerializer.Implements<PrivateKey>(PrivateKey::class.java) {

private val allowedUseCases = EnumSet.of(Storage, Checkpoint)

override val schemaForDocumentation = Schema(listOf(RestrictedType(type.toString(), "", listOf(type.toString()), SerializerFactory.primitiveTypeName(ByteArray::class.java)!!, descriptor, emptyList())))

override fun writeDescribedObject(obj: PrivateKey, data: Data, type: Type, output: SerializationOutput) {
checkUseCase(allowedUseCases)
output.writeObject(obj.encoded, data, clazz)
}

override fun readObject(obj: Any, schema: Schema, input: DeserializationInput): PrivateKey {
val bits = input.readObject(obj, schema, ByteArray::class.java) as ByteArray
return Crypto.decodePrivateKey(bits)
}
}

0 comments on commit a9508b3

Please sign in to comment.