Class ParseBuffer


  • public class ParseBuffer
    extends java.lang.Object
    Object used to parse binary buffers
    Author:
    Andreas Schwier (info@cardcontact.de)
    • Constructor Summary

      Constructors 
      Constructor Description
      ParseBuffer​(byte[] newBuffer)
      Create ParseBuffer to parse entire byte array
      ParseBuffer​(byte[] newBuffer, int newCursor, int newLength)
      Create ParseBuffer using bytes at given range in byte array
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      byte get()
      Get next byte from parse buffer.
      ParseBuffer get​(byte[] dst, int offset, int length)
      Bulk get from parse buffer Get specified number of bytes from buffer
      int getDERLength()
      Get DER coded length Values between 0 and 127 are encoded in one byte Values between 128 and 255 are encoded in two bytes Values between 256 and 65535 are encoded in three bytes Values between 65536 and 2^24 - 1 are encoded in four bytes Values between 2^24 and 2^32 - 1 are encoded in five byte For value >= 128 the first byte encoded the number of trailing bytes plus '80'
      int getDGILength()
      Get DGI coded length Values between 0 and 254 are encoded in one byte Values between 255 and 65535 are encoded in three bytes with the first byte set to 'FF'
      int getLimit()
      Returns the current upper limit for the parse buffer
      int getTag()
      Get variable length encoded tag as used in DER/BER encoding
      int getUnsignedWord()
      Return next two bytes as unsigned integer
      boolean hasRemaining()
      Return true if bytes are available to parse
      void mark()
      Mark current parser position
      int remaining()
      Return number of remaining bytes in parse buffer
      void reset()
      Reset current parser position to previously set mark
      void setLength​(int newLength)
      Set new length of parse region starting at current offset Throws IllegalArgumentException if the length exceed the underlying byte array
      void setLimit​(int limit)
      Sets the upper limit for the parse buffer
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ParseBuffer

        public ParseBuffer​(byte[] newBuffer,
                           int newCursor,
                           int newLength)
        Create ParseBuffer using bytes at given range in byte array
        Parameters:
        newBuffer - Binary array
        newCursor - Offset in buffer to start at
        newLength - Length of region in buffer to parse
      • ParseBuffer

        public ParseBuffer​(byte[] newBuffer)
        Create ParseBuffer to parse entire byte array
        Parameters:
        newBuffer - Binary array
    • Method Detail

      • mark

        public void mark()
        Mark current parser position
      • reset

        public void reset()
        Reset current parser position to previously set mark
      • remaining

        public int remaining()
        Return number of remaining bytes in parse buffer
        Returns:
        Number of bytes
      • getLimit

        public int getLimit()
        Returns the current upper limit for the parse buffer
        Returns:
        the upper limit
      • setLength

        public void setLength​(int newLength)
                       throws TLVEncodingException
        Set new length of parse region starting at current offset Throws IllegalArgumentException if the length exceed the underlying byte array
        Parameters:
        newLength - New length starting at current offset
        Throws:
        TLVEncodingException
      • hasRemaining

        public boolean hasRemaining()
        Return true if bytes are available to parse
        Returns:
        true if more bytes are available
      • get

        public byte get()
                 throws TLVEncodingException
        Get next byte from parse buffer. Advance current position by one.
        Returns:
        Byte at current parse position
        Throws:
        TLVEncodingException - End of region reached
      • get

        public ParseBuffer get​(byte[] dst,
                               int offset,
                               int length)
                        throws TLVEncodingException
        Bulk get from parse buffer Get specified number of bytes from buffer
        Parameters:
        dst - Receiving buffer
        offset - Offset in receiving buffer
        length - Number of bytes to get
        Returns:
        This ParseBuffer object
        Throws:
        TLVEncodingException - Given length exceeds parse region
      • getDGILength

        public int getDGILength()
                         throws TLVEncodingException
        Get DGI coded length Values between 0 and 254 are encoded in one byte Values between 255 and 65535 are encoded in three bytes with the first byte set to 'FF'
        Returns:
        Length
        Throws:
        TLVEncodingException - End of region reached during decoding
      • getDERLength

        public int getDERLength()
                         throws TLVEncodingException
        Get DER coded length Values between 0 and 127 are encoded in one byte Values between 128 and 255 are encoded in two bytes Values between 256 and 65535 are encoded in three bytes Values between 65536 and 2^24 - 1 are encoded in four bytes Values between 2^24 and 2^32 - 1 are encoded in five byte For value >= 128 the first byte encoded the number of trailing bytes plus '80'
        Returns:
        Length or -1 if variable length BER encoding
        Throws:
        TLVEncodingException - End of region reached during decoding