Package davmail.ldap

Class BerDecoder

java.lang.Object
davmail.ldap.Ber
davmail.ldap.BerDecoder

public final class BerDecoder extends Ber
A BER decoder. Contains methods to parse a BER buffer.
Author:
Jagane Sundar, Vincent Ryan
  • 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

      public int parseLength() throws Ber.DecodeException
      Parses a possibly variable length field.
      Throws:
      Ber.DecodeException
    • parseSeq

      public int parseSeq(int[] rlen) throws Ber.DecodeException
      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

      public int parseByte() throws Ber.DecodeException
      Parses the next byte in this BER buffer.
      Returns:
      The byte parsed.
      Throws:
      Ber.DecodeException
    • peekByte

      public int peekByte() throws Ber.DecodeException
      Returns the next byte in this BER buffer without consuming it.
      Returns:
      The next byte.
      Throws:
      Ber.DecodeException
    • parseBoolean

      public boolean parseBoolean() throws Ber.DecodeException
      Parses an ASN_BOOLEAN tagged integer from this BER buffer.
      Returns:
      true if the tagged integer is 0; false otherwise.
      Throws:
      Ber.DecodeException
    • parseEnumeration

      public int parseEnumeration() throws Ber.DecodeException
      Parses an ASN_ENUMERATED tagged integer from this BER buffer.
      Returns:
      The tag of enumeration.
      Throws:
      Ber.DecodeException
    • parseInt

      public int parseInt() throws Ber.DecodeException
      Parses an ASN_INTEGER tagged integer from this BER buffer.
      Returns:
      The value of the integer.
      Throws:
      Ber.DecodeException
    • parseIntWithTag

      protected int parseIntWithTag(int tag) throws Ber.DecodeException
      Parses an integer that's preceded by a tag.
       BER integer ::= tag length byte {byte}*
      
      Throws:
      Ber.DecodeException
    • parseString

      public String parseString(boolean decodeUTF8) throws Ber.DecodeException
      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

      public byte[] parseOctetString(int tag, int[] rlen) throws Ber.DecodeException
      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 not tag, 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.