Class IdentityBlock

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

public class IdentityBlock extends AbstractBlock implements Serializable, Dumpable

Represents an identity block of a vortexMessage.

See Also:
  • Field Details

  • Constructor Details

    • IdentityBlock

      public IdentityBlock() throws IOException

      Creates a new IdentityBlock with a medium security default key.

      This is a convenience wrapper for @see IdentityBlock(AsymmetricKey)

      Throws:
      IOException - if generation of the key fails
    • IdentityBlock

      public IdentityBlock(AsymmetricKey key) throws IOException

      Generates a new IdentityBlock for the given key.

      The new identity block is characterized by 1 replay (not replayable), a random serial, a usage perod of 1 hour, and no requests.

      Parameters:
      key - the key to be used
      Throws:
      IOException - if generation of the block fails
    • IdentityBlock

      public IdentityBlock(byte[] b, AsymmetricKey ownIdentity) throws IOException

      Parses the given identity block using the specified key.

      Parameters:
      b - a byte array reflecting the encrypted IdentityBlock
      ownIdentity - the identity to be used to decrypt the block
      Throws:
      IOException - if parsing fails for any reason
    • IdentityBlock

      public IdentityBlock(byte[] b) throws IOException

      Parses the given unecrypted identity block.

      Parameters:
      b - a byte array reflecting the IdentityBlock
      Throws:
      IOException - if parsing fails for any reason
    • IdentityBlock

      public IdentityBlock(org.bouncycastle.asn1.ASN1Encodable to) throws IOException

      Create object from ASN.1 code.

      Parameters:
      to - the ASN.1 code
      Throws:
      IOException - if parsing of ASN.1 code fails
    • IdentityBlock

      public IdentityBlock(org.bouncycastle.asn1.ASN1Encodable to, AsymmetricKey ownIdentity) throws IOException

      Create object from encrypted ASN.1 code.

      Parameters:
      to - the ASN.1 code
      ownIdentity - the identity to be used to decrypt the block
      Throws:
      IOException - if parsing of ASN.1 code fails
  • Method Details

    • setRequests

      public void setRequests(HeaderRequest[] hr)
    • parse

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

      public int getReplay()

      Gets the maximum number of replays for this block.

      Returns:
      the currently set maximum number of replays
    • setReplay

      public int setReplay(int maxReplay)

      Sets the maximum number of replays for this block.

      Parameters:
      maxReplay - the maximum nuber of replays to be set
      Returns:
      the previously set maximum
    • getUsagePeriod

      public UsagePeriod getUsagePeriod()

      Gets the currently set validity period of the block.

      Returns:
      the previously set validity period
    • setUsagePeriod

      public UsagePeriod setUsagePeriod(UsagePeriod valid)

      Sets the maximum usage period of the block.

      Parameters:
      valid - the new usage period to be set
      Returns:
      the previously set usage period
    • getOwnIdentity

      public AsymmetricKey getOwnIdentity()

      Gets the identity representation (asymmetric key) of the block.

      Returns:
      the previously set identity
    • setOwnIdentity

      public AsymmetricKey setOwnIdentity(AsymmetricKey oid)

      Sets the identity representation (asymmetric key) of the block.

      Parameters:
      oid - the identity key
      Returns:
      the previously set identity
    • getIdentityKey

      public AsymmetricKey getIdentityKey()

      Gets the identity representation (asymmetric key) of the block.

      Returns:
      the previously set identity
    • setIdentityKey

      public AsymmetricKey setIdentityKey(AsymmetricKey oid)

      Sets the identity representation (asymmetric key) of the block.

      Parameters:
      oid - the identity key
      Returns:
      the previously set identity
    • toAsn1Object

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

      Dumps the identity block as ASN.1 der encoded object.

      Specified by:
      toAsn1Object in interface Dumpable
      Parameters:
      dumpType - the dump type to be used
      Returns:
      the block as der encodable object
      Throws:
      IOException - if the block is not encodable
    • toAsn1Object

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

      Dumps the identity block as ASN.1 der encoded object.

      Parameters:
      dumpType - the type of dump to be used
      targetIdentity - the identity to be used to secure the Identity block (target identity)
      Returns:
      the block as der encodable object
      Throws:
      IOException - if the block is not encodable
    • dumpValueNotation

      public String dumpValueNotation(String prefix) throws IOException
      Throws:
      IOException
    • dumpValueNotation

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

      Dumps the current block state in ASN.1 value notation.

      Specified by:
      dumpValueNotation in interface Block
      Parameters:
      prefix - the prefix to be prepended to each line (whitespaces for indentation)
      dumpType - the type of dump to be used
      Returns:
      a String representing the ASN.1 value notation of the Block
      Throws:
      IOException - if the block is not encodable
    • getSerial

      public long getSerial()

      Get the serial of the identity block.

      Returns:
      the currently set serial number
    • setSerial

      public long setSerial(long serial)

      Set the serial of the identity block.

      Parameters:
      serial - the serial to be set
      Returns:
      the previously set serial number
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object