You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2006/10/02 00:55:56 UTC
svn commit: r451834 - in /directory/branches/shared/0.9.5/asn1/src:
main/java/org/apache/directory/shared/asn1/ber/
main/java/org/apache/directory/shared/asn1/ber/grammar/
main/java/org/apache/directory/shared/asn1/ber/tlv/
main/java/org/apache/directo...
Author: elecharny
Date: Sun Oct 1 15:55:55 2006
New Revision: 451834
URL: http://svn.apache.org/viewvc?view=rev&rev=451834
Log:
simplified the TLV handling
Removed:
directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Length.java
directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Tag.java
Modified:
directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/AbstractContainer.java
directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/Asn1Decoder.java
directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/IAsn1Container.java
directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/grammar/AbstractGrammar.java
directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/grammar/GrammarAction.java
directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/grammar/GrammarTransition.java
directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/grammar/IStates.java
directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/TLV.java
directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java
directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/primitives/OID.java
directory/branches/shared/0.9.5/asn1/src/test/java/org/apache/directory/shared/asn1/ber/tlv/LengthTest.java
Modified: directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/AbstractContainer.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/AbstractContainer.java?view=diff&rev=451834&r1=451833&r2=451834
==============================================================================
--- directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/AbstractContainer.java (original)
+++ directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/AbstractContainer.java Sun Oct 1 15:55:55 2006
@@ -38,26 +38,12 @@
// ~ Instance fields
// ----------------------------------------------------------------------------
- /**
- * The grammars that are used. It's a stack as we can switch grammars
- */
- protected IGrammar[] grammarStack;
-
/** All the possible grammars */
- protected IGrammar[] grammars;
+ protected IGrammar grammar;
/** Store a stack of the current states used when switching grammars */
protected int[] stateStack;
- /** Store a stack of allowed pop */
- protected boolean[] popAllowedStack;
-
- /** The number of stored grammars */
- protected int nbGrammars;
-
- /** The current grammar */
- protected int currentGrammar;
-
/** The current state of the decoding */
protected int state;
@@ -76,10 +62,6 @@
/** The grammar end transition flag */
protected boolean grammarEndAllowed;
- /** The grammar pop transition flag */
- protected boolean grammarPopAllowed;
-
-
// ~ Methods
// ------------------------------------------------------------------------------------
@@ -90,59 +72,7 @@
*/
public IGrammar getGrammar()
{
- return grammarStack[currentGrammar];
- }
-
-
- /**
- * Add a IGrammar to use
- *
- * @param grammar
- * The grammar to add.
- */
- public void addGrammar( IGrammar grammar )
- {
- grammars[nbGrammars++] = grammar;
- }
-
-
- /**
- * Switch to another grammar
- *
- * @param currentState
- * The current state in the current grammar
- * @param grammar
- * The grammar to add.
- */
- public void switchGrammar( int currentState, int grammar )
- {
- stateStack[currentGrammar] = currentState;
- currentGrammar++;
- popAllowedStack[currentGrammar] = false;
- grammarStack[currentGrammar] = grammars[( grammar >> 8 ) - 1];
- }
-
-
- /**
- * restore the previous grammar (the one before a switch has occured)
- *
- * @return The previous current state, if any.
- */
- public int restoreGrammar()
- {
- grammarStack[currentGrammar] = null;
- popAllowedStack[currentGrammar] = false;
- currentGrammar--;
-
- if ( currentGrammar >= 0 )
- {
- return stateStack[currentGrammar];
- }
- else
- {
- return -1;
- }
-
+ return grammar;
}
@@ -160,8 +90,7 @@
/**
* Set the new current state
*
- * @param state
- * The new state
+ * @param state The new state
*/
public void setState( int state )
{
@@ -183,9 +112,8 @@
/**
* Set the flag to allow a end transition
*
- * @param endAllowed
- * true or false, depending on the next transition being an end
- * or not.
+ * @param endAllowed true or false, depending on the next transition
+ * being an end or not.
*/
public void grammarEndAllowed( boolean grammarEndAllowed )
{
@@ -194,30 +122,6 @@
/**
- * Check that we can have a pop after this transition
- *
- * @return true if this can be the last transition before a pop
- */
- public boolean isGrammarPopAllowed()
- {
- return popAllowedStack[currentGrammar];
- }
-
-
- /**
- * Set the flag to allow a pop transition
- *
- * @param popAllowed
- * true or false, depending on the next transition allows a pop
- * or not.
- */
- public void grammarPopAllowed( boolean grammarPopAllowed )
- {
- popAllowedStack[currentGrammar] = grammarPopAllowed;
- }
-
-
- /**
* Get the transition
*
* @return Returns the transition from the previous state to the new state
@@ -231,8 +135,7 @@
/**
* Update the transition from a state to another
*
- * @param transition
- * The transition to set
+ * @param transition The transition to set
*/
public void setTransition( int transition )
{
@@ -241,56 +144,9 @@
/**
- * Gert the current grammar number
- *
- * @return Returns the currentGrammar.
- */
- public int getCurrentGrammar()
- {
- return currentGrammar;
- }
-
-
- /**
- * Get the current grammar type.
- *
- * @return Returns the current Grammar type, or -1 if not found.
- */
- public int getCurrentGrammarType()
- {
-
- for ( int i = 0; i < grammars.length; i++ )
- {
-
- if ( grammars[i] == grammarStack[currentGrammar] )
- {
- return i;
- }
- }
-
- return -1;
- }
-
-
- /**
- * Initialize the grammar stack
- *
- * @param grammar
- * Set the initial grammar
- */
- public void setInitGrammar( int grammar )
- {
- currentGrammar++;
- grammarStack[currentGrammar] = grammars[grammar];
- stateStack[currentGrammar] = 0;
- }
-
-
- /**
* Set the current TLV
*
- * @param tlv
- * The current TLV
+ * @param tlv The current TLV
*/
public void setCurrentTLV( TLV tlv )
{
@@ -334,8 +190,7 @@
/**
* Set the parent TLV.
*
- * @param The
- * parent TLV to set.
+ * @param The parent TLV to set.
*/
public void setParentTLV( TLV parentTLV )
{
@@ -348,7 +203,6 @@
*/
public void clean()
{
- currentGrammar = 0;
tlv = null;
parentTLV = null;
transition = 0;
Modified: directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/Asn1Decoder.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/Asn1Decoder.java?view=diff&rev=451834&r1=451833&r2=451834
==============================================================================
--- directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/Asn1Decoder.java (original)
+++ directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/Asn1Decoder.java Sun Oct 1 15:55:55 2006
@@ -22,11 +22,8 @@
import org.apache.directory.shared.asn1.ber.grammar.IStates;
import org.apache.directory.shared.asn1.ber.tlv.ITLVBerDecoderMBean;
-import org.apache.directory.shared.asn1.ber.tlv.Length;
import org.apache.directory.shared.asn1.ber.tlv.TLV;
import org.apache.directory.shared.asn1.ber.tlv.TLVStateEnum;
-import org.apache.directory.shared.asn1.ber.tlv.Tag;
-import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
import org.apache.directory.shared.asn1.ber.tlv.Value;
import org.apache.directory.shared.asn1.codec.DecoderException;
import org.apache.directory.shared.asn1.util.Asn1StringUtils;
@@ -95,18 +92,14 @@
/**
* Treat the start of a TLV. It reads the tag and get its value.
*
- * @param stream
- * The ByteBuffer containing the PDU to decode
- * @param container
- * The container that stores the current state, the result and
- * other informations.
+ * @param stream The ByteBuffer containing the PDU to decode
+ * @param container The container that stores the current state,
+ * the result and other informations.
* @return <code>true</code> if there are more bytes to read, <code>false
- * </code>
- * otherwise
- * @throws DecoderException
- * If something went wrong.
+ * </code> otherwise
+ * @throws DecoderException If something went wrong.
*/
- private boolean treatTagStartState( ByteBuffer stream, IAsn1Container container ) throws DecoderException
+ private boolean treatTagStartState( ByteBuffer stream, IAsn1Container container ) throws DecoderException, NamingException
{
if ( stream.hasRemaining() )
@@ -115,57 +108,30 @@
byte octet = stream.get();
TLV tlv = new TLV();
- Tag tag = tlv.getTag();
+ tlv.setTag( octet );
- tag.setSize( 1 );
- tag.setPrimitive( ( octet & Tag.CONSTRUCTED_FLAG ) == 0 );
- tag.setTypeClass( Tag.TYPE_CLASS[( octet & Tag.TYPE_CLASS_MASK ) >>> 6] );
+ // Store the current TLV in the container.
+ container.setCurrentTLV( tlv );
- int value = octet & Tag.SHORT_MASK;
+ // Create a link between the current TLV with its parent
+ tlv.setParent( container.getParentTLV() );
- if ( value == Tag.SHORT_MASK )
- {
+ // Switch to the next state, which is the Length decoding
+ container.setState( TLVStateEnum.LENGTH_STATE_START );
- // we have to check the typeClass. UNIVERSAL class is not
- // allowed with this value.
- if ( tag.isUniversal() )
+ if ( IS_DEBUG )
+ {
+ if ( tlv != null )
{
- throw new DecoderException( "Universal tag 31 is reserved" );
+ byte tag = container.getCurrentTLV().getTag();
+ log.debug( "Tag {} has been decoded", Asn1StringUtils.dumpByte( tag ) );
}
-
- // we will have more than one byte to encode the value
- // The tag is encoded on [2 - 6 bytes], its value
- // is container in the 7 lower bits of the bytes following
- // the first byte.
- container.setState( TLVStateEnum.TAG_STATE_PENDING );
- tag.setId( 0 );
- tag.addByte( octet );
- }
- else
- {
- // It's a tag wich value is below 30 (31 is not allowed
- // as it signals a multi-bytes value. Everything is done.
-
- // We have to check for reserved tags if typeClass is UNIVERSAL
- if ( tag.isUniversal() )
+ else
{
-
- if ( ( value == UniversalTag.RESERVED_14 ) || ( value == UniversalTag.RESERVED_15 ) )
- {
- throw new DecoderException( "Universal tag " + value + " is reserved" );
- }
+ log.debug( "Tag has been decoded, but is null" );
}
-
- tag.setId( value );
- tag.addByte( octet );
-
- // The tag has been completed, we have to decode the Length
- container.setState( TLVStateEnum.TAG_STATE_END );
}
- // Store the current TLV in the container.
- container.setCurrentTLV( tlv );
-
return MORE;
}
else
@@ -176,81 +142,24 @@
}
}
-
- /**
- * Treat a tag that is more than one byte long if the stream was cut in
- * pieces. This function is called when some new bytes where got from the
- * stream.
- *
- * @param stream
- * The ByteBuffer containing the PDU to decode
- * @param container
- * The container that stores the current state, the result and
- * other informations.
- * @return <code>true</code> if there are more bytes to read, <code>false
- * </code>
- * otherwise
- * @throws DecoderException
- * Thrown if anything went wrong
- */
- private boolean treatTagPendingState( ByteBuffer stream, IAsn1Container container ) throws DecoderException
- {
-
- if ( stream.hasRemaining() )
- {
-
- Tag tag = container.getCurrentTLV().getTag();
- byte octet = stream.get();
-
- if ( tag.getSize() >= Tag.MAX_TAG_BYTES )
- {
- container.setState( TLVStateEnum.TAG_STATE_OVERFLOW );
- log.error( "Tag label Overflow" );
- throw new DecoderException( "Tag label overflow" );
- }
-
- byte val = ( byte ) ( octet & Tag.LONG_MASK );
-
- tag.setId( ( tag.getId() << 7 ) | val );
- tag.incTagSize();
-
- if ( val == octet )
- {
-
- // The Tag is completed, so let's decode the Length
- container.setState( TLVStateEnum.LENGTH_STATE_START );
- }
-
- return MORE;
- }
- else
- {
-
- return END;
- }
-
- }
-
-
/**
* Dump the current TLV tree
*
- * @param container
- * The container
+ * @param container The container
*/
private void dumpTLVTree( IAsn1Container container )
{
StringBuffer sb = new StringBuffer();
TLV current = container.getCurrentTLV();
- sb.append( "TLV" ).append( Asn1StringUtils.dumpByte( current.getTag().getTagBytes()[0] ) ).append( "(" )
+ sb.append( "TLV" ).append( Asn1StringUtils.dumpByte( current.getTag() ) ).append( "(" )
.append( current.getExpectedLength() ).append( ")" );
current = current.getParent();
while ( current != null )
{
- sb.append( "-TLV" ).append( Asn1StringUtils.dumpByte( current.getTag().getTagBytes()[0] ) ).append( "(" )
+ sb.append( "-TLV" ).append( Asn1StringUtils.dumpByte( current.getTag() ) ).append( "(" )
.append( current.getExpectedLength() ).append( ")" );
current = current.getParent();
}
@@ -265,8 +174,7 @@
/**
* Check if the TLV tree is fully decoded
*
- * @param container
- * The container
+ * @param container The container
*/
private boolean isTLVDecoded( IAsn1Container container )
{
@@ -296,86 +204,39 @@
}
}
-
- /**
- * Action to be executed when the Tag has been decoded. Basically, this is a
- * debug action. We will log the information that the Tag has been decoded.
- *
- * @param container
- * The container that stores the current state, the result and
- * other informations.
- * @throws DecoderException
- * Thrown if anything went wrong
- */
- private void treatTagEndState( IAsn1Container container ) throws DecoderException, NamingException
- {
-
- if ( IS_DEBUG )
- {
- if ( container.getCurrentTLV() != null )
- {
- Tag tag = container.getCurrentTLV().getTag();
- log.debug( "Tag {} has been decoded", tag.toString() );
- }
- else
- {
- log.debug( "Tag has been decoded, but is null" );
- }
- }
-
- // Create a link between the current TLV with its parent
- container.getCurrentTLV().setParent( container.getParentTLV() );
-
- // After having decoded a tag, we have to execute the action
- // which controls if this tag is allowed and well formed.
- container.getGrammar().executeAction( container );
-
- // Switch to the next state, which is the Length decoding
- container.setState( TLVStateEnum.LENGTH_STATE_START );
- }
-
-
/**
* Treat the Length start. The tag has been decoded, so we have to deal with
* the LENGTH, which can be multi-bytes.
*
- * @param stream
- * The ByteBuffer containing the PDU to decode
- * @param container
- * The container that stores the current state, the result and
- * other informations.
+ * @param stream The ByteBuffer containing the PDU to decode
+ * @param container The container that stores the current state,
+ * the result and other informations.
* @return <code>true</code> if there are more bytes to read, <code>false
- * </code>
- * otherwise
- * @throws DecoderException
- * Thrown if anything went wrong
+ * </code> otherwise
+ * @throws DecoderException Thrown if anything went wrong
*/
private boolean treatLengthStartState( ByteBuffer stream, IAsn1Container container ) throws DecoderException
{
if ( stream.hasRemaining() )
{
-
byte octet = stream.get();
+ TLV tlv = container.getCurrentTLV();
- Length length = container.getCurrentTLV().getLength();
-
- if ( ( octet & Length.LENGTH_LONG_FORM ) == 0 )
+ if ( ( octet & TLV.LENGTH_LONG_FORM ) == 0 )
{
// We don't have a long form. The Length of the Value part is
// given by this byte.
- length.setLength( octet );
- length.setExpectedLength( 0 );
- length.setCurrentLength( 0 );
- length.setSize( 1 );
+ tlv.setLength( octet );
+ tlv.setLengthNbBytes( 1 );
container.setState( TLVStateEnum.LENGTH_STATE_END );
}
- else if ( ( octet & Length.LENGTH_EXTENSION_RESERVED ) != Length.LENGTH_EXTENSION_RESERVED )
+ else if ( ( octet & TLV.LENGTH_EXTENSION_RESERVED ) != TLV.LENGTH_EXTENSION_RESERVED )
{
- int expectedLength = octet & Length.SHORT_MASK;
+ int expectedLength = octet & TLV.LENGTH_SHORT_MASK;
if ( expectedLength > 4 )
{
@@ -383,10 +244,9 @@
throw new DecoderException( "Overflow : can't have more than 4 bytes long length" );
}
- length.setExpectedLength( expectedLength );
- length.setCurrentLength( 0 );
- length.setLength( 0 );
- length.setSize( 1 );
+ tlv.setLength( 0 );
+ tlv.setLengthNbBytes( 1 + expectedLength );
+ tlv.setLengthBytesRead( 1 );
container.setState( TLVStateEnum.LENGTH_STATE_PENDING );
}
else
@@ -399,7 +259,6 @@
}
else
{
-
return END;
}
}
@@ -409,16 +268,12 @@
* 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.
*
- * @param stream
- * The ByteBuffer containing the PDU to decode
- * @param container
- * The container that stores the current state, the result and
- * other informations.
+ * @param stream The ByteBuffer containing the PDU to decode
+ * @param container The container that stores the current state,
+ * the result and other informations.
* @return <code>true</code> if there are more bytes to read, <code>false
- * </code>
- * otherwise
- * @throws DecoderException
- * Thrown if anything went wrong
+ * </code> otherwise
+ * @throws DecoderException Thrown if anything went wrong
*/
private boolean treatLengthPendingState( ByteBuffer stream, IAsn1Container container ) throws DecoderException
{
@@ -426,9 +281,10 @@
if ( stream.hasRemaining() )
{
- Length length = container.getCurrentTLV().getLength();
+ TLV tlv = container.getCurrentTLV();
+ int length = tlv.getLength();
- while ( length.getCurrentLength() < length.getExpectedLength() )
+ while ( tlv.getLengthBytesRead() < tlv.getLengthNbBytes() )
{
byte octet = stream.get();
@@ -438,16 +294,27 @@
log.debug( " current byte : {}", Asn1StringUtils.dumpByte( octet ) );
}
- length.incCurrentLength();
- length.incSize();
- length.setLength( ( length.getLength() << 8 ) | ( octet & 0x00FF ) );
+ tlv.incLengthBytesRead();
+ length = ( length << 8 ) | ( octet & 0x00FF );
if ( stream.hasRemaining() == false )
{
+ tlv.setLength( length );
+
+ if ( tlv.getLengthBytesRead() < tlv.getLengthNbBytes() )
+ {
+ container.setState( TLVStateEnum.LENGTH_STATE_PENDING );
+ }
+ else
+ {
+ container.setState( TLVStateEnum.LENGTH_STATE_END );
+ }
+
return END;
}
}
+ tlv.setLength( length );
container.setState( TLVStateEnum.LENGTH_STATE_END );
return MORE;
@@ -463,8 +330,7 @@
/**
* A debug function used to dump the expected length stack.
*
- * @param tlv
- * The current TLV.
+ * @param tlv The current TLV.
* @return A string which represent the expected length stack.
*/
private String getParentLength( TLV tlv )
@@ -495,16 +361,14 @@
/**
* The Length is fully decoded. We have to call an action to check the size.
*
- * @param container
- * The container that stores the current state, the result and
- * other informations.
- * @throws DecoderException
- * Thrown if anything went wrong
+ * @param container The container that stores the current state,
+ * the result and other informations.
+ * @throws DecoderException Thrown if anything went wrong
*/
private void treatLengthEndState( IAsn1Container container ) throws DecoderException
{
TLV tlv = container.getCurrentTLV();
- Length length = tlv.getLength();
+ int length = tlv.getLength();
// We will check the length here. What we must control is
// that the enclosing constructed TLV expected length is not
@@ -520,14 +384,14 @@
{
// This is the first TLV, so we can't check anything. We will
// just store this TLV as the root of the PDU
- tlv.setExpectedLength( length.getLength() );
+ tlv.setExpectedLength( length );
container.setParentTLV( tlv );
if ( IS_DEBUG )
{
- if ( ( tlv != null ) && ( tlv.getLength() != null ) )
+ if ( tlv != null )
{
- log.debug( "Root TLV[{}]", new Integer( tlv.getLength().getLength() ) );
+ log.debug( "Root TLV[{}]", new Integer( length ) );
}
else
{
@@ -550,23 +414,23 @@
throw new DecoderException( "The current Value length is above the expected length" );
}
+ // deal with the particular case where expected length equal
+ // the current length, which means that the parentTLV has been
+ // completed.
if ( expectedLength == currentLength )
{
parentTLV.setExpectedLength( 0 );
- // deal with the particular case where expected length equal
- // the current length, which means that the parentTLV has been
- // completed.
// We also have to check that the current TLV is a constructed
// one.
// In this case, we have to switch from this parent TLV
// to the parent's parent TLV.
- if ( tlv.getTag().isConstructed() )
+ if ( tlv.isConstructed() )
{
// here, we also have another special case : a
// zero length TLV. We must then unstack all
// the parents which length is null.
- if ( tlv.getLength().getLength() == 0 )
+ if ( length == 0 )
{
// We will set the parent to the first parentTLV which
// expectedLength
@@ -594,11 +458,12 @@
}
tlv.setParent( parentTLV );
- tlv.setExpectedLength( tlv.getLength().getLength() );
+ tlv.setExpectedLength( length );
}
else
{
- tlv.setExpectedLength( tlv.getLength().getLength() );
+ tlv.setExpectedLength( length );
+
// It's over, the parent TLV has been completed.
// Go back to the parent's parent TLV until we find
// a tlv which is not complete.
@@ -623,9 +488,9 @@
{
// Renew the expected Length.
parentTLV.setExpectedLength( expectedLength - currentLength );
- tlv.setExpectedLength( tlv.getLength().getLength() );
+ tlv.setExpectedLength( length );
- if ( tlv.getTag().isConstructed() )
+ if ( tlv.isConstructed() )
{
// We have a constructed tag, so we must switch the
// parentTLV
@@ -638,18 +503,16 @@
if ( IS_DEBUG )
{
- log.debug( "Length {} has been decoded", length.toString() );
+ log.debug( "Length {} has been decoded", new Integer( length ) );
}
- if ( length.getLength() == 0 )
+ if ( length == 0 )
{
-
// The length is 0, so we can't expect a value.
container.setState( TLVStateEnum.TLV_STATE_DONE );
}
else
{
-
// Go ahead and decode the value part
container.setState( TLVStateEnum.VALUE_STATE_START );
}
@@ -661,23 +524,19 @@
* Primitive one, we will get the value. - if the Tag is a Constructed one,
* nothing will be done.
*
- * @param stream
- * The ByteBuffer containing the PDU to decode
- * @param container
- * The container that stores the current state, the result and
- * other informations.
+ * @param stream The ByteBuffer containing the PDU to decode
+ * @param container The container that stores the current state,
+ * the result and other informations.
* @return <code>true</code> if there are more bytes to read, <code>false
- * </code>
- * otherwise
- * @throws DecoderException
- * Thrown if anything went wrong
+ * </code> otherwise
+ * @throws DecoderException Thrown if anything went wrong
*/
private boolean treatValueStartState( ByteBuffer stream, IAsn1Container container ) throws DecoderException
{
TLV currentTlv = container.getCurrentTLV();
- if ( currentTlv.getTag().isConstructed() )
+ if ( TLV.isConstructed( currentTlv.getTag() ) )
{
container.setState( TLVStateEnum.TLV_STATE_DONE );
@@ -686,7 +545,7 @@
else
{
- int length = currentTlv.getLength().getLength();
+ int length = currentTlv.getLength();
int nbBytes = stream.remaining();
if ( nbBytes < length )
@@ -712,23 +571,20 @@
/**
* Treat a pending Value when we get more bytes in the buffer.
*
- * @param stream
- * The ByteBuffer containing the PDU to decode
- * @param container
- * The container that stores the current state, the result and
- * other informations.
+ * @param stream The ByteBuffer containing the PDU to decode
+ * @param container The container that stores the current state,
+ * the result and other informations.
* @return <code>MORE</code> if some bytes remain in the buffer when the
- * value has been decoded, <code>END</code> if whe still need to
- * get some more bytes.
- * @throws DecoderException
- * Thrown if anything went wrong
+ * value has been decoded, <code>END</code> if whe still need to get some
+ * more bytes.
+ * @throws DecoderException Thrown if anything went wrong
*/
private boolean treatValuePendingState( ByteBuffer stream, IAsn1Container container ) throws DecoderException
{
TLV currentTlv = container.getCurrentTLV();
- int length = currentTlv.getLength().getLength();
+ int length = currentTlv.getLength();
int currentLength = currentTlv.getValue().getCurrentLength();
int nbBytes = stream.remaining();
@@ -757,16 +613,12 @@
* 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.
*
- * @param stream
- * The ByteBuffer containing the PDU to decode
- * @param container
- * The container that stores the current state, the result and
- * other informations.
+ * @param stream The ByteBuffer containing the PDU to decode
+ * @param container The container that stores the current state,
+ * the result and other informations.
* @return <code>true</code> if there are more bytes to read, <code>false
- * </code>
- * otherwise
- * @throws DecoderException
- * Thrown if anything went wrong
+ * </code> otherwise
+ * @throws DecoderException Thrown if anything went wrong
*/
private boolean treatTLVDoneState( ByteBuffer stream, IAsn1Container container ) throws DecoderException, NamingException
{
@@ -815,8 +667,7 @@
* An helper function that return a string representing the current state
* for debuging purpose.
*
- * @param state
- * The state
+ * @param state The state
* @return A string representation of the state
*/
private String stateToString( int state )
@@ -828,9 +679,6 @@
case TLVStateEnum.TAG_STATE_START:
return "TAG_STATE_START";
- case TLVStateEnum.TAG_STATE_PENDING:
- return "TAG_STATE_PENDING";
-
case TLVStateEnum.TAG_STATE_END:
return "TAG_STATE_END";
@@ -867,22 +715,20 @@
* more bytes are to be read. It can occurs if the ByteBuffer is exhausted
* or if the PDU has been fully decoded.
*
- * @param stream
- * The ByteBuffer containing the PDU to decode
- * @param container
- * The container that store the state, the result and other
- * elements.
- * @throws DecoderException
- * Thrown if anything went wrong!
+ * @param stream The ByteBuffer containing the PDU to decode
+ * @param container The container that store the state, the result
+ * and other elements.
+ * @throws DecoderException Thrown if anything went wrong!
*/
public void decode( ByteBuffer stream, IAsn1Container container ) throws DecoderException, NamingException
{
/*
* We have to deal with the current state. This is an infinite loop,
- * which will stop for any of these reasons : - STATE_END has been
- * reached (hopefully, the most frequent case) - buffer is empty (it
- * could happen) - STATE_OVERFLOW : bad situation ! The PDU may be a
+ * which will stop for any of these reasons :
+ * - STATE_END has been reached (hopefully, the most frequent case)
+ * - buffer is empty (it could happen)
+ * - STATE_OVERFLOW : bad situation ! The PDU may be a
* malevolous hand crafted ones, that try to "kill" our decoder. Whe
* must log it with all information to track back this case, and punish
* the guilty !
@@ -926,20 +772,6 @@
break;
- case TLVStateEnum.TAG_STATE_PENDING:
- hasRemaining = treatTagPendingState( stream, container );
-
- break;
-
- case TLVStateEnum.TAG_STATE_END:
- treatTagEndState( container );
-
- break;
-
- case TLVStateEnum.TAG_STATE_OVERFLOW:
- log.error( "Incompatible state : OVERFLOW" );
- throw new DecoderException( "Incompatible state occured" );
-
case TLVStateEnum.LENGTH_STATE_START:
hasRemaining = treatLengthStartState( stream, container );
@@ -1018,7 +850,7 @@
}
return;
- } // end method decode
+ }
/**
@@ -1028,7 +860,6 @@
*/
public int getMaxLengthLength()
{
-
return maxLengthLength;
}
@@ -1040,7 +871,6 @@
*/
public int getMaxTagLength()
{
-
return maxTagLength;
}
@@ -1079,11 +909,9 @@
/**
* Set the maximul length for a Length
*
- * @param maxLengthLength
- * The lengthLength to set.
- * @throws DecoderException
- * Thrown if the indefinite length is allowed or if the length's
- * Length is above 126 bytes
+ * @param maxLengthLength The lengthLength to set.
+ * @throws DecoderException Thrown if the indefinite length is
+ * allowed or if the length's Length is above 126 bytes
*/
public void setMaxLengthLength( int maxLengthLength ) throws DecoderException
{
@@ -1100,13 +928,10 @@
/**
* Set the maximum Tag length
*
- * @param maxTagLength
- * The tagLength to set.
+ * @param maxTagLength The tagLength to set.
*/
public void setMaxTagLength( int maxTagLength )
{
this.maxTagLength = maxTagLength;
}
-
}
-
Modified: directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/IAsn1Container.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/IAsn1Container.java?view=diff&rev=451834&r1=451833&r2=451834
==============================================================================
--- directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/IAsn1Container.java (original)
+++ directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/IAsn1Container.java Sun Oct 1 15:55:55 2006
@@ -47,8 +47,7 @@
/**
* Set the new current state
*
- * @param state
- * The new state
+ * @param state The new state
*/
void setState( int state );
@@ -56,8 +55,7 @@
/**
* Set the current TLV
*
- * @param tlv
- * The current TLV
+ * @param tlv The current TLV
*/
public void setCurrentTLV( TLV tlv );
@@ -79,47 +77,6 @@
/**
- * Add a new IGrammar to use
- *
- * @param grammar
- * The grammar to add.
- */
- public void addGrammar( IGrammar grammar );
-
-
- /**
- * Switch to another grammar
- *
- * @param grammar
- * The grammar to switch to.
- */
- public void switchGrammar( int currentState, int grammar );
-
-
- /**
- * restore the previous grammar (the one before a switch has occured)
- *
- * @return Returns the previous state if any.
- */
- public int restoreGrammar();
-
-
- /**
- * @return Returns the currentGrammar.
- */
- public int getCurrentGrammar();
-
-
- /**
- * Set the first grammar to use
- *
- * @param The
- * first grammar .
- */
- public void setInitGrammar( int grammar );
-
-
- /**
* Get the transition
*
* @return Returns the transition from the previous state to the new state
@@ -130,18 +87,10 @@
/**
* Update the transition from a state to another
*
- * @param transition
- * The transition to set
+ * @param transition The transition to set
*/
public void setTransition( int transition );
-
- /**
- * @return Returns the current Grammar type, or -1 if not found.
- */
- public int getCurrentGrammarType();
-
-
/**
* @return Returns the states.
*/
@@ -157,8 +106,7 @@
/**
* Set the parent TLV
*
- * @param The
- * new parent TLV
+ * @param The new parent TLV
*/
public void setParentTLV( TLV parentTLV );
@@ -174,27 +122,8 @@
/**
* Set the flag to allow a end transition
*
- * @param endAllowed
- * true or false, depending on the next transition being an end
- * or not.
+ * @param endAllowed true or false, depending on the next transition
+ * being an end or not.
*/
public void grammarEndAllowed( boolean grammarEndAllowed );
-
-
- /**
- * Check that we can have a pop state after this transition
- *
- * @return true if we can pop the grammar
- */
- public boolean isGrammarPopAllowed();
-
-
- /**
- * Set the flag to allow a pop of the current grammar
- *
- * @param popAllowed
- * true or false, depending on the next transition allows a pop
- * or not.
- */
- public void grammarPopAllowed( boolean grammarPopAllowed );
}
Modified: directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/grammar/AbstractGrammar.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/grammar/AbstractGrammar.java?view=diff&rev=451834&r1=451833&r2=451834
==============================================================================
--- directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/grammar/AbstractGrammar.java (original)
+++ directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/grammar/AbstractGrammar.java Sun Oct 1 15:55:55 2006
@@ -22,10 +22,7 @@
import javax.naming.NamingException;
-import org.apache.directory.shared.asn1.Asn1Object;
import org.apache.directory.shared.asn1.ber.IAsn1Container;
-import org.apache.directory.shared.asn1.ber.tlv.TLV;
-import org.apache.directory.shared.asn1.ber.tlv.Tag;
import org.apache.directory.shared.asn1.codec.DecoderException;
import org.apache.directory.shared.asn1.util.Asn1StringUtils;
import org.slf4j.LoggerFactory;
@@ -66,7 +63,7 @@
/** The grammar's states */
protected IStates statesEnum;
-
+ /** Default constructor */
public AbstractGrammar()
{
}
@@ -89,63 +86,23 @@
/**
* Set the grammar's name
*
- * @param name
- * DOCUMENT ME!
+ * @param name The new grammar name
*/
public void setName( String name )
{
this.name = name;
}
-
- /**
- * Checks the Length. If the current TLV length is above the expected length
- * of the PDU, an exception is thrown. The current Object contains the sum
- * of all included Objects and element, which is compared with the PDU's
- * expected length (the Length part of the PDU containing the Object).
- *
- * @param object
- * The Object that is being decoded.
- * @param tlv
- * The current TLV
- * @throws DecoderException
- * Thrown if the expected length is lower than the sum of all
- * the included elements.
- */
- protected void checkLength( Asn1Object object, TLV tlv ) throws DecoderException
- {
-
- // Create a new expected Length
- int expectedLength = tlv.getLength().getLength();
-
- int tlvLength = tlv.getSize();
-
- if ( IS_DEBUG )
- {
- log.debug( "Expected Length = " + ( ( Asn1Object ) object ).getExpectedLength() + ", current length = "
- + ( ( Asn1Object ) object ).getCurrentLength() + ", added length = " + expectedLength
- + ", tlv length = " + tlvLength );
- }
-
- // We already are at the top level.
- // An exception will be thrown if the current length exceed the expected
- // length
- ( ( Asn1Object ) object ).addLength( tlvLength );
- }
-
-
/**
* Get the transition associated with the state and tag
*
- * @param state
- * The current state
- * @param tag
- * The current tag
+ * @param state The current state
+ * @param tag The current tag
* @return A valid transition if any, or null.
*/
public GrammarTransition getTransition( int state, int tag )
{
- return transitions[state][tag & IStates.STATES_SWITCH_MASK];
+ return transitions[state][tag & 0x00FF];
}
@@ -153,10 +110,8 @@
* The main function. This is where an action is executed. If the action is
* null, nothing is done.
*
- * @param container
- * The Asn1Container
- * @throws DecoderException
- * Thrown if anything went wrong
+ * @param container The Asn1Container
+ * @throws DecoderException Thrown if anything went wrong
*/
public void executeAction( IAsn1Container container ) throws DecoderException, NamingException
{
@@ -167,113 +122,39 @@
// We have to deal with the special case of a GRAMMAR_END state
if ( currentState == IStates.END_STATE )
{
- currentState = container.restoreGrammar();
-
- if ( currentState == IStates.END_STATE )
- {
- return;
- }
+ return;
}
- Tag tag = container.getCurrentTLV().getTag();
- byte tagByte = tag.getTagByte();
+ byte tagByte = container.getCurrentTLV().getTag();
// We will loop until no more actions are to be executed
- while ( true )
- {
+ GrammarTransition transition = ( ( AbstractGrammar ) container.getGrammar() ).getTransition( currentState, tagByte );
- GrammarTransition transition = ( ( AbstractGrammar ) container.getGrammar() ).getTransition( currentState,
- tagByte & IStates.STATES_SWITCH_MASK );
+ if ( transition == null )
+ {
- if ( transition == null )
- {
+ String errorMessage = "Bad transition from state "
+ + currentGrammar.getStatesEnum().getState( currentState )
+ + ", tag " + Asn1StringUtils.dumpByte( tagByte );
+
+ log.error( errorMessage );
+
+ // If we have no more grammar on the stack, then this is an
+ // error
+ throw new DecoderException( "Bad transition !" );
+ }
- if ( container.getCurrentGrammar() == 0 )
- {
- String errorMessage = "Bad transition from state "
- + currentGrammar.getStatesEnum().getState( container.getCurrentGrammarType(), currentState )
- + ", tag " + Asn1StringUtils.dumpByte( tag.getTagByte() );
-
- log.error( errorMessage );
-
- // If we have no more grammar on the stack, then this is an
- // error
- throw new DecoderException( "Bad transition !" );
- }
- else
- {
-
- // We have finished with the current grammar, so we have to
- // continue with the
- // previous one, only if allowed
-
- if ( container.isGrammarPopAllowed() )
- {
- if ( IS_DEBUG )
- {
- log.debug( "Pop grammar {}, state = {}", container.getStates().getGrammarName(
- currentGrammar ), currentGrammar.getStatesEnum().getState(
- container.getCurrentGrammarType(), currentState ) );
- }
-
- currentState = container.restoreGrammar();
- container.setTransition( currentState );
- continue;
- }
- else
- {
- String msg = "Cannot pop the grammar " + container.getStates().getGrammarName( currentGrammar )
- + " for state "
- + currentGrammar.getStatesEnum().getState( container.getCurrentGrammarType(), currentState );
- // We can't pop the grammar
- log.error( msg );
- throw new DecoderException( msg );
- }
- }
- }
-
- if ( IS_DEBUG )
- {
- log.debug( transition.toString( container.getCurrentGrammarType(), currentGrammar.getStatesEnum() ) );
- }
-
- int nextState = transition.getNextState();
-
- if ( ( ( nextState & IStates.GRAMMAR_SWITCH_MASK ) != 0 ) && ( nextState != IStates.END_STATE ) )
- {
-
- if ( transition.hasAction() )
- {
- transition.getAction().action( container );
- }
-
- if ( IS_DEBUG )
- {
- log.debug( "Switching from grammar {} to grammar {}", container.getStates().getGrammarName(
- currentGrammar ), container.getStates().getGrammarName( ( nextState >> 8 ) - 1 ) );
- }
-
- // We have a grammar switch, so we change the current state to
- // the initial
- // state in the new grammar and loop.
- container.switchGrammar( currentState, nextState & IStates.GRAMMAR_SWITCH_MASK );
- currentState = IStates.INIT_GRAMMAR_STATE;
- }
- else
- {
-
- // This is not a grammar switch, so we execute the
- // action if we have one, and we quit the loop.
- container.setTransition( nextState );
-
- if ( transition.hasAction() )
- {
- transition.getAction().action( container );
- }
+ if ( IS_DEBUG )
+ {
+ log.debug( transition.toString( currentGrammar.getStatesEnum() ) );
+ }
- break;
- }
+ if ( transition.hasAction() )
+ {
+ transition.getAction().action( container );
}
+
+ container.setTransition( transition.getCurrentState() );
}
@@ -291,8 +172,7 @@
/**
* Set the states for this grammar
*
- * @param statesEnum
- * The statesEnum to set.
+ * @param statesEnum The statesEnum to set.
*/
public void setStatesEnum( IStates statesEnum )
{
Modified: directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/grammar/GrammarAction.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/grammar/GrammarAction.java?view=diff&rev=451834&r1=451833&r2=451834
==============================================================================
--- directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/grammar/GrammarAction.java (original)
+++ directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/grammar/GrammarAction.java Sun Oct 1 15:55:55 2006
@@ -34,17 +34,18 @@
/** The action's name */
protected String name;
+ /** A default constructor */
+ public GrammarAction()
+ {
+ }
- // ~ Constructors
- // -------------------------------------------------------------------------------
/**
* Creates a new GrammarAction object.
*
- * @param name
- * The name of the create daction
+ * @param name The name of the create daction
*/
- public GrammarAction(String name)
+ public GrammarAction( String name )
{
this.name = name;
}
Modified: directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/grammar/GrammarTransition.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/grammar/GrammarTransition.java?view=diff&rev=451834&r1=451833&r2=451834
==============================================================================
--- directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/grammar/GrammarTransition.java (original)
+++ directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/grammar/GrammarTransition.java Sun Oct 1 15:55:55 2006
@@ -20,7 +20,7 @@
package org.apache.directory.shared.asn1.ber.grammar;
-import org.apache.directory.shared.asn1.ber.grammar.GrammarAction;
+import org.apache.directory.shared.asn1.util.Asn1StringUtils;
/**
@@ -31,18 +31,17 @@
*/
public class GrammarTransition
{
- // ~ Instance fields
- // ----------------------------------------------------------------------------
-
- /** The next state in the grammar */
- private int nextState;
-
/** The action associated to the transition */
- private GrammarAction action;
+ private IAction action;
+ /** The previous state */
+ private int previousState;
+
/** The current state */
private int currentState;
+ /** The current tag */
+ private int currentTag;
// ~ Constructors
// -------------------------------------------------------------------------------
@@ -50,33 +49,17 @@
/**
* Creates a new GrammarTransition object.
*
- * @param currentState
- * The current transition
- * @param nextState
- * The target state
- * @param action
- * The action to execute. It could be null.
+ * @param currentState The current transition
+ * @param action The action to execute. It could be null.
*/
- public GrammarTransition(int currentState, int nextState, GrammarAction action)
+ public GrammarTransition( int previousState, int currentState, int currentTag, IAction action )
{
+ this.previousState = previousState;
this.currentState = currentState;
- this.nextState = nextState;
this.action = action;
+ this.currentTag = currentTag;
}
-
- // ~ Methods
- // ------------------------------------------------------------------------------------
-
- /**
- * @return Returns the target state.
- */
- public int getNextState()
- {
- return nextState;
- }
-
-
/**
* Tells if the transition has an associated action.
*
@@ -88,30 +71,44 @@
return action != null;
}
-
/**
* @return Returns the action associated with the transition
*/
- public GrammarAction getAction()
+ public IAction getAction()
{
return action;
}
-
/**
- * @param grammar
- * The grammar which state we want a String from
+ * @param grammar The grammar which state we want a String from
* @return A representation of the transition as a string.
*/
- public String toString( int grammar, IStates statesEnum )
+ public String toString( IStates statesEnum )
{
StringBuffer sb = new StringBuffer();
- sb.append( "Transition from <" ).append( statesEnum.getState( grammar, currentState ) ).append( "> to <" )
- .append( statesEnum.getState( grammar, nextState ) ).append( ">, action : " ).append(
- ( ( action == null ) ? "no action" : action.toString() ) ).append( ">" );
+ sb.append( "Transition from state <" ).append( statesEnum.getState( previousState ) ).append( "> " );
+ sb.append( "to state <" ).append( statesEnum.getState( currentState ) ).append( ">, " );
+ sb.append( "tag <" ).append( Asn1StringUtils.dumpByte( (byte)currentTag ) ).append( ">, " );
+ sb.append( "action : " ).append( ( ( action == null ) ? "no action" : action.toString() ) ).append( ">" );
return sb.toString();
+ }
+
+ /**
+ * @return The current state
+ */
+ public int getCurrentState()
+ {
+ return currentState;
+ }
+
+ /**
+ * @return The previous state
+ */
+ public int getPreviousState()
+ {
+ return previousState;
}
}
Modified: directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/grammar/IStates.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/grammar/IStates.java?view=diff&rev=451834&r1=451833&r2=451834
==============================================================================
--- directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/grammar/IStates.java (original)
+++ directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/grammar/IStates.java Sun Oct 1 15:55:55 2006
@@ -41,20 +41,11 @@
/** The END_STATE */
static int END_STATE = -1;
- /** The mask to filter grammar switch */
- final static int GRAMMAR_SWITCH_MASK = 0xFF00;
-
- /** The mask to filter states transition */
- final static int STATES_SWITCH_MASK = 0x00FF;
-
-
- /** Get the current state for a specified grammar */
- String getState( int grammar, int state );
-
+ /** Get the current state */
+ String getState( int state );
/** Return the grammar name from a grammar */
String getGrammarName( IGrammar grammar );
-
/** Return the grammar name from a grammar number */
String getGrammarName( int grammar );
Modified: directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/TLV.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/TLV.java?view=diff&rev=451834&r1=451833&r2=451834
==============================================================================
--- directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/TLV.java (original)
+++ directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/TLV.java Sun Oct 1 15:55:55 2006
@@ -20,8 +20,7 @@
package org.apache.directory.shared.asn1.ber.tlv;
-import org.apache.directory.shared.asn1.ber.tlv.Length;
-import org.apache.directory.shared.asn1.ber.tlv.Tag;
+import org.apache.directory.shared.asn1.util.Asn1StringUtils;
/**
@@ -38,10 +37,16 @@
// ----------------------------------------------------------------------------
/** The current Tag being processed */
- private Tag tag;
+ private byte tag;
/** The current Length being processed */
- private Length length;
+ private int length;
+
+ /** The number of byte to store the Length being processed */
+ private int lengthNbBytes;
+
+ /** The number of length's bytes currently read */
+ private int LengthBytesRead;
/** The current Value being processed */
private Value value;
@@ -59,17 +64,35 @@
*/
private int expectedLength;
+ /** tag flag for the primitive/constructed bit - 0010 0000 - 0x20 */
+ public static final byte CONSTRUCTED_FLAG = 0x20;
+
+ /** mask to get the type class value */
+ public static final byte TYPE_CLASS_MASK = (byte)0xC0;
+
+ /** value for the universal type class */
+ public static final byte TYPE_CLASS_UNIVERSAL = 0x00;
+
+ /** tag mask for the short tag format - 0001 1111 - 0x1F */
+ public static final int SHORT_MASK = 0x1F;
+
+ /** A mask to get the Length form */
+ public static final transient int LENGTH_LONG_FORM = 0x0080;
- // ~ Constructors
- // -------------------------------------------------------------------------------
+ /** Value of the reserved extension */
+ public static final transient int LENGTH_EXTENSION_RESERVED = 0x7F;
+
+ /** A mask to get the long form value */
+ public static final transient int LENGTH_SHORT_MASK = 0x007F;
/**
* Creates a new TLV object.
*/
public TLV()
{
- tag = new Tag();
- length = new Length();
+ tag = 0;
+ length = 0;
+ lengthNbBytes = 0;
value = new Value();
expectedLength = 0;
@@ -80,49 +103,75 @@
// ------------------------------------------------------------------------------------
/**
- * Reset the TLV, so it can be reused for the next PDU decoding.
+ * Checks to see if the tag is constructed.
+ *
+ * @return true if constructed, false if primitive
*/
- public void reset()
+ public static boolean isConstructed( byte tag )
{
- tag.reset();
- length.reset();
- value.reset();
-
- expectedLength = 0;
+ return ( tag & CONSTRUCTED_FLAG ) != 0;
}
-
/**
- * @return Returns the length.
+ * Checks to see if the current tlv's tag is constructed.
+ *
+ * @return true if constructed, false if primitive
*/
- public Length getLength()
+ public boolean isConstructed()
{
- return length;
+ return ( tag & CONSTRUCTED_FLAG ) != 0;
}
/**
- * Add the TLV Length part
+ * Checks to see if the tag represented by this Tag is primitive or
+ * constructed.
*
- * @param length
- * The length to set.
+ * @return true if it is primitive, false if it is constructed
*/
- public void setLength( Length length )
+ public static boolean isPrimitive( byte tag )
{
- this.length = length;
+ return ( tag & CONSTRUCTED_FLAG ) == 0;
+ }
- expectedLength = length.getLength();
+ /**
+ * Tells if the tag is Universal or not
+ *
+ * @return true if it is primitive, false if it is constructed
+ */
+ public static boolean isUniversal( byte tag )
+ {
+ return ( tag & TYPE_CLASS_MASK ) == TYPE_CLASS_UNIVERSAL;
}
+ /**
+ * Reset the TLV, so it can be reused for the next PDU decoding.
+ */
+ public void reset()
+ {
+ tag = 0;
+ length = 0;
+ lengthNbBytes = 0;
+ value.reset();
+
+ expectedLength = 0;
+ }
/**
* @return Returns the tag.
*/
- public Tag getTag()
+ public byte getTag()
{
return tag;
}
+ /**
+ * @return Returns the tag.
+ */
+ public void setTag( byte tag )
+ {
+ this.tag = tag;
+ }
/**
* @return Returns the value.
@@ -132,7 +181,6 @@
return value;
}
-
/**
* Get a String representation of the TLV
*
@@ -144,8 +192,8 @@
StringBuffer sb = new StringBuffer();
sb.append( "TLV[ " );
- sb.append( tag.toString() ).append( ", " );
- sb.append( length.toString() ).append( ", " );
+ sb.append( Asn1StringUtils.dumpByte( tag ) ).append( ", " );
+ sb.append( length ).append( ", " );
sb.append( value.toString() );
sb.append( "]" );
@@ -161,9 +209,106 @@
*/
public int getSize()
{
- return tag.getSize() + length.getSize() + length.getLength();
+ return 1 + lengthNbBytes + length;
+ }
+
+ /**
+ * Utility function that return the number of bytes necessary to store the
+ * length
+ *
+ * @param length The length to store in a byte array
+ * @return The number of bytes necessary to store the length.
+ */
+ public static int getNbBytes( int length )
+ {
+
+ if ( length >= 0 )
+ {
+
+ if ( length < 128 )
+ {
+ return 1;
+ }
+ else if ( length < 256 )
+ {
+ return 2;
+ }
+ else if ( length < 65536 )
+ {
+ return 3;
+ }
+ else if ( length < 16777216 )
+ {
+ return 4;
+ }
+ else
+ {
+ return 5;
+ }
+ }
+ else
+ {
+ return 5;
+ }
}
+ /**
+ * Utility function that return a byte array representing the length
+ *
+ * @param length The length to store in a byte array
+ * @return The byte array representing the length.
+ */
+ public static byte[] getBytes( int length )
+ {
+
+ byte[] bytes = new byte[getNbBytes( length )];
+
+ if ( length >= 0 )
+ {
+
+ if ( length < 128 )
+ {
+ bytes[0] = ( byte ) length;
+ }
+ else if ( length < 256 )
+ {
+ bytes[0] = ( byte ) 0x81;
+ bytes[1] = ( byte ) length;
+ }
+ else if ( length < 65536 )
+ {
+ bytes[0] = ( byte ) 0x82;
+ bytes[1] = ( byte ) ( length >> 8 );
+ bytes[2] = ( byte ) ( length & 0x00FF );
+ }
+ else if ( length < 16777216 )
+ {
+ bytes[0] = ( byte ) 0x83;
+ bytes[1] = ( byte ) ( length >> 16 );
+ bytes[2] = ( byte ) ( ( length >> 8 ) & 0x00FF );
+ bytes[3] = ( byte ) ( length & 0x00FF );
+ }
+ else
+ {
+ bytes[0] = ( byte ) 0x84;
+ bytes[1] = ( byte ) ( length >> 24 );
+ bytes[2] = ( byte ) ( ( length >> 16 ) & 0x00FF );
+ bytes[3] = ( byte ) ( ( length >> 8 ) & 0x00FF );
+ bytes[4] = ( byte ) ( length & 0x00FF );
+ }
+ }
+ else
+ {
+ bytes[0] = ( byte ) 0x84;
+ bytes[1] = ( byte ) ( length >> 24 );
+ bytes[2] = ( byte ) ( ( length >> 16 ) & 0x00FF );
+ bytes[3] = ( byte ) ( ( length >> 8 ) & 0x00FF );
+ bytes[4] = ( byte ) ( length & 0x00FF );
+ }
+
+ return bytes;
+ }
+
/**
* @return Returns the parent.
@@ -175,8 +320,7 @@
/**
- * @param parent
- * The parent to set.
+ * @param parent The parent to set.
*/
public void setParent( TLV parent )
{
@@ -198,11 +342,52 @@
/**
* Set the new expected length of the current TLV.
*
- * @param expectedLength
- * The expectedLength to set.
+ * @param expectedLength The expectedLength to set.
*/
public void setExpectedLength( int expectedLength )
{
this.expectedLength = expectedLength;
}
+
+
+ public int getLengthNbBytes()
+ {
+ return lengthNbBytes;
+ }
+
+
+ public void setLengthNbBytes( int lengthNbBytes )
+ {
+ this.lengthNbBytes = lengthNbBytes;
+ }
+
+
+ public int getLength()
+ {
+ return length;
+ }
+
+
+ public void setLength( int length )
+ {
+ this.length = length;
+ }
+
+
+ public int getLengthBytesRead()
+ {
+ return LengthBytesRead;
+ }
+
+
+ public void setLengthBytesRead( int lengthBytesRead )
+ {
+ LengthBytesRead = lengthBytesRead;
+ }
+
+ public void incLengthBytesRead()
+ {
+ LengthBytesRead++;
+ }
}
+
\ No newline at end of file
Modified: directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java?view=diff&rev=451834&r1=451833&r2=451834
==============================================================================
--- directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java (original)
+++ directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java Sun Oct 1 15:55:55 2006
@@ -20,7 +20,6 @@
package org.apache.directory.shared.asn1.ber.tlv;
-import org.apache.directory.shared.asn1.ber.tlv.Length;
import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
import org.apache.directory.shared.asn1.codec.EncoderException;
import org.apache.directory.shared.asn1.primitives.OID;
@@ -108,8 +107,7 @@
/**
* Initialize the Value
*
- * @param size
- * The data size to allocate.
+ * @param size The data size to allocate.
*/
public void init( int size )
{
@@ -132,8 +130,7 @@
* Clone the Value
*
* @return An object that is a copy of this Value
- * @throws CloneNotSupportedException
- * Thrown when the cloning failed
+ * @throws CloneNotSupportedException Thrown when the cloning failed
*/
public Object clone() throws CloneNotSupportedException
{
@@ -156,8 +153,7 @@
/**
* Set a block of bytes in the Value
*
- * @param data
- * The data to set.
+ * @param data The data to set.
*/
public void setData( ByteBuffer data )
{
@@ -170,8 +166,7 @@
/**
* Append some bytes to the data buffer.
*
- * @param data
- * The data to append.
+ * @param data The data to append.
*/
public void addData( ByteBuffer data )
{
@@ -184,8 +179,7 @@
/**
* Set a block of bytes in the Value
*
- * @param data
- * The data to set.
+ * @param data The data to set.
*/
public void setData( byte[] data )
{
@@ -197,8 +191,7 @@
/**
* Append some bytes to the data buffer.
*
- * @param data
- * The data to append.
+ * @param data The data to append.
*/
public void addData( byte[] data )
{
@@ -221,10 +214,8 @@
* integer value. Note that this value must be in [Integer.MIN_VALUE,
* Integer.MAX_VALUE].
*
- * @param value
- * The value to store in a byte array
- * @param sign
- * The integer value sign
+ * @param value The value to store in a byte array
+ * @param sign The integer value sign
* @return The number of bytes necessary to store the value.
*/
public static int getNbBytes( int value )
@@ -254,17 +245,20 @@
/**
* Utility function that return a byte array representing the Value We must
- * respect the ASN.1 BER encoding scheme : 1) positive integer - [0 - 0x7F] :
- * 0xVV - [0x80 - 0xFF] : 0x00 0xVV - [0x0100 - 0x7FFF] : 0xVV 0xVV -
- * [0x8000 - 0xFFFF] : 0x00 0xVV 0xVV - [0x010000 - 0x7FFFFF] : 0xVV 0xVV
- * 0xVV - [0x800000 - 0xFFFFFF] : 0x00 0xVV 0xVV 0xVV - [0x01000000 -
- * 0x7FFFFFFF] : 0xVV 0xVV 0xVV 0xVV - [0x80000000 - 0xFFFFFFFF] : 0x00 0xVV
- * 0xVV 0xVV 0xVV 2) Negative number - (~value) + 1
- *
- * @param value
- * The value to store in a byte array
- * @param sign
- * The value sign : positive or negative
+ * respect the ASN.1 BER encoding scheme :
+ * 1) positive integer
+ * - [0 - 0x7F] : 0xVV
+ * - [0x80 - 0xFF] : 0x00 0xVV
+ * - [0x0100 - 0x7FFF] : 0xVV 0xVV
+ * - [0x8000 - 0xFFFF] : 0x00 0xVV 0xVV
+ * - [0x010000 - 0x7FFFFF] : 0xVV 0xVV 0xVV
+ * - [0x800000 - 0xFFFFFF] : 0x00 0xVV 0xVV 0xVV
+ * - [0x01000000 - 0x7FFFFFFF] : 0xVV 0xVV 0xVV 0xVV
+ * - [0x80000000 - 0xFFFFFFFF] : 0x00 0xVV 0xVV 0xVV 0xVV
+ * 2) Negative number - (~value) + 1
+ *
+ * @param value The value to store in a byte array
+ * @param sign The value sign : positive or negative
* @return The byte array representing the value.
*/
public static byte[] getBytes( int value )
@@ -305,10 +299,8 @@
/**
* Encode a String value
*
- * @param buffer
- * The PDU in which the value will be put
- * @param string
- * The String to be encoded. It is supposed to be UTF-8
+ * @param buffer The PDU in which the value will be put
+ * @param string The String to be encoded. It is supposed to be UTF-8
*/
public static void encode( ByteBuffer buffer, String string ) throws EncoderException
{
@@ -323,7 +315,7 @@
byte[] value = Asn1StringUtils.getBytesUtf8( string );
- buffer.put( Length.getBytes( value.length ) );
+ buffer.put( TLV.getBytes( value.length ) );
if ( value.length != 0 )
{
@@ -342,10 +334,8 @@
/**
* Encode an OctetString value
*
- * @param buffer
- * The PDU in which the value will be put
- * @param byte[]
- * The bytes to be encoded
+ * @param buffer The PDU in which the value will be put
+ * @param byte[] The bytes to be encoded
*/
public static void encode( ByteBuffer buffer, byte[] bytes ) throws EncoderException
{
@@ -364,7 +354,7 @@
}
else
{
- buffer.put( Length.getBytes( bytes.length ) );
+ buffer.put( TLV.getBytes( bytes.length ) );
buffer.put( bytes );
}
}
@@ -380,10 +370,8 @@
/**
* Encode an OID value
*
- * @param buffer
- * The PDU in which the value will be put
- * @param string
- * The OID to be encoded
+ * @param buffer The PDU in which the value will be put
+ * @param string The OID to be encoded
*/
public static void encode( ByteBuffer buffer, OID oid ) throws EncoderException
{
@@ -395,7 +383,7 @@
try
{
buffer.put( UniversalTag.OCTET_STRING_TAG );
- buffer.put( Length.getBytes( oid.getOIDLength() ) );
+ buffer.put( TLV.getBytes( oid.getOIDLength() ) );
if ( oid.getOIDLength() != 0 )
{
@@ -414,10 +402,8 @@
/**
* Encode an integer value
*
- * @param buffer
- * The PDU in which the value will be put
- * @param value
- * The integer to be encoded
+ * @param buffer The PDU in which the value will be put
+ * @param value The integer to be encoded
*/
public static void encode( ByteBuffer buffer, int value ) throws EncoderException
{
@@ -444,12 +430,9 @@
/**
* Encode an integer value
*
- * @param buffer
- * The PDU in which the value will be put
- * @param tag
- * The tag if it's not an UNIVERSAL one
- * @param value
- * The integer to be encoded
+ * @param buffer The PDU in which the value will be put
+ * @param tag The tag if it's not an UNIVERSAL one
+ * @param value The integer to be encoded
*/
public static void encode( ByteBuffer buffer, byte tag, int value ) throws EncoderException
{
@@ -476,10 +459,8 @@
/**
* Encode an enumerated value
*
- * @param buffer
- * The PDU in which the value will be put
- * @param value
- * The integer to be encoded
+ * @param buffer The PDU in which the value will be put
+ * @param value The integer to be encoded
*/
public static void encodeEnumerated( ByteBuffer buffer, int value ) throws EncoderException
{
@@ -491,7 +472,7 @@
try
{
buffer.put( UniversalTag.ENUMERATED_TAG );
- buffer.put( Length.getBytes( getNbBytes( value ) ) );
+ buffer.put( TLV.getBytes( getNbBytes( value ) ) );
buffer.put( getBytes( value ) );
}
catch ( BufferOverflowException boe )
@@ -506,10 +487,8 @@
/**
* Encode a boolean value
*
- * @param buffer
- * The PDU in which the value will be put
- * @param bool
- * The boolean to be encoded
+ * @param buffer The PDU in which the value will be put
+ * @param bool The boolean to be encoded
*/
public static void encode( ByteBuffer buffer, boolean bool ) throws EncoderException
{
Modified: directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/primitives/OID.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/primitives/OID.java?view=diff&rev=451834&r1=451833&r2=451834
==============================================================================
--- directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/primitives/OID.java (original)
+++ directory/branches/shared/0.9.5/asn1/src/main/java/org/apache/directory/shared/asn1/primitives/OID.java Sun Oct 1 15:55:55 2006
@@ -26,19 +26,31 @@
/**
- * This class implement an OID (Object Identifier). An OID is encoded as a list
- * of bytes representing integers. An OID has a numeric representation where
- * number are separated with dots : SPNEGO Oid = 1.3.6.1.5.5.2 Translating from
- * a byte list to a dot separated list of number follows the rules : - the first
- * number is in [0..2] - the second number is in [0..39] if the first number is
- * 0 or 1 - the first byte has a value equal to : number 1 * 40 + number two -
- * the upper bit of a byte is set if the next byte is a part of the number For
- * instance, the SPNEGO Oid (1.3.6.1.5.5.2) will be encoded : 1.3 -> 0x2B (1*40 +
- * 3 = 43 = 0x2B) .6 -> 0x06 .1 -> 0x01 .5 -> 0x05 .5 -> 0x05 .2 -> 0x02 The
- * Kerberos V5 Oid (1.2.840.48018.1.2.2) will be encoded : 1.2 -> 0x2A (1*40 + 2 =
- * 42 = 0x2A) 840 -> 0x86 0x48 (840 = 6 * 128 + 72 = (0x06 | 0x80) 0x48 = 0x86
- * 0x48 48018 -> 0x82 0xF7 0x12 (2 * 128 * 128 + 119 * 128 + 18 = (0x02 | 0x80)
- * (0x77 | 0x80) 0x12
+ * This class implement an OID (Object Identifier).
+ *
+ * An OID is encoded as a list of bytes representing integers.
+ *
+ * An OID has a numeric representation where number are separated with dots :
+ * SPNEGO Oid = 1.3.6.1.5.5.2
+ *
+ * Translating from a byte list to a dot separated list of number follows the rules :
+ * - the first number is in [0..2]
+ * - the second number is in [0..39] if the first number is 0 or 1
+ * - the first byte has a value equal to : number 1 * 40 + number two
+ * - the upper bit of a byte is set if the next byte is a part of the number
+ *
+ * For instance, the SPNEGO Oid (1.3.6.1.5.5.2) will be encoded :
+ * 1.3 -> 0x2B (1*40 + 3 = 43 = 0x2B)
+ * .6 -> 0x06
+ * .1 -> 0x01
+ * .5 -> 0x05
+ * .5 -> 0x05
+ * .2 -> 0x02
+ *
+ * The Kerberos V5 Oid (1.2.840.48018.1.2.2) will be encoded :
+ * 1.2 -> 0x2A (1*40 + 2 = 42 = 0x2A)
+ * 840 -> 0x86 0x48 (840 = 6 * 128 + 72 = (0x06 | 0x80) 0x48 = 0x86 0x48
+ * 48018 -> 0x82 0xF7 0x12 (2 * 128 * 128 + 119 * 128 + 18 = (0x02 | 0x80) (0x77 | 0x80) 0x12
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
@@ -81,8 +93,7 @@
/**
* Create a new OID object from a String
*
- * @param oid
- * The String which is supposed to be an OID
+ * @param oid The String which is supposed to be an OID
*/
public OID(String oid) throws DecoderException
{
@@ -96,8 +107,7 @@
* Set the OID. It will be translated from a byte array to an internal
* representation.
*
- * @param oid
- * The bytes containing the OID
+ * @param oid The bytes containing the OID
*/
public void setOID( byte[] oid ) throws DecoderException
{
@@ -189,11 +199,12 @@
/**
* Set the OID. It will be translated from a String to an internal
- * representation. The syntax will be controled in respect with this rule :
+ * representation.
+ *
+ * The syntax will be controled in respect with this rule :
* OID = ( [ '0' | '1' ] '.' [ 0 .. 39 ] | '2' '.' int) ( '.' int )*
*
- * @param oid
- * The String containing the OID
+ * @param oid The String containing the OID
*/
public void setOID( String oid ) throws DecoderException
{
@@ -204,7 +215,7 @@
}
int nbValues = 1;
- byte[] bytes = oid.getBytes();
+ char[] bytes = oid.toCharArray();
boolean dotSeen = false;
// Count the number of int to allocate.
@@ -503,7 +514,11 @@
return sb.toString();
}
-
+ /**
+ * Check that an OID is valid
+ * @param oid The oid to be checked
+ * @return <code>true</code> if the OID is valid
+ */
public static boolean isOID( String oid )
{
if ( ( oid == null ) || ( oid.length() == 0 ) )
Modified: directory/branches/shared/0.9.5/asn1/src/test/java/org/apache/directory/shared/asn1/ber/tlv/LengthTest.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/asn1/src/test/java/org/apache/directory/shared/asn1/ber/tlv/LengthTest.java?view=diff&rev=451834&r1=451833&r2=451834
==============================================================================
--- directory/branches/shared/0.9.5/asn1/src/test/java/org/apache/directory/shared/asn1/ber/tlv/LengthTest.java (original)
+++ directory/branches/shared/0.9.5/asn1/src/test/java/org/apache/directory/shared/asn1/ber/tlv/LengthTest.java Sun Oct 1 15:55:55 2006
@@ -25,9 +25,6 @@
import junit.framework.Assert;
import junit.framework.TestCase;
-import org.apache.directory.shared.asn1.ber.tlv.Length;
-
-
/**
* This class is used to test the Length class
*
@@ -41,17 +38,17 @@
*/
public void testLengthGetNbBytes()
{
- Assert.assertEquals( 1, Length.getNbBytes( 0 ) );
- Assert.assertEquals( 1, Length.getNbBytes( 1 ) );
- Assert.assertEquals( 1, Length.getNbBytes( 127 ) );
- Assert.assertEquals( 2, Length.getNbBytes( 128 ) );
- Assert.assertEquals( 2, Length.getNbBytes( 255 ) );
- Assert.assertEquals( 3, Length.getNbBytes( 256 ) );
- Assert.assertEquals( 3, Length.getNbBytes( 65535 ) );
- Assert.assertEquals( 4, Length.getNbBytes( 65536 ) );
- Assert.assertEquals( 4, Length.getNbBytes( 16777215 ) );
- Assert.assertEquals( 5, Length.getNbBytes( 16777216 ) );
- Assert.assertEquals( 5, Length.getNbBytes( 0xFFFFFFFF ) );
+ Assert.assertEquals( 1, TLV.getNbBytes( 0 ) );
+ Assert.assertEquals( 1, TLV.getNbBytes( 1 ) );
+ Assert.assertEquals( 1, TLV.getNbBytes( 127 ) );
+ Assert.assertEquals( 2, TLV.getNbBytes( 128 ) );
+ Assert.assertEquals( 2, TLV.getNbBytes( 255 ) );
+ Assert.assertEquals( 3, TLV.getNbBytes( 256 ) );
+ Assert.assertEquals( 3, TLV.getNbBytes( 65535 ) );
+ Assert.assertEquals( 4, TLV.getNbBytes( 65536 ) );
+ Assert.assertEquals( 4, TLV.getNbBytes( 16777215 ) );
+ Assert.assertEquals( 5, TLV.getNbBytes( 16777216 ) );
+ Assert.assertEquals( 5, TLV.getNbBytes( 0xFFFFFFFF ) );
}
@@ -61,26 +58,26 @@
public void testLengthGetBytes()
{
assertTrue( Arrays.equals( new byte[]
- { 0x01 }, Length.getBytes( 1 ) ) );
+ { 0x01 }, TLV.getBytes( 1 ) ) );
assertTrue( Arrays.equals( new byte[]
- { 0x7F }, Length.getBytes( 127 ) ) );
+ { 0x7F }, TLV.getBytes( 127 ) ) );
assertTrue( Arrays.equals( new byte[]
- { ( byte ) 0x81, ( byte ) 0x80 }, Length.getBytes( 128 ) ) );
+ { ( byte ) 0x81, ( byte ) 0x80 }, TLV.getBytes( 128 ) ) );
assertTrue( Arrays.equals( new byte[]
- { ( byte ) 0x81, ( byte ) 0xFF }, Length.getBytes( 255 ) ) );
+ { ( byte ) 0x81, ( byte ) 0xFF }, TLV.getBytes( 255 ) ) );
assertTrue( Arrays.equals( new byte[]
- { ( byte ) 0x82, 0x01, 0x00 }, Length.getBytes( 256 ) ) );
+ { ( byte ) 0x82, 0x01, 0x00 }, TLV.getBytes( 256 ) ) );
assertTrue( Arrays.equals( new byte[]
- { ( byte ) 0x82, ( byte ) 0xFF, ( byte ) 0xFF }, Length.getBytes( 65535 ) ) );
+ { ( byte ) 0x82, ( byte ) 0xFF, ( byte ) 0xFF }, TLV.getBytes( 65535 ) ) );
assertTrue( Arrays.equals( new byte[]
- { ( byte ) 0x83, 0x01, 0x00, 0x00 }, Length.getBytes( 65536 ) ) );
+ { ( byte ) 0x83, 0x01, 0x00, 0x00 }, TLV.getBytes( 65536 ) ) );
assertTrue( Arrays.equals( new byte[]
- { ( byte ) 0x83, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF }, Length.getBytes( 16777215 ) ) );
+ { ( byte ) 0x83, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF }, TLV.getBytes( 16777215 ) ) );
assertTrue( Arrays.equals( new byte[]
- { ( byte ) 0x84, 0x01, 0x00, 0x00, 0x00 }, Length.getBytes( 16777216 ) ) );
+ { ( byte ) 0x84, 0x01, 0x00, 0x00, 0x00 }, TLV.getBytes( 16777216 ) ) );
assertTrue( Arrays
.equals( new byte[]
- { ( byte ) 0x84, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF }, Length
+ { ( byte ) 0x84, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF }, TLV
.getBytes( 0xFFFFFFFF ) ) );
}
}