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
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 Details
-
buffer
protected byte[] buffer -
offset
protected int offsetThe position in the buffer. Next read must place data into the buffer from this offset -
INDEFINIT_LENGTH
protected static final int INDEFINIT_LENGTHIndicates indefinite length of the current type- See Also:
- Constant Field Values
-
tag
public int tagCurrent decoded tag -
length
protected int lengthCurrent decoded length -
content
Current decoded content -
tagOffset
protected int tagOffsetCurrent decoded tag offset -
contentOffset
protected int contentOffsetCurrent decoded content offset -
choiceIndex
public int choiceIndexThe last choice index -
times
public int[] timesKeeps last decoded: year, month, day, hour, minute, second, millisecond -
oidElement
public int oidElement -
isVerify
protected boolean isVerifyIndicates 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 isIndefinedLengthIndicates 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
Creates stream for decoding.- Throws:
IOException
-
BerInputStream
Creates 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
Creates stream for decoding. Allocates initial buffer of default size- Throws:
IOException
-
BerInputStream
Creates stream for decoding.- Parameters:
initialSize- the internal buffer initial size- Throws:
IOException
-
-
Method Details
-
reset
Resets this stream to initial state.- Parameters:
encoded- a new bytes array to be decoded- Throws:
IOException- if an error occurs
-
next
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
Decodes ASN.1 bitstring type- Throws:
IOException
-
readEnumerated
Decodes ASN.1 Enumerated type- Throws:
IOException
-
readBoolean
Decodes ASN.1 boolean type- Throws:
IOException
-
readGeneralizedTime
Decodes ASN.1 GeneralizedTime type- Throws:
IOException- if error occured
-
readUTCTime
Decodes ASN.1 UTCTime type- Throws:
IOException- if an I/O error occurs or the end of the stream is reached
-
readInteger
Decodes ASN.1 Integer type- Throws:
IOException
-
readOctetString
Decodes ASN.1 Octetstring type- Throws:
IOException
-
readOID
Decodes ASN.1 ObjectIdentifier type- Throws:
IOException
-
readSequence
Decodes ASN.1 Sequence type- Throws:
IOException
-
readSequenceOf
Decodes ASN.1 SequenceOf type- Throws:
IOException
-
readSet
Decodes ASN.1 Set type- Throws:
IOException
-
readSetOf
Decodes ASN.1 SetOf type- Throws:
IOException
-
readString
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
Reads the next encoded byte from the encoded input stream.- Throws:
IOException
-
readContent
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
-
get
-