Class PayloadChunk

java.lang.Object
net.messagevortex.asn1.AbstractBlock
net.messagevortex.asn1.PayloadChunk
All Implemented Interfaces:
Serializable, Block, Dumpable

public class PayloadChunk extends AbstractBlock implements Serializable
See Also:
  • Field Details

  • Constructor Details

    • PayloadChunk

      public PayloadChunk()

      Creates an empty payload block.

    • PayloadChunk

      public PayloadChunk(org.bouncycastle.asn1.ASN1Encodable to, UsagePeriod period) throws IOException

      Creates a payload block from a ASN1 stream.

      Parameters:
      to - the ASN.1 object of the PayloadCunk to be parsed
      period - the validity period to be associated with
      Throws:
      IOException - if parsing fails
    • PayloadChunk

      public PayloadChunk(int id, byte[] payload, UsagePeriod period)

      Creates a payload block from raw data.

      Parameters:
      id - the payload location
      payload - the payload content
      period - the validity period to be associated with
  • Method Details

    • toAsn1Object

      public org.bouncycastle.asn1.ASN1Object toAsn1Object(DumpType dumpType) throws IOException

      Creates a der encoded ASN1 representation of the payload chunk.

      Specified by:
      toAsn1Object in interface Dumpable
      Parameters:
      dumpType - the dump type to be used
      Returns:
      the ASN.1 object
      Throws:
      IOException - if id is too low or the payload has not been set
    • setPayload

      public final byte[] setPayload(byte[] b)

      Set a byte array as payload.

      Parameters:
      b - the payload to be set
      Returns:
      the previously set payload (may have been a reply block)
    • getPayload

      public final byte[] getPayload()

      Gets the the currently set payload.

      Returns:
      the payload as byte array or null if a replyblock has been set
    • setReplyBlock

      public final byte[] setReplyBlock(byte[] reply)

      Set a byte array as reply block.

      Parameters:
      reply - the reply block to be set
      Returns:
      the previously set reply block (may have been a payload block)
    • getReplyBlock

      public final byte[] getReplyBlock()

      Gets the the currently set reply block.

      Returns:
      the reply block as byte array or null if a payload block has been set
    • getUsagePeriod

      public final UsagePeriod getUsagePeriod()
    • setUsagePeriod

      public final UsagePeriod setUsagePeriod(UsagePeriod period)

      Sets the usage period of the payload cunk.

      Parameters:
      period - the new usage period
      Returns:
      the previously set usage period
    • parse

      protected final void parse(org.bouncycastle.asn1.ASN1Encodable to) throws IOException
      Specified by:
      parse in class AbstractBlock
      Throws:
      IOException
    • setId

      public final int setId(int id)

      Sets the id of the payload chunk.

      Parameters:
      id - the id to be set
      Returns:
      the previously set id
    • getId

      public final int getId()

      Gets the id of the payload chunk.

      Returns:
      the id currently set
    • dumpValueNotation

      public String dumpValueNotation(String prefix, DumpType dumpType) throws IOException

      Dumps the current object as a value representation.

      Specified by:
      dumpValueNotation in interface Block
      Parameters:
      prefix - the prefix to be used (normally used for indentation)
      dumpType - the dump type to be used (@see DumpType)
      Returns:
      the string representation of the ASN1 object
      Throws:
      IOException - if the payload id is below MIN_VALID_ID or no payload/reply block has been set
    • isInUsagePeriod

      public boolean isInUsagePeriod()
    • isInUsagePeriod

      public boolean isInUsagePeriod(Date reference)

      Checks if the usage period passed is fully embraced in the usage period.

      Parameters:
      reference - the usage period to be embraced
      Returns:
      tre if embraced or no usage restriction
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object