Package davmail.ldap
Class BerDecoder
java.lang.Object
davmail.ldap.Ber
davmail.ldap.BerDecoder
A BER decoder. Contains methods to parse a BER buffer.
- Author:
- Jagane Sundar, Vincent Ryan
-
Nested Class Summary
Nested classes/interfaces inherited from class davmail.ldap.Ber
Ber.DecodeException, Ber.EncodeException -
Field Summary
Fields inherited from class davmail.ldap.Ber
ASN_APPLICATION, ASN_BIT_STRING, ASN_BOOLEAN, ASN_CONSTRUCTOR, ASN_CONTEXT, ASN_ENUMERATED, ASN_INTEGER, ASN_NULL, ASN_OBJECT_ID, ASN_OCTET_STR, ASN_PRIMITIVE, ASN_PRIVATE, ASN_SEQUENCE, ASN_SET, ASN_SIMPLE_STRING, ASN_UNIVERSAL, buf, bufsize, offset -
Constructor Summary
ConstructorsConstructorDescriptionBerDecoder(byte[] buf, int offset, int bufsize) Creates a BER decoder that reads bytes from the specified buffer. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of unparsed bytes in this BER buffer.intReturns the current parse position.booleanParses an ASN_BOOLEAN tagged integer from this BER buffer.intParses the next byte in this BER buffer.intParses an ASN_ENUMERATED tagged integer from this BER buffer.intparseInt()Parses an ASN_INTEGER tagged integer from this BER buffer.protected intparseIntWithTag(int tag) Parses an integer that's preceded by a tag.intParses a possibly variable length field.byte[]parseOctetString(int tag, int[] rlen) Parses an octet string of a given type(tag) from this BER buffer.intparseSeq(int[] rlen) Parses the next sequence in this BER buffer.parseString(boolean decodeUTF8) Parses a string.parseStringWithTag(int tag, boolean decodeUTF8, int[] rlen) Parses a string of a given tag from this BER buffer.intpeekByte()Returns the next byte in this BER buffer without consuming it.voidreset()Resets this decode to start parsing from the initial offset (ie., same state as after calling the constructor).
-
Constructor Details
-
BerDecoder
public BerDecoder(byte[] buf, int offset, int bufsize) Creates a BER decoder that reads bytes from the specified buffer.
-
-
Method Details
-
reset
public void reset()Resets this decode to start parsing from the initial offset (ie., same state as after calling the constructor). -
getParsePosition
public int getParsePosition()Returns the current parse position. It points to the byte that will be parsed next. Useful for parsing sequences. -
parseLength
Parses a possibly variable length field.- Throws:
Ber.DecodeException
-
parseSeq
Parses the next sequence in this BER buffer.- Parameters:
rlen- An array for returning size of the sequence in bytes. If null, the size is not returned.- Returns:
- The sequence's tag.
- Throws:
Ber.DecodeException
-
parseByte
Parses the next byte in this BER buffer.- Returns:
- The byte parsed.
- Throws:
Ber.DecodeException
-
peekByte
Returns the next byte in this BER buffer without consuming it.- Returns:
- The next byte.
- Throws:
Ber.DecodeException
-
parseBoolean
Parses an ASN_BOOLEAN tagged integer from this BER buffer.- Returns:
- true if the tagged integer is 0; false otherwise.
- Throws:
Ber.DecodeException
-
parseEnumeration
Parses an ASN_ENUMERATED tagged integer from this BER buffer.- Returns:
- The tag of enumeration.
- Throws:
Ber.DecodeException
-
parseInt
Parses an ASN_INTEGER tagged integer from this BER buffer.- Returns:
- The value of the integer.
- Throws:
Ber.DecodeException
-
parseIntWithTag
Parses an integer that's preceded by a tag.BER integer ::= tag length byte {byte}*- Throws:
Ber.DecodeException
-
parseString
Parses a string.- Throws:
Ber.DecodeException
-
parseStringWithTag
public String parseStringWithTag(int tag, boolean decodeUTF8, int[] rlen) throws Ber.DecodeException Parses a string of a given tag from this BER buffer.BER simple string ::= tag length {byte}*- Parameters:
tag- The tag that precedes the string.decodeUTF8- If true, use UTF-8 when decoding the string; otherwise use ISO-Latin-1 (8859_1). Use true for LDAPv3; false for LDAPv2.rlen- An array for holding the relative parsed offset; if null offset not set.- Returns:
- The non-null parsed string.
- Throws:
Ber.DecodeException
-
parseOctetString
Parses an octet string of a given type(tag) from this BER buffer.BER Binary Data of type "tag" ::= tag length {byte}*- Parameters:
tag- The tag to look for.rlen- An array for returning the relative parsed position. If null, the relative parsed position is not returned.- Returns:
- A non-null array containing the octet string.
- Throws:
Ber.DecodeException- If the next byte in the BER buffer is nottag, or if length specified in the BER buffer exceeds the number of bytes left in the buffer.
-
bytesLeft
public int bytesLeft()Returns the number of unparsed bytes in this BER buffer.
-