forked from corda/corda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CORDA-540: AMQP Private key serializer (corda#1838)
- Loading branch information
1 parent
a425f82
commit a9508b3
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
.../main/kotlin/net/corda/nodeapi/internal/serialization/amqp/custom/PrivateKeySerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |