Class PrefixBlock

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

public class PrefixBlock extends AbstractBlock implements Serializable

ASN1 parser class for header reply.

See Also:
  • Field Details

  • Constructor Details

    • PrefixBlock

      public PrefixBlock() throws IOException

      Creates a prefix with a random symmetric key.

      Throws:
      IOException - if key generation fails
    • PrefixBlock

      public PrefixBlock(SymmetricKey sk) throws IOException

      Creates a prefix with the given key.

      Parameters:
      sk - symmetric key to embed in the prefix block
      Throws:
      IOException - if key generation fails
    • PrefixBlock

      public PrefixBlock(org.bouncycastle.asn1.ASN1Primitive to, AsymmetricKey ak) throws IOException

      Creates a prefix by parsing to in plan (unencrypted).

      Parameters:
      to - The primitive to be parsed
      ak - the asymmetric key required to decrypt the block
      Throws:
      IOException - if parsing fails
    • PrefixBlock

      public PrefixBlock(byte[] to, AsymmetricKey ak) throws IOException

      Creates a prefix from the provided byte array by decyphering it with the provided key.

      Parameters:
      to - the ASN1 OCTET STRING containing the encrypted prefix
      ak - the host key
      Throws:
      IOException - if parsing of the prefix block fails
  • Method Details

    • parse

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

      public final AsymmetricKey setDecryptionKey(AsymmetricKey dk) throws IOException

      Sets the decryption key for the prefix block.

      If the prefixblock is already encrypted a decryption is attempted.

      Parameters:
      dk - the decryption key to be used when decrypting the block
      Returns:
      the previous decryption key
      Throws:
      IOException - if decryption tails
    • getDecryptionKey

      public final AsymmetricKey getDecryptionKey()
    • setKey

      public SymmetricKey setKey(SymmetricKey dk)

      Sets the symmetric key contained in the block.

      Parameters:
      dk - the decryption key for all subsequent blocks
      Returns:
      the key set before the change
    • getKey

      public SymmetricKey getKey()
    • toAsn1Object

      public org.bouncycastle.asn1.ASN1Object toAsn1Object(DumpType dumpType) throws IOException
      Description copied from interface: Dumpable

      Dumps an ASN.1 representation of the object.

      Specified by:
      toAsn1Object in interface Dumpable
      Parameters:
      dumpType - the dump type to be used
      Returns:
      the ASN.1 string representation of the object
      Throws:
      IOException - if dumping of the object fails due to an illegal internal state of the object
    • dumpValueNotation

      public String dumpValueNotation(String prefix, DumpType dumpType) throws IOException
      Specified by:
      dumpValueNotation in interface Block
      Throws:
      IOException
    • equals

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

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

      public boolean isEncrypted()

      get the encryption status of the prefix block.

      Returns:
      true if the block is encrypted
    • toEncBytes

      public byte[] toEncBytes() throws IOException

      Get the ASN.1 encoded prefix block in encrypted form.

      Returns:
      the encrypted ASN.1 rncoded block
      Throws:
      IOException - if encoding fails