All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tech.relaycorp.relaynet.messages.Cargo.kt Maven / Gradle / Ivy

There is a newer version: 1.69.11
Show newest version
package tech.relaycorp.relaynet.messages

import java.io.InputStream
import java.time.ZonedDateTime
import tech.relaycorp.relaynet.messages.payloads.CargoMessageSet
import tech.relaycorp.relaynet.ramf.EncryptedRAMFMessage
import tech.relaycorp.relaynet.ramf.RAMFException
import tech.relaycorp.relaynet.ramf.RAMFMessageCompanion
import tech.relaycorp.relaynet.ramf.RAMFSerializer
import tech.relaycorp.relaynet.wrappers.x509.Certificate

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

/**
 * Cargo
 */
class Cargo(
    recipient: Recipient,
    payload: ByteArray,
    senderCertificate: Certificate,
    messageId: String? = null,
    creationDate: ZonedDateTime? = null,
    ttl: Int? = null,
    senderCertificateChain: Set? = null,
) : EncryptedRAMFMessage(
        SERIALIZER,
        recipient,
        payload,
        senderCertificate,
        messageId,
        creationDate,
        ttl,
        senderCertificateChain,
    ) {
    override fun deserializePayload(payloadPlaintext: ByteArray) =
        CargoMessageSet.deserialize(payloadPlaintext)

    companion object : RAMFMessageCompanion {
        /**
         * Deserialize cargo
         */
        @JvmStatic
        @Throws(RAMFException::class)
        override fun deserialize(serialization: ByteArray) =
            SERIALIZER.deserialize(serialization, ::Cargo)

        /**
         * Deserialize cargo
         */
        @JvmStatic
        @Throws(RAMFException::class)
        override fun deserialize(serialization: InputStream) =
            SERIALIZER.deserialize(serialization, ::Cargo)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy