Class IntegerDecoder

    • Field Detail

      • MASK

        private static final int[] MASK
        A mask used to get only the necessary bytes
    • Constructor Detail

      • IntegerDecoder

        private IntegerDecoder()
    • Method Detail

      • parse

        public static int parse​(BerValue value,
                                int min,
                                int max)
                         throws IntegerDecoderException
        Parse a byte buffer and send back an integer, controlling that this number is in a specified interval.
        Parameters:
        value - The Value containing the byte[] to parse
        min - Lowest value allowed, included
        max - Highest value allowed, included
        Returns:
        An integer
        Throws:
        IntegerDecoderException - Thrown if the byte[] does not contains an integer
      • parse

        public static int parse​(BerValue value)
                         throws IntegerDecoderException
        Parse a byte buffer and send back an integer
        Parameters:
        value - The byte buffer to parse
        Returns:
        An integer
        Throws:
        IntegerDecoderException - Thrown if the byte stream does not contains an integer
      • parseInt

        private static int parseInt​(BerValue value)
                             throws IntegerDecoderException
        Helper method used to parse the integer. We don't check any minimal or maximal bound. An BER encoded int can be either positive or negative. It uses the minimum number of bytes necessary to encode the value. The high order bit gives the sign of the integer : if it's 1, then it's a negative value, otherwise it's a positive value. Integer with a high order bit set to 1 but prefixed by a 0x00 are positive. If the integer is negative, then the 2 complement value is stored
        Here are a few samples :
        • 0x02 0x01 0x00 : integer 0
        • 0x02 0x01 0x01 : integer 1
        • 0x02 0x01 0x7F : integer 127
        • 0x02 0x01 0x80 : integer -128
        • 0x02 0x01 0x81 : integer -127
        • 0x02 0x01 0xFF : integer -1
        • 0x02 0x02 0x00 0x80 : integer 128
        • 0x02 0x02 0x00 0x81 : integer 129
        • 0x02 0x02 0x00 0xFF : integer 255
        and so on...
        Parameters:
        value - the BER PDU to parse
        Returns:
        The decoded value
        Throws:
        IntegerDecoderException - If the BER contains an invalid integer value