Class Asn1Decoder
- java.lang.Object
-
- org.apache.directory.api.asn1.ber.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 Summary
Fields Modifier and Type Field Description private static booleanENDThis flag is used to indicate that there are no more bytes in the streamprivate booleanindefiniteLengthAllowedFlag that is used to allow/disallow the indefinite form of Lengthprivate static org.slf4j.LoggerLOGThe loggerprivate intmaxLengthLengthThe maximum number of bytes that could be used to encode the Lengthprivate intmaxTagLengthThe maximum number of bytes that could be used to encode the Tagprivate static booleanMOREThis flag is used to indicate that there are more bytes in the stream
-
Constructor Summary
Constructors Modifier Constructor Description privateAsn1Decoder()A public constructor of an Asn1 Decoder.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voiddecode(ByteBuffer stream, Asn1Container container)The decoder main function.private static voiddumpTLVTree(Asn1Container container)Dump the current TLV treeintgetMaxLengthLength()Get the actual maximum number of bytes that can be used to encode the LengthintgetMaxTagLength()Get the actual maximum number of bytes that can be used to encode the Tagprivate static StringgetParentLength(TLV tlv)A debug function used to dump the expected length stack.booleanisIndefiniteLengthAllowed()Tell if indefinite length form could be used for Lengthprivate static booleanisTLVDecoded(Asn1Container container)Check if the TLV tree is fully decodedprivate static voidtreatLengthEndState(Asn1Container container)The Length is fully decoded.private static booleantreatLengthPendingState(ByteBuffer stream, Asn1Container container)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.private static booleantreatLengthStartState(ByteBuffer stream, Asn1Container container)Treat the Length start.private static booleantreatTagStartState(ByteBuffer stream, Asn1Container container)Treat the start of a TLV.private static booleantreatTLVDoneState(ByteBuffer stream, Asn1Container container)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.private static booleantreatValuePendingState(ByteBuffer stream, Asn1Container container)Treat a pending Value when we get more bytes in the buffer.private static booleantreatValueStartState(ByteBuffer stream, Asn1Container container)Treat the Value part.
-
-
-
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
-
-
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 decodecontainer- The container that stores the current state, the result and other informations.- Returns:
trueif there are more bytes to read,falseotherwise
-
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:
trueif 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 decodecontainer- The container that stores the current state, the result and other informations.- Returns:
trueif there are more bytes to read,falseotherwise- 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 decodecontainer- The container that stores the current state, the result and other informations.- Returns:
trueif there are more bytes to read,falseotherwise- 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 decodecontainer- The container that stores the current state, the result and other informations.- Returns:
trueif there are more bytes to read,falseotherwise
-
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 decodecontainer- The container that stores the current state, the result and other informations.- Returns:
MOREif some bytes remain in the buffer when the value has been decoded,ENDif 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 decodecontainer- The container that stores the current state, the result and other informations.- Returns:
trueif there are more bytes to read,falseotherwise- 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 decodecontainer- 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:
getMaxLengthLengthin interfaceTLVBerDecoderMBean- 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:
getMaxTagLengthin interfaceTLVBerDecoderMBean- Returns:
- The maximum length of the Tag
-
isIndefiniteLengthAllowed
public boolean isIndefiniteLengthAllowed()
Tell if indefinite length form could be used for Length- Specified by:
isIndefiniteLengthAllowedin interfaceTLVBerDecoderMBean- Returns:
trueif the Indefinite form is allowed
-
-