-
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.
- Loading branch information
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
src/main/kotlin/tech/relaycorp/relaynet/messages/Parcel.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,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
23
src/test/kotlin/tech/relaycorp/relaynet/messages/ParcelTest.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,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) | ||
} | ||
} |