Class Asn1Decoder

  • All Implemented Interfaces:
    TLVBerDecoderMBean

    public final class Asn1Decoder
    extends Object
    implements TLVBerDecoderMBean
    A BER TLV Tag component decoder. This decoder instantiate a Tag. The tag won't be implementations should not copy the handle to the Tag object delivered but should copy the data if they need it over the long term.
    Author:
    Apache Directory Project
    • Field Detail

      • LOG

        private static final org.slf4j.Logger LOG
        The logger
      • MORE

        private static final boolean MORE
        This flag is used to indicate that there are more bytes in the stream
        See Also:
        Constant Field Values
      • END

        private static final boolean END
        This flag is used to indicate that there are no more bytes in the stream
        See Also:
        Constant Field Values
      • indefiniteLengthAllowed

        private boolean indefiniteLengthAllowed
        Flag that is used to allow/disallow the indefinite form of Length
      • maxLengthLength

        private int maxLengthLength
        The maximum number of bytes that could be used to encode the Length
      • maxTagLength

        private int maxTagLength
        The maximum number of bytes that could be used to encode the Tag
    • Constructor Detail

      • Asn1Decoder

        private Asn1Decoder()
        A public constructor of an Asn1 Decoder.
    • Method Detail

      • treatTagStartState

        private static boolean treatTagStartState​(ByteBuffer stream,
                                                  Asn1Container container)
        Treat the start of a TLV. It reads the tag and get its value.
        Parameters:
        stream - The ByteBuffer containing the PDU to decode
        container - The container that stores the current state, the result and other informations.
        Returns:
        true if there are more bytes to read, false otherwise
      • dumpTLVTree

        private static void dumpTLVTree​(Asn1Container container)
        Dump the current TLV tree
        Parameters:
        container - The container
      • isTLVDecoded

        private static boolean isTLVDecoded​(Asn1Container container)
        Check if the TLV tree is fully decoded
        Parameters:
        container - The container
        Returns:
        true if the TLV has been decoded
      • treatLengthStartState

        private static boolean treatLengthStartState​(ByteBuffer stream,
                                                     Asn1Container container)
                                              throws org.apache.directory.api.asn1.DecoderException
        Treat the Length start. The tag has been decoded, so we have to deal with the LENGTH, which can be multi-bytes.
        Parameters:
        stream - The ByteBuffer containing the PDU to decode
        container - The container that stores the current state, the result and other informations.
        Returns:
        true if there are more bytes to read, false otherwise
        Throws:
        org.apache.directory.api.asn1.DecoderException - Thrown if anything went wrong
      • treatLengthPendingState

        private static boolean treatLengthPendingState​(ByteBuffer stream,
                                                       Asn1Container container)
                                                throws org.apache.directory.api.asn1.DecoderException
        This function is called when a Length is in the process of being decoded, but the lack of bytes in the buffer stopped the process.
        Parameters:
        stream - The ByteBuffer containing the PDU to decode
        container - The container that stores the current state, the result and other informations.
        Returns:
        true if there are more bytes to read, false otherwise
        Throws:
        org.apache.directory.api.asn1.DecoderException - Thrown if anything went wrong
      • getParentLength

        private static String getParentLength​(TLV tlv)
        A debug function used to dump the expected length stack.
        Parameters:
        tlv - The current TLV.
        Returns:
        A string which represent the expected length stack.
      • treatLengthEndState

        private static void treatLengthEndState​(Asn1Container container)
                                         throws org.apache.directory.api.asn1.DecoderException
        The Length is fully decoded. We have to call an action to check the size.
        Parameters:
        container - The container that stores the current state, the result and other informations.
        Throws:
        org.apache.directory.api.asn1.DecoderException - Thrown if anything went wrong
      • treatValueStartState

        private static boolean treatValueStartState​(ByteBuffer stream,
                                                    Asn1Container container)
        Treat the Value part. We will distinguish two cases : - if the Tag is a Primitive one, we will get the value. - if the Tag is a Constructed one, nothing will be done.
        Parameters:
        stream - The ByteBuffer containing the PDU to decode
        container - The container that stores the current state, the result and other informations.
        Returns:
        true if there are more bytes to read, false otherwise
      • treatValuePendingState

        private static boolean treatValuePendingState​(ByteBuffer stream,
                                                      Asn1Container container)
        Treat a pending Value when we get more bytes in the buffer.
        Parameters:
        stream - The ByteBuffer containing the PDU to decode
        container - The container that stores the current state, the result and other informations.
        Returns:
        MORE if some bytes remain in the buffer when the value has been decoded, END if whe still need to get some more bytes.
      • treatTLVDoneState

        private static boolean treatTLVDoneState​(ByteBuffer stream,
                                                 Asn1Container container)
                                          throws org.apache.directory.api.asn1.DecoderException
        When the TLV has been fully decoded, we have to execute the associated action and switch to the next TLV, which will start with a Tag.
        Parameters:
        stream - The ByteBuffer containing the PDU to decode
        container - The container that stores the current state, the result and other informations.
        Returns:
        true if there are more bytes to read, false otherwise
        Throws:
        org.apache.directory.api.asn1.DecoderException - Thrown if anything went wrong
      • decode

        public static void decode​(ByteBuffer stream,
                                  Asn1Container container)
                           throws org.apache.directory.api.asn1.DecoderException
        The decoder main function. This is where we read bytes from the stream and go through the automaton. It's an inifnite loop which stop when no more bytes are to be read. It can occurs if the ByteBuffer is exhausted or if the PDU has been fully decoded.
        Parameters:
        stream - The ByteBuffer containing the PDU to decode
        container - The container that store the state, the result and other elements.
        Throws:
        org.apache.directory.api.asn1.DecoderException - Thrown if anything went wrong!
      • getMaxLengthLength

        public int getMaxLengthLength()
        Get the actual maximum number of bytes that can be used to encode the Length
        Specified by:
        getMaxLengthLength in interface TLVBerDecoderMBean
        Returns:
        The maximum bytes of the Length
      • getMaxTagLength

        public int getMaxTagLength()
        Get the actual maximum number of bytes that can be used to encode the Tag
        Specified by:
        getMaxTagLength in interface TLVBerDecoderMBean
        Returns:
        The maximum length of the Tag
      • isIndefiniteLengthAllowed

        public boolean isIndefiniteLengthAllowed()
        Tell if indefinite length form could be used for Length
        Specified by:
        isIndefiniteLengthAllowed in interface TLVBerDecoderMBean
        Returns:
        true if the Indefinite form is allowed