Class BerInputStream

java.lang.Object
org.apache.harmony.security.asn1.BerInputStream
Direct Known Subclasses:
DerInputStream

public class BerInputStream
extends Object
Decodes ASN.1 types encoded with BER (X.690)
See Also:
ASN.1
  • Field Details

    • buffer

      protected byte[] buffer
    • offset

      protected int offset
      The position in the buffer. Next read must place data into the buffer from this offset
    • INDEFINIT_LENGTH

      protected static final int INDEFINIT_LENGTH
      Indicates indefinite length of the current type
      See Also:
      Constant Field Values
    • tag

      public int tag
      Current decoded tag
    • length

      protected int length
      Current decoded length
    • content

      public Object content
      Current decoded content
    • tagOffset

      protected int tagOffset
      Current decoded tag offset
    • contentOffset

      protected int contentOffset
      Current decoded content offset
    • choiceIndex

      public int choiceIndex
      The last choice index
    • times

      public int[] times
      Keeps last decoded: year, month, day, hour, minute, second, millisecond
    • oidElement

      public int oidElement
    • isVerify

      protected boolean isVerify
      Indicates verify or store mode. In store mode a decoded content is stored in a newly allocated appropriate object. The content variable holds a reference to the last created object. In verify mode a decoded content is not stored.
    • isIndefinedLength

      protected boolean isIndefinedLength
      Indicates defined or indefined reading mode for associated InputStream. This mode is defined by reading a length for a first ASN.1 type from InputStream.
  • Constructor Details

    • BerInputStream

      public BerInputStream​(byte[] encoded) throws IOException
      Creates stream for decoding.
      Throws:
      IOException
    • BerInputStream

      public BerInputStream​(byte[] encoded, int offset, int expectedLength) throws IOException
      Creates stream for decoding.
      Parameters:
      encoded - bytes array to be decoded
      offset - the encoding offset
      expectedLength - expected length of full encoding, this includes identifier, length an content octets
      Throws:
      IOException
    • BerInputStream

      public BerInputStream​(InputStream in) throws IOException
      Creates stream for decoding. Allocates initial buffer of default size
      Throws:
      IOException
    • BerInputStream

      public BerInputStream​(InputStream in, int initialSize) throws IOException
      Creates stream for decoding.
      Parameters:
      initialSize - the internal buffer initial size
      Throws:
      IOException
  • Method Details

    • reset

      public final void reset​(byte[] encoded) throws IOException
      Resets this stream to initial state.
      Parameters:
      encoded - a new bytes array to be decoded
      Throws:
      IOException - if an error occurs
    • next

      public int next() throws IOException
      Decodes next encoded type. Initializes tag, length, tagOffset and contentOffset variables
      Returns:
      next decoded tag
      Throws:
      IOException - if error occured
    • getLength

      public static int getLength​(byte[] encoding)
      Returns the length of the encoding
    • readBitString

      public void readBitString() throws IOException
      Decodes ASN.1 bitstring type
      Throws:
      IOException
    • readEnumerated

      public void readEnumerated() throws IOException
      Decodes ASN.1 Enumerated type
      Throws:
      IOException
    • readBoolean

      public void readBoolean() throws IOException
      Decodes ASN.1 boolean type
      Throws:
      IOException
    • readGeneralizedTime

      public void readGeneralizedTime() throws IOException
      Decodes ASN.1 GeneralizedTime type
      Throws:
      IOException - if error occured
    • readUTCTime

      public void readUTCTime() throws IOException
      Decodes ASN.1 UTCTime type
      Throws:
      IOException - if an I/O error occurs or the end of the stream is reached
    • readInteger

      public void readInteger() throws IOException
      Decodes ASN.1 Integer type
      Throws:
      IOException
    • readOctetString

      public void readOctetString() throws IOException
      Decodes ASN.1 Octetstring type
      Throws:
      IOException
    • readOID

      public void readOID() throws IOException
      Decodes ASN.1 ObjectIdentifier type
      Throws:
      IOException
    • readSequence

      public void readSequence​(ASN1Sequence sequence) throws IOException
      Decodes ASN.1 Sequence type
      Throws:
      IOException
    • readSequenceOf

      public void readSequenceOf​(ASN1SequenceOf sequenceOf) throws IOException
      Decodes ASN.1 SequenceOf type
      Throws:
      IOException
    • readSet

      public void readSet​(ASN1Set set) throws IOException
      Decodes ASN.1 Set type
      Throws:
      IOException
    • readSetOf

      public void readSetOf​(ASN1SetOf setOf) throws IOException
      Decodes ASN.1 SetOf type
      Throws:
      IOException
    • readString

      public void readString​(ASN1StringType type) throws IOException
      Decodes ASN.1 String type
      Throws:
      IOException - if an I/O error occurs or the end of the stream is reached
    • getEncoded

      public byte[] getEncoded()
      Returns encoded array. MUST be invoked after decoding corresponding ASN.1 notation
    • getBuffer

      public final byte[] getBuffer()
      Returns internal buffer used for decoding
    • getLength

      public final int getLength()
      Returns length of the current content for decoding
    • getOffset

      public final int getOffset()
      Returns the current offset
    • getEndOffset

      public final int getEndOffset()
      Returns end offset for the current encoded type
    • getTagOffset

      public final int getTagOffset()
      Returns start offset for the current encoded type
    • setVerify

      public final void setVerify()
      Sets verify mode.
    • read

      protected int read() throws IOException
      Reads the next encoded byte from the encoded input stream.
      Throws:
      IOException
    • readContent

      public void readContent() throws IOException
      Reads the next encoded content from the encoded input stream. The method MUST be used for reading a primitive encoded content.
      Throws:
      IOException
    • compactBuffer

      public void compactBuffer()
      Reallocates the buffer in order to make it exactly the size of data it contains
    • put

      public void put​(Object key, Object entry)
    • get

      public Object get​(Object key)