Skip to content

Commit

Permalink
feat(RAMF): Implement Parcel class
Browse files Browse the repository at this point in the history
  • Loading branch information
gnarea committed Jul 15, 2020
1 parent f354100 commit c07f6c9
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/main/kotlin/tech/relaycorp/relaynet/messages/Parcel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package tech.relaycorp.relaynet.messages

import tech.relaycorp.relaynet.ramf.RAMFException
import tech.relaycorp.relaynet.ramf.RAMFMessage
import tech.relaycorp.relaynet.ramf.RAMFMessageCompanion
import tech.relaycorp.relaynet.ramf.RAMFSerializer
import tech.relaycorp.relaynet.wrappers.x509.Certificate
import java.io.InputStream
import java.time.ZonedDateTime

private val SERIALIZER = RAMFSerializer(0x50, 0x00)

/**
* Parcel
*/
class Parcel(
recipientAddress: String,
payload: ByteArray,
senderCertificate: Certificate,
messageId: String? = null,
creationDate: ZonedDateTime? = null,
ttl: Int? = null,
senderCertificateChain: Set<Certificate>? = null
) : RAMFMessage(
SERIALIZER,
recipientAddress,
payload,
senderCertificate,
messageId,
creationDate,
ttl,
senderCertificateChain
) {
companion object : RAMFMessageCompanion<Parcel> {
/**
* Deserialize parcel
*/
@JvmStatic
@Throws(RAMFException::class)
override fun deserialize(serialization: ByteArray) =
SERIALIZER.deserialize(serialization, ::Parcel)

/**
* Deserialize parcel
*/
@JvmStatic
@Throws(RAMFException::class)
override fun deserialize(serialization: InputStream) =
SERIALIZER.deserialize(serialization, ::Parcel)
}
}
23 changes: 23 additions & 0 deletions src/test/kotlin/tech/relaycorp/relaynet/messages/ParcelTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package tech.relaycorp.relaynet.messages

import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.TestFactory
import tech.relaycorp.relaynet.ramf.makeRAMFMessageCompanionTests
import tech.relaycorp.relaynet.ramf.makeRAMFMessageConstructorTests
import tech.relaycorp.relaynet.wrappers.x509.Certificate

class ParcelTest {
@TestFactory
fun makeConstructorTests() = makeRAMFMessageConstructorTests(
::Parcel,
{ r: String, p: ByteArray, s: Certificate -> Parcel(r, p, s) },
0x50,
0x00
)

@Nested
inner class Companion {
@TestFactory
fun makeDeserializationTests() = makeRAMFMessageCompanionTests(Parcel.Companion, ::Parcel)
}
}

0 comments on commit c07f6c9

Please sign in to comment.