Package org.apache.harmony.security.asn1
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 Summary
Fields Modifier and Type Field Description protected byte[]bufferintchoiceIndexThe last choice indexObjectcontentCurrent decoded contentprotected intcontentOffsetCurrent decoded content offsetprotected static intINDEFINIT_LENGTHIndicates indefinite length of the current typeprotected booleanisIndefinedLengthIndicates defined or indefined reading mode for associated InputStream.protected booleanisVerifyIndicates verify or store mode.protected intlengthCurrent decoded lengthprotected intoffsetThe position in the buffer.intoidElementinttagCurrent decoded tagprotected inttagOffsetCurrent decoded tag offsetint[]timesKeeps last decoded: year, month, day, hour, minute, second, millisecond
-
Constructor Summary
Constructors Constructor Description BerInputStream(byte[] encoded)Creates stream for decoding.BerInputStream(byte[] encoded, int offset, int expectedLength)Creates stream for decoding.BerInputStream(InputStream in)Creates stream for decoding.BerInputStream(InputStream in, int initialSize)Creates stream for decoding.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcompactBuffer()Reallocates the buffer in order to make it exactly the size of data it containsObjectget(Object key)byte[]getBuffer()Returns internal buffer used for decodingbyte[]getEncoded()Returns encoded array.intgetEndOffset()Returns end offset for the current encoded typeintgetLength()Returns length of the current content for decodingstatic intgetLength(byte[] encoding)Returns the length of the encodingintgetOffset()Returns the current offsetintgetTagOffset()Returns start offset for the current encoded typeintnext()Decodes next encoded type.voidput(Object key, Object entry)protected intread()Reads the next encoded byte from the encoded input stream.voidreadBitString()Decodes ASN.1 bitstring typevoidreadBoolean()Decodes ASN.1 boolean typevoidreadContent()Reads the next encoded content from the encoded input stream.voidreadEnumerated()Decodes ASN.1 Enumerated typevoidreadGeneralizedTime()Decodes ASN.1 GeneralizedTime typevoidreadInteger()Decodes ASN.1 Integer typevoidreadOctetString()Decodes ASN.1 Octetstring typevoidreadOID()Decodes ASN.1 ObjectIdentifier typevoidreadSequence(ASN1Sequence sequence)Decodes ASN.1 Sequence typevoidreadSequenceOf(ASN1SequenceOf sequenceOf)Decodes ASN.1 SequenceOf typevoidreadSet(ASN1Set set)Decodes ASN.1 Set typevoidreadSetOf(ASN1SetOf setOf)Decodes ASN.1 SetOf typevoidreadString(ASN1StringType type)Decodes ASN.1 String typevoidreadUTCTime()Decodes ASN.1 UTCTime typevoidreset(byte[] encoded)Resets this stream to initial state.voidsetVerify()Sets verify mode.
-
-
-
Field Detail
-
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. Thecontentvariable 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 Detail
-
BerInputStream
public BerInputStream(byte[] encoded) throws IOExceptionCreates stream for decoding.- Throws:
IOException
-
BerInputStream
public BerInputStream(byte[] encoded, int offset, int expectedLength) throws IOExceptionCreates stream for decoding.- Parameters:
encoded- bytes array to be decodedoffset- the encoding offsetexpectedLength- 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 Detail
-
reset
public final void reset(byte[] encoded) throws IOExceptionResets 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 IOExceptionDecodes 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 IOExceptionDecodes ASN.1 bitstring type- Throws:
IOException
-
readEnumerated
public void readEnumerated() throws IOExceptionDecodes ASN.1 Enumerated type- Throws:
IOException
-
readBoolean
public void readBoolean() throws IOExceptionDecodes ASN.1 boolean type- Throws:
IOException
-
readGeneralizedTime
public void readGeneralizedTime() throws IOExceptionDecodes ASN.1 GeneralizedTime type- Throws:
IOException- if error occured
-
readUTCTime
public void readUTCTime() throws IOExceptionDecodes 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 IOExceptionDecodes ASN.1 Integer type- Throws:
IOException
-
readOctetString
public void readOctetString() throws IOExceptionDecodes ASN.1 Octetstring type- Throws:
IOException
-
readOID
public void readOID() throws IOExceptionDecodes 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 IOExceptionReads the next encoded byte from the encoded input stream.- Throws:
IOException
-
readContent
public void readContent() throws IOExceptionReads 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
-
-