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 2005/09/09 22:17:49 UTC
svn commit: r279865 [1/3] - in
/directory/asn1/branches/elecharny-cleanup/ber-new: ./ src/ src/java/
src/java/main/ src/java/main/org/ src/java/main/org/apache/
src/java/main/org/apache/asn1new/ src/java/main/org/apache/asn1new/ber/
src/java/main/org/a...
Author: elecharny
Date: Fri Sep 9 13:17:27 2005
New Revision: 279865
URL: http://svn.apache.org/viewcvs?rev=279865&view=rev
Log:
added
Added:
directory/asn1/branches/elecharny-cleanup/ber-new/
directory/asn1/branches/elecharny-cleanup/ber-new/maven.xml
directory/asn1/branches/elecharny-cleanup/ber-new/project.properties
directory/asn1/branches/elecharny-cleanup/ber-new/project.xml
directory/asn1/branches/elecharny-cleanup/ber-new/src/
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/Asn1Object.java
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/AbstractContainer.java
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/Asn1Decoder.java
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/containers/
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/containers/IAsn1Container.java
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/AbstractGrammar.java
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/GrammarAction.java
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/GrammarTransition.java
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/IAction.java
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/IGrammar.java
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/IStates.java
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/tlv/
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/tlv/ITLVBerDecoderMBean.java
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/tlv/Length.java
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/tlv/TLV.java
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/tlv/TLVStateEnum.java
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/tlv/Tag.java
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/tlv/UniversalTag.java
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/tlv/Value.java
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/primitives/
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/primitives/BitString.java
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/primitives/OID.java
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/primitives/OctetString.java
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/util/
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/util/IntegerDecoder.java
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/util/MutableString.java
directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/util/StringUtils.java
directory/asn1/branches/elecharny-cleanup/ber-new/src/test/
directory/asn1/branches/elecharny-cleanup/ber-new/src/test/org/
directory/asn1/branches/elecharny-cleanup/ber-new/src/test/org/apache/
directory/asn1/branches/elecharny-cleanup/ber-new/src/test/org/apache/asn1new/
directory/asn1/branches/elecharny-cleanup/ber-new/src/test/org/apache/asn1new/ber/
directory/asn1/branches/elecharny-cleanup/ber-new/src/test/org/apache/asn1new/ber/tlv/
directory/asn1/branches/elecharny-cleanup/ber-new/src/test/org/apache/asn1new/ber/tlv/LengthTest.java
directory/asn1/branches/elecharny-cleanup/ber-new/src/test/org/apache/asn1new/primitives/
directory/asn1/branches/elecharny-cleanup/ber-new/src/test/org/apache/asn1new/primitives/BitStringTest.java
directory/asn1/branches/elecharny-cleanup/ber-new/src/test/org/apache/asn1new/primitives/OIDTest.java
directory/asn1/branches/elecharny-cleanup/ber-new/src/test/org/apache/asn1new/primitives/PrimitivesTest.java
directory/asn1/branches/elecharny-cleanup/ber-new/src/test/org/apache/asn1new/util/
directory/asn1/branches/elecharny-cleanup/ber-new/src/test/org/apache/asn1new/util/MutableStringTest.java
directory/asn1/branches/elecharny-cleanup/ber-new/src/test/org/apache/asn1new/util/StringUtilsTest.java
directory/asn1/branches/elecharny-cleanup/ber-new/todo.txt
Added: directory/asn1/branches/elecharny-cleanup/ber-new/maven.xml
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/elecharny-cleanup/ber-new/maven.xml?rev=279865&view=auto
==============================================================================
--- directory/asn1/branches/elecharny-cleanup/ber-new/maven.xml (added)
+++ directory/asn1/branches/elecharny-cleanup/ber-new/maven.xml Fri Sep 9 13:17:27 2005
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<project
+ default="jar:install"
+ >
+
+</project>
Added: directory/asn1/branches/elecharny-cleanup/ber-new/project.properties
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/elecharny-cleanup/ber-new/project.properties?rev=279865&view=auto
==============================================================================
--- directory/asn1/branches/elecharny-cleanup/ber-new/project.properties (added)
+++ directory/asn1/branches/elecharny-cleanup/ber-new/project.properties Fri Sep 9 13:17:27 2005
@@ -0,0 +1,20 @@
+maven.javadoc.private=true
+maven.javadoc.customtags=tag1 tag2
+
+tag1.name=todo
+tag1.description=To Do:
+tag1.enabled=true
+tag1.scope=all
+
+tag2.name=task
+tag2.description=Task:
+tag2.enabled=false
+tag2.scope=all
+
+maven.license.licenseFile=../../../LICENSE.txt
+#maven.clover.instrument.tests=true
+#maven.junit.fork=true
+maven.xdoc.includeProjectDocumentation=yes
+
+#maven.repo.remote=http://cvs.apache.org/repository, http://ibiblio.org/maven, http://ldapd.sourceforge.net/maven/repository
+
Added: directory/asn1/branches/elecharny-cleanup/ber-new/project.xml
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/elecharny-cleanup/ber-new/project.xml?rev=279865&view=auto
==============================================================================
--- directory/asn1/branches/elecharny-cleanup/ber-new/project.xml (added)
+++ directory/asn1/branches/elecharny-cleanup/ber-new/project.xml Fri Sep 9 13:17:27 2005
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
+ <extend>${basedir}/../project.xml</extend>
+ <pomVersion>1</pomVersion>
+ <artifactId>asn1-new-ber</artifactId>
+ <developers>
+ <developer>
+ <name>Emmanuel Lécharny</name>
+ <id>elecharny</id>
+ <email>elecharny at apache.org</email>
+ </developer>
+ </developers>
+ <build>
+ <sourceDirectory>${basedir}/src/java/main</sourceDirectory>
+ </build>
+ <name>ASN.1 new BER Runtime</name>
+ <package>org.apache.asn1new</package>
+ <inceptionYear>2005</inceptionYear>
+ <shortDescription>ASN.1 new BER Runtime</shortDescription>
+ <description>A new BER implementation</description>
+
+ <dependencies>
+ <!-- deps in group -->
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>asn1-codec</artifactId>
+ <version>${pom.currentVersion}</version>
+ </dependency>
+ </dependencies>
+</project>
+
Added: directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/Asn1Object.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/Asn1Object.java?rev=279865&view=auto
==============================================================================
--- directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/Asn1Object.java (added)
+++ directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/Asn1Object.java Fri Sep 9 13:17:27 2005
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.asn1new;
+
+import java.nio.ByteBuffer;
+
+import org.apache.asn1.codec.DecoderException;
+import org.apache.asn1.codec.EncoderException;
+
+
+/**
+ * An abstract class which implements basic TLV operations.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public abstract class Asn1Object
+{
+ //~ Instance fields ----------------------------------------------------------------------------
+
+ /** The object's current length. It is used while decoding PDUs */
+ private transient int currentLength;
+
+ /** The object's expected length. It is used while decoding PDUs */
+ private transient int expectedLength;
+
+ /** The encapsulating Object */
+ protected transient Asn1Object parent;
+
+ //~ Methods ------------------------------------------------------------------------------------
+
+ /**
+ * Get the current object length, which is the sum of all inner length
+ * already decoded.
+ *
+ * @return The current object's length
+ */
+ public int getCurrentLength()
+ {
+ return currentLength;
+ }
+
+ /**
+ * Compute the object length, which is the sum of all inner length.
+ *
+ * @return The object's computed length
+ */
+ public abstract int computeLength();
+
+ /**
+ * Encode the object to a PDU.
+ *
+ * @param buffer The buffer where to put the PDU
+ * @return The PDU.
+ */
+ public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException {
+ return null;
+ }
+
+ /**
+ * Get the expected object length.
+ *
+ * @return The expected object's length
+ */
+ public int getExpectedLength()
+ {
+ return expectedLength;
+ }
+
+ /**
+ * Add a length to the object
+ *
+ * @param length The length to add.
+ * @throws DecoderException Thrown if the current length exceed the expected length
+ */
+ public void addLength( int length ) throws DecoderException
+ {
+ currentLength += length;
+
+ if ( currentLength > expectedLength )
+ {
+ throw new DecoderException( "Current Length is above expected Length" );
+ }
+ }
+
+ /**
+ * Set the expected length
+ *
+ * @param expectedLength The expectedLength to set.
+ */
+ public void setExpectedLength( int expectedLength )
+ {
+ this.expectedLength = expectedLength;
+ }
+
+ /**
+ * Set the current length
+ *
+ * @param currentLength The currentLength to set.
+ */
+ public void setCurrentLength( int currentLength )
+ {
+ this.currentLength = currentLength;
+ }
+
+ /**
+ * Get the parent
+ *
+ * @return Returns the parent.
+ */
+ public Asn1Object getParent()
+ {
+ return parent;
+ }
+
+ /**
+ * Set the parent
+ *
+ * @param parent The parent to set.
+ */
+ public void setParent( Asn1Object parent )
+ {
+ this.parent = parent;
+ }
+}
Added: directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/AbstractContainer.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/AbstractContainer.java?rev=279865&view=auto
==============================================================================
--- directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/AbstractContainer.java (added)
+++ directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/AbstractContainer.java Fri Sep 9 13:17:27 2005
@@ -0,0 +1,269 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.asn1new.ber;
+
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ber.grammar.IGrammar;
+import org.apache.asn1new.ber.grammar.IStates;
+import org.apache.asn1new.ber.tlv.TLV;
+import org.apache.asn1new.ber.tlv.TLVStateEnum;
+
+
+/**
+ * This class is the abstract container used to store the current state
+ * of a PDU being decoded. It also stores the grammars used to decode
+ * the PDU, and zll the informations needed to decode a PDU.
+ *
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AbstractContainer implements IAsn1Container
+{
+ //~ 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;
+
+ /** Store a stack of the current states used when switching grammars */
+ protected int[] stateStack;
+
+ /** The number of stored grammars */
+ protected int nbGrammars;
+
+ /** The current grammar */
+ protected int currentGrammar;
+
+ /** The current state of the decoding */
+ protected int state;
+
+ /** The current transition */
+ protected int transition;
+
+ /** The current TLV */
+ protected TLV tlv;
+
+ /** Store the different states for debug purpose */
+ protected IStates states;
+
+ /** The parent TLV */
+ protected TLV parentTLV;
+
+ //~ Methods ------------------------------------------------------------------------------------
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return Returns the grammar used to decode a LdapMessage.
+ */
+ 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 DOCUMENT ME!
+ * @param grammar The grammar to add.
+ */
+ public void switchGrammar( int currentState, int grammar )
+ {
+ stateStack[currentGrammar] = currentState;
+ currentGrammar++;
+ 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;
+ currentGrammar--;
+
+ if ( currentGrammar >= 0 )
+ {
+ return stateStack[currentGrammar];
+ }
+ else
+ {
+ return -1;
+ }
+
+ }
+
+ /**
+ * Get the current grammar state
+ *
+ * @return Returns the current grammar state
+ */
+ public int getState()
+ {
+ return state;
+ }
+
+ /**
+ * Set the new current state
+ *
+ * @param state The new state
+ */
+ public void setState( int state )
+ {
+ this.state = state;
+ }
+
+ /**
+ * Get the transition
+ *
+ * @return Returns the transition from the previous state to the new
+ * state
+ */
+ public int getTransition()
+ {
+ return transition;
+ }
+
+ /**
+ * Update the transition from a state to another
+ *
+ * @param transition The transition to set
+ */
+ public void setTransition( int transition )
+ {
+ this.transition = transition;
+ }
+
+ /**
+ * 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
+ */
+ public void setCurrentTLV( TLV tlv )
+ {
+ this.tlv = tlv;
+ }
+
+ /**
+ * Get the current TLV
+ *
+ * @return Returns the current TLV being decoded
+ */
+ public TLV getCurrentTLV()
+ {
+ return this.tlv;
+ }
+
+ /**
+ * Get the states for this container's grammars
+ *
+ * @return Returns the states.
+ */
+ public IStates getStates() {
+ return states;
+ }
+
+ /**
+ * Get the parent TLV;
+ *
+ * @return Returns the parent TLV, if any.
+ */
+ public TLV getParentTLV()
+ {
+ return parentTLV;
+ }
+
+ /**
+ * Set the parent TLV.
+ *
+ * @param The parent TLV to set.
+ */
+ public void setParentTLV(TLV parentTLV)
+ {
+ this.parentTLV = parentTLV;
+ }
+
+ /**
+ * Clean the container for the next usage.
+ *
+ */
+ public void clean()
+ {
+ currentGrammar = 0;
+ tlv = null;
+ parentTLV = null;
+ transition = 0;
+ state = TLVStateEnum.TAG_STATE_START;
+ }
+}
Added: directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/Asn1Decoder.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/Asn1Decoder.java?rev=279865&view=auto
==============================================================================
--- directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/Asn1Decoder.java (added)
+++ directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/Asn1Decoder.java Fri Sep 9 13:17:27 2005
@@ -0,0 +1,998 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.asn1new.ber;
+
+
+import org.apache.asn1.codec.DecoderException;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ber.tlv.Length;
+import org.apache.asn1new.ber.tlv.TLV;
+import org.apache.asn1new.ber.tlv.ITLVBerDecoderMBean;
+import org.apache.asn1new.ber.tlv.TLVStateEnum;
+import org.apache.asn1new.ber.tlv.Tag;
+import org.apache.asn1new.ber.tlv.UniversalTag;
+import org.apache.asn1new.ber.tlv.Value;
+import org.apache.asn1new.util.StringUtils;
+
+import org.apache.log4j.Logger;
+
+import java.nio.ByteBuffer;
+
+
+/**
+ * A BER TLV Tag component decoder. This decoder instanciate 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 <a href="mailto:dev@directory.apache.org">Apache
+ * Directory Project</a>
+ */
+public class Asn1Decoder implements ITLVBerDecoderMBean
+{
+ //~ Static fields/initializers -----------------------------------------------------------------
+
+ /** The logger */
+ private static final Logger log = Logger.getLogger( Asn1Decoder.class );
+
+ /** A speedup for logs */
+ private static boolean DEBUG;
+
+ /** This flag is used to indicate that there are more bytes in the stream */
+ private static final boolean MORE = true;
+
+ /** This flag is used to indicate that there are no more bytes in the stream */
+ private static final boolean END = false;
+
+ //~ Instance fields ----------------------------------------------------------------------------
+
+ /** Flag that is used to allow/disallow the indefinite form of Length */
+ private boolean indefiniteLengthAllowed;
+
+ /** The maximum number of bytes that could be used to encode the Length */
+ private int maxLengthLength;
+
+ /** The maximum number of bytes that could be used to encode the Tag */
+ private int maxTagLength;
+
+ //~ Constructors -------------------------------------------------------------------------------
+
+ /**
+ * A public constructor of an Asn1 Decoder.
+ */
+ public Asn1Decoder()
+ {
+ indefiniteLengthAllowed = false;
+ maxLengthLength = 1;
+ maxTagLength = 1;
+ DEBUG = log.isDebugEnabled();
+ }
+
+ //~ Methods ------------------------------------------------------------------------------------
+
+ /**
+ * 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.
+ *
+ * @return <code>true</code> if there are more bytes to read, <code>false
+ * </code> otherwise
+ *
+ * @throws DecoderException If something went wrong.
+ */
+ private boolean treatTagStartState( ByteBuffer stream, IAsn1Container container )
+ throws DecoderException
+ {
+
+ if ( stream.hasRemaining() )
+ {
+
+ byte octet = stream.get();
+
+ TLV tlv = new TLV();
+ Tag tag = tlv.getTag();
+
+ tag.setSize( 1 );
+ tag.setPrimitive( ( octet & Tag.CONSTRUCTED_FLAG ) == 0 );
+ tag.setTypeClass( Tag.TYPE_CLASS[( octet & Tag.TYPE_CLASS_MASK ) >>> 6] );
+
+ int value = octet & Tag.SHORT_MASK;
+
+ if ( value == Tag.SHORT_MASK )
+ {
+
+ // we have to check the typeClass. UNIVERSAL class is not
+ // allowed with this value.
+ if ( tag.isUniversal() )
+ {
+ throw new DecoderException( "Universal tag 31 is reserved" );
+ }
+
+ // 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() )
+ {
+
+ if ( ( value == UniversalTag.RESERVED_14 ) || ( value == UniversalTag.RESERVED_15 ) )
+ {
+ throw new DecoderException( "Universal tag " + value + " is reserved" );
+ }
+ }
+
+ 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
+ {
+
+ // The stream has been exhausted
+ return END;
+ }
+ }
+
+ /**
+ * 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
+ */
+ private void dumpTLVTree( IAsn1Container container )
+ {
+ StringBuffer sb = new StringBuffer();
+ TLV current = container.getCurrentTLV();
+
+ sb.append("TLV").
+ append(StringUtils.dumpByte(current.getTag().getTagBytes()[0])).
+ append("(").
+ append(current.getExpectedLength()).
+ append(")");
+
+ current = current.getParent();
+
+ while (current != null)
+ {
+ sb.append("-TLV").
+ append(StringUtils.dumpByte(current.getTag().getTagBytes()[0])).
+ append("(").
+ append(current.getExpectedLength()).
+ append(")");
+ current = current.getParent();
+ }
+
+ log.debug("TLV Tree : " + sb.toString());
+ }
+
+ /**
+ * Check if the TLV tree is fully decoded
+ * @param container The container
+ */
+ private boolean isTLVDecoded( IAsn1Container container )
+ {
+ TLV current = container.getCurrentTLV();
+
+ TLV parent = current.getParent();
+
+ while (parent != null)
+ {
+ if (parent.getExpectedLength() != 0)
+ {
+ return false;
+ }
+
+ parent = parent.getParent();
+ }
+
+ Value value = current.getValue();
+
+ if ( (value != null) && (value.getData() != null) )
+ {
+ return (current.getExpectedLength() == value.getData().length);
+ }
+ else
+ {
+ return current.getExpectedLength() == 0;
+ }
+ }
+
+ /**
+ * 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
+ {
+
+ if ( DEBUG )
+ {
+ Tag tag = container.getCurrentTLV().getTag();
+ log.debug( tag.toString() + " has been decoded" );
+ }
+
+ // 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.
+ *
+ * @return <code>true</code> if there are more bytes to read, <code>false
+ * </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();
+
+ Length length = container.getCurrentTLV().getLength();
+
+ if ( ( octet & Length.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 );
+
+ container.setState( TLVStateEnum.LENGTH_STATE_END );
+ }
+ else if ( ( octet & Length.LENGTH_EXTENSION_RESERVED ) !=
+ Length.LENGTH_EXTENSION_RESERVED )
+ {
+
+ int expectedLength = octet & Length.SHORT_MASK;
+
+ if ( expectedLength > 4 )
+ {
+ log.error( "Overflow : can't have more than 4 bytes long length" );
+ 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 );
+ container.setState( TLVStateEnum.LENGTH_STATE_PENDING );
+ }
+ else
+ {
+ log.error( "Length reserved extension used" );
+ throw new DecoderException( "Length reserved extension used" );
+ }
+
+ return MORE;
+ }
+ else
+ {
+
+ return END;
+ }
+ }
+
+ /**
+ * 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.
+ *
+ * @return <code>true</code> if there are more bytes to read, <code>false
+ * </code> otherwise
+ *
+ * @throws DecoderException Thrown if anything went wrong
+ */
+ private boolean treatLengthPendingState( ByteBuffer stream, IAsn1Container container )
+ throws DecoderException
+ {
+
+ if ( stream.hasRemaining() )
+ {
+
+ Length length = container.getCurrentTLV().getLength();
+
+ while ( length.getCurrentLength() < length.getExpectedLength() )
+ {
+
+ byte octet = stream.get();
+
+ if ( DEBUG )
+ {
+ log.debug( " current byte : " + StringUtils.dumpByte( octet ) );
+ }
+
+ length.incCurrentLength();
+ length.incSize();
+ length.setLength( ( length.getLength() << 8 ) | (octet & 0x00FF));
+ }
+
+ container.setState( TLVStateEnum.LENGTH_STATE_END );
+
+ return MORE;
+ }
+ else
+ {
+
+ return END;
+ }
+ }
+
+ /**
+ * A debug function used to dump the expected length stack.
+ * @param tlv The current TLV.
+ * @return A string which represent the expected length stack.
+ */
+ private String getParentLength(TLV tlv)
+ {
+ StringBuffer buffer = new StringBuffer();
+
+ buffer.append("TLV expected length stack : ");
+
+ while (true)
+ {
+ if ( tlv == null )
+ {
+ buffer.append(" - null");
+ break;
+ }
+ else
+ {
+ buffer.append(" - ").append(tlv.getExpectedLength());
+ }
+
+ tlv = tlv.getParent();
+ }
+
+ return buffer.toString();
+ }
+
+ /**
+ * 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
+ */
+ private void treatLengthEndState( IAsn1Container container )
+ throws DecoderException
+ {
+ TLV tlv = container.getCurrentTLV();
+ Length length = tlv.getLength();
+
+ // We will check the length here. What we must control is
+ // that the enclosing constructed TLV expected length is not
+ // exceeded by the current TLV.
+ TLV parentTLV = container.getParentTLV();
+
+ if ( DEBUG )
+ {
+ log.debug(getParentLength(parentTLV));
+ }
+
+ if (parentTLV == null)
+ {
+ // 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());
+ container.setParentTLV(tlv);
+
+ if ( DEBUG )
+ {
+ log.debug("Root TLV[" + tlv.getLength().getLength() + "]");
+ }
+ }
+ else
+ {
+ // We have a parent, so we will check that its expected length is
+ // not exceeded.
+ int expectedLength = parentTLV.getExpectedLength();
+ int currentLength = tlv.getSize();
+
+ if (expectedLength < currentLength)
+ {
+ // The expected length is lower than the Value length of the
+ // current TLV. This is an error...
+ log.error("tlv[" + expectedLength + ", " + currentLength + "]");
+ throw new DecoderException("The current Value length is above the expected length");
+ }
+
+ 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())
+ {
+ // It's a constructed TLV. We will set it's parent to the
+ // parentTLV, and it will become the new parent TLV, after
+ // having set the new expected length.
+ tlv.setParent(parentTLV);
+ tlv.setExpectedLength(tlv.getLength().getLength());
+ container.setParentTLV(tlv);
+ }
+ else
+ {
+ tlv.setExpectedLength(tlv.getLength().getLength());
+ // 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.
+ while (parentTLV != null)
+ {
+ if ( parentTLV.getExpectedLength() != 0 )
+ {
+ // ok, we have an incomplete parent. we will
+ // stop the recursion right here
+ break;
+ }
+ else
+ {
+ parentTLV = parentTLV.getParent();
+ }
+ }
+
+ container.setParentTLV(parentTLV);
+ }
+ }
+ else
+ {
+ // Renew the expected Length.
+ parentTLV.setExpectedLength(expectedLength - currentLength);
+ tlv.setExpectedLength(tlv.getLength().getLength());
+
+ if (tlv.getTag().isConstructed())
+ {
+ // We have a constructed tag, so we must switch the parentTLV
+ tlv.setParent(parentTLV);
+ tlv.setExpectedLength(tlv.getLength().getLength());
+ container.setParentTLV(tlv);
+ }
+ }
+
+ }
+
+ if ( DEBUG )
+ {
+ log.debug( length.toString() + " has been decoded" );
+ }
+
+ if ( length.getLength() == 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 );
+ }
+ }
+
+ /**
+ * 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.
+ *
+ * @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 treatValueStartState( ByteBuffer stream, IAsn1Container container )
+ throws DecoderException
+ {
+
+ TLV currentTlv = container.getCurrentTLV();
+
+ if ( currentTlv.getTag().isConstructed() )
+ {
+ container.setState( TLVStateEnum.TLV_STATE_DONE );
+
+ return MORE;
+ }
+ else
+ {
+
+ int length = currentTlv.getLength().getLength();
+ int nbBytes = stream.remaining();
+
+ if ( nbBytes < length )
+ {
+ currentTlv.getValue().init( length );
+ currentTlv.getValue().setData( stream );
+ container.setState( TLVStateEnum.VALUE_STATE_PENDING );
+
+ return END;
+ }
+ else
+ {
+ currentTlv.getValue().init( length );
+ stream.get( currentTlv.getValue().getData(), 0, length );
+ container.setState( TLVStateEnum.TLV_STATE_DONE );
+
+ return MORE;
+ }
+ }
+ }
+
+ /**
+ * 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.
+ *
+ * @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
+ */
+ private boolean treatValuePendingState( ByteBuffer stream, IAsn1Container container )
+ throws DecoderException
+ {
+
+ TLV currentTlv = container.getCurrentTLV();
+
+ int length = currentTlv.getLength().getLength();
+ int currentLength = currentTlv.getValue().getCurrentLength();
+ int nbBytes = stream.remaining();
+
+ if ( ( currentLength + nbBytes ) < length )
+ {
+ currentTlv.getValue().addData( stream );
+ container.setState( TLVStateEnum.VALUE_STATE_PENDING );
+
+ return END;
+ }
+ else
+ {
+
+ int remaining = length - currentLength;
+ byte[] data = new byte[remaining];
+ stream.get( data, 0, remaining );
+ currentTlv.getValue().addData( data );
+ container.setState( TLVStateEnum.TLV_STATE_DONE );
+
+ return MORE;
+ }
+ }
+
+ /**
+ * 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.
+ *
+ * @return <code>true</code> if there are more bytes to read, <code>false
+ * </code> otherwise
+ *
+ * @throws DecoderException Thrown if anything went wrong
+ */
+ private boolean treatTLVDoneState( ByteBuffer stream, IAsn1Container container )
+ throws DecoderException
+ {
+ if ( DEBUG )
+ {
+ dumpTLVTree(container);
+ }
+
+ // First, we have to execute the associated action
+ container.getGrammar().executeAction( container );
+
+ // Check if the PDU has been fully decoded.
+ if ( isTLVDecoded(container) )
+ {
+ // Change the state to DECODED
+ container.setState( TLVStateEnum.PDU_DECODED );
+
+ }
+ else
+ {
+ // Then we switch to the Start tag state and free the current TLV
+ container.setState( TLVStateEnum.TAG_STATE_START );
+ }
+
+ return stream.hasRemaining();
+ }
+
+ /**
+ * An helper function that return a string representing the current state
+ * for debuging purpose.
+ *
+ * @param state The state
+ *
+ * @return A string representation of the state
+ */
+ private String stateToString( int state )
+ {
+
+ switch ( state )
+ {
+
+ 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";
+
+ case TLVStateEnum.TAG_STATE_OVERFLOW :
+ return "TAG_STATE_OVERFLOW";
+
+ case TLVStateEnum.LENGTH_STATE_START :
+ return "LENGTH_STATE_START";
+
+ case TLVStateEnum.LENGTH_STATE_PENDING :
+ return "LENGTH_STATE_PENDING";
+
+ case TLVStateEnum.LENGTH_STATE_END :
+ return "LENGTH_STATE_END";
+
+ case TLVStateEnum.VALUE_STATE_START :
+ return "VALUE_STATE_START";
+
+ case TLVStateEnum.VALUE_STATE_PENDING :
+ return "VALUE_STATE_PENDING";
+
+ case TLVStateEnum.TLV_STATE_DONE :
+ return "TLV_STATE_DONE";
+
+ default :
+ return "UNKNOWN_STATE";
+ }
+ }
+
+ /**
+ * 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.
+ *
+ * @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 org.apache.asn1.codec.DecoderException
+ {
+
+ /* 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 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 !
+ */
+
+ boolean hasRemaining = stream.hasRemaining();
+
+ if ( DEBUG )
+ {
+ log.debug( ">>>==========================================" );
+ log.debug( "--> Decoding a PDU" );
+ log.debug( ">>>------------------------------------------" );
+ }
+
+ while ( hasRemaining )
+ {
+
+ if ( DEBUG )
+ {
+ log.debug( "--- State = " + stateToString( container.getState() ) + " ---" );
+
+ if (stream.hasRemaining())
+ {
+ byte octet = stream.get(stream.position());
+
+ log.debug( " current byte : " + StringUtils.dumpByte( octet ) );
+ }
+ else
+ {
+ log.debug( " no more byte to decode in the stream");
+ }
+ }
+
+ switch ( container.getState() )
+ {
+
+ case TLVStateEnum.TAG_STATE_START :
+ hasRemaining = treatTagStartState( stream, container );
+
+ 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 );
+
+ break;
+
+ case TLVStateEnum.LENGTH_STATE_PENDING :
+ hasRemaining = treatLengthPendingState( stream, container );
+
+ break;
+
+ case TLVStateEnum.LENGTH_STATE_END :
+ treatLengthEndState( container );
+
+ break;
+
+ case TLVStateEnum.VALUE_STATE_START :
+ hasRemaining = treatValueStartState( stream, container );
+
+ break;
+
+ case TLVStateEnum.VALUE_STATE_PENDING :
+ hasRemaining = treatValuePendingState( stream, container );
+
+ break;
+
+ case TLVStateEnum.VALUE_STATE_END :
+ hasRemaining = stream.hasRemaining();
+
+ // Nothing to do. We will never reach this state
+ break;
+
+ case TLVStateEnum.TLV_STATE_DONE :
+ hasRemaining = treatTLVDoneState( stream, container );
+
+ break;
+
+ case TLVStateEnum.PDU_DECODED :
+ // We have to deal with the case where there are
+ // more bytes in the buffer, but the PDU has been decoded.
+ if ( log.isWarnEnabled() )
+ {
+ log.warn("The PDU has been fully decoded but there are still bytes in the buffer.");
+ }
+
+ hasRemaining = false;
+
+ break;
+ }
+ }
+
+ if ( DEBUG )
+ {
+ log.debug( "<<<------------------------------------------" );
+
+ if ( container.getState() == TLVStateEnum.PDU_DECODED )
+ {
+ log.debug( "<-- Stop decoding : " + container.getCurrentTLV().toString() );
+ }
+ else
+ {
+ log.debug( "<-- End decoding : " + container.getCurrentTLV().toString() );
+ }
+
+ log.debug( "<<<==========================================" );
+ }
+
+ return;
+ } // end method decode
+
+ /**
+ * Get the length's Length.
+ *
+ * @return Returns the length's Length.
+ */
+ public int getMaxLengthLength()
+ {
+
+ return maxLengthLength;
+ }
+
+ /**
+ * Get the maximum Tag's length
+ *
+ * @return Returns the maximum tag Length.
+ */
+ public int getMaxTagLength()
+ {
+
+ return maxTagLength;
+ }
+
+ /**
+ * Disallow indefinite length.
+ */
+ public void disallowIndefiniteLength()
+ {
+ this.indefiniteLengthAllowed = false;
+ }
+
+ /**
+ * Allow indefinite length.
+ */
+ public void allowIndefiniteLength()
+ {
+ this.indefiniteLengthAllowed = true;
+ }
+
+ /**
+ * Tells if indefinite length form could be used for Length
+ *
+ * @return Returns <code>true</code> if the current decoder support
+ * indefinite length
+ */
+ public boolean isIndefiniteLengthAllowed()
+ {
+
+ return indefiniteLengthAllowed;
+ }
+
+ /**
+ * 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
+ */
+ public void setMaxLengthLength( int maxLengthLength ) throws DecoderException
+ {
+
+ if ( ( this.indefiniteLengthAllowed ) && ( maxLengthLength > 126 ) )
+ {
+ throw new DecoderException(
+ "Length above 126 bytes are not allowed for a definite form Length" );
+ }
+
+ this.maxLengthLength = maxLengthLength;
+ }
+
+ /**
+ * Set the maximum Tag length
+ *
+ * @param maxTagLength The tagLength to set.
+ */
+ public void setMaxTagLength( int maxTagLength )
+ {
+ this.maxTagLength = maxTagLength;
+ }
+
+} // end class TLVTagDecoder
Added: directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/containers/IAsn1Container.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/containers/IAsn1Container.java?rev=279865&view=auto
==============================================================================
--- directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/containers/IAsn1Container.java (added)
+++ directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/containers/IAsn1Container.java Fri Sep 9 13:17:27 2005
@@ -0,0 +1,136 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.asn1new.ber.containers;
+
+import org.apache.asn1new.ber.grammar.IGrammar;
+import org.apache.asn1new.ber.grammar.IStates;
+import org.apache.asn1new.ber.tlv.TLV;
+
+
+/**
+ * Every ASN1 container must implement this interface.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface IAsn1Container
+{
+ //~ Methods ------------------------------------------------------------------------------------
+
+ // State accessors
+ /**
+ * Get the current grammar state
+ *
+ * @return Returns the current grammar state
+ */
+ int getState();
+
+ /**
+ * Set the new current state
+ *
+ * @param state The new state
+ */
+ void setState( int state );
+
+ /**
+ * Set the current TLV
+ *
+ * @param tlv The current TLV
+ */
+ public void setCurrentTLV( TLV tlv );
+
+ /**
+ * Get the currentTLV
+ *
+ * @return Returns the current TLV being decoded
+ */
+ public TLV getCurrentTLV();
+
+ /**
+ * Get the grammar
+ *
+ * @return Returns the grammar used to decode a LdapMessage.
+ */
+ public IGrammar getGrammar();
+
+ /**
+ * 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
+ */
+ public int getTransition();
+
+ /**
+ * Update the transition from a state to another
+ *
+ * @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.
+ */
+ public IStates getStates();
+
+ /**
+ * @return get the parent TLV.
+ */
+ public TLV getParentTLV();
+
+ /**
+ * Set the parent TLV
+ * @param The new parent TLV
+ */
+ public void setParentTLV(TLV parentTLV);
+}
Added: directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/AbstractGrammar.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/AbstractGrammar.java?rev=279865&view=auto
==============================================================================
--- directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/AbstractGrammar.java (added)
+++ directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/AbstractGrammar.java Fri Sep 9 13:17:27 2005
@@ -0,0 +1,248 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.asn1new.ber.grammar;
+
+import org.apache.asn1new.Asn1Object;
+import org.apache.asn1.codec.DecoderException;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ber.tlv.TLV;
+import org.apache.asn1new.ber.tlv.Tag;
+import org.apache.asn1new.util.StringUtils;
+import org.slf4j.LoggerFactory;
+
+import org.slf4j.Logger;
+
+
+/**
+ * The abstract IGrammar which is the Mother of all the grammars. It
+ * contains the transitions table.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public abstract class AbstractGrammar implements IGrammar
+{
+ //~ Static fields/initializers -----------------------------------------------------------------
+
+ /** The logger */
+ private static final Logger log = LoggerFactory.getLogger( AbstractGrammar.class );
+
+ /** A speedup for logs */
+ private static boolean DEBUG;
+
+ //~ Instance fields ----------------------------------------------------------------------------
+
+ /** Table of transitions. It's a two dimension array, the first dimension
+ * indice the states, the second dimension indices the Tag value, so it is 256 wide. */
+ protected GrammarTransition[][] transitions;
+
+ /** The grammar name */
+ protected String name;
+
+ /** The grammar's states */
+ protected IStates statesEnum;
+
+ public AbstractGrammar()
+ {
+ DEBUG = log.isDebugEnabled();
+ }
+
+ //~ Methods ------------------------------------------------------------------------------------
+
+ /**
+ * Return the grammar's name
+ * @return The grammar name
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * Set the grammar's name
+ * @param name DOCUMENT ME!
+ */
+ 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 ( 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
+ * @return A valid transition if any, or null.
+ */
+ public GrammarTransition getTransition( int state, int tag )
+ {
+ return transitions[state][tag & IStates.STATES_SWITCH_MASK];
+ }
+
+ /**
+ * 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
+ */
+ public void executeAction( IAsn1Container container ) throws DecoderException
+ {
+
+ int currentState = container.getTransition();
+ IGrammar currentGrammar = container.getGrammar();
+
+ // 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;
+ }
+ }
+
+ Tag tag = container.getCurrentTLV().getTag();
+ byte tagByte = tag.getTagByte();
+
+ // We will loop until no more actions are to be executed
+ while ( true )
+ {
+
+ GrammarTransition transition = ( ( AbstractGrammar ) container.getGrammar() )
+ .getTransition( currentState, tagByte & IStates.STATES_SWITCH_MASK );
+
+ if ( transition == null )
+ {
+
+ if ( container.getCurrentGrammar() == 0 )
+ {
+ String errorMessage = "Bad transition from state " +
+ currentGrammar.getStatesEnum().getState( container.getCurrentGrammarType(),
+ currentState ) + ", tag " + StringUtils.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.
+ currentState = container.restoreGrammar();
+ continue;
+ }
+ }
+
+ if ( 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 ( DEBUG )
+ {
+ log.debug(
+ "Switching from grammar " +
+ container.getStates().getGrammarName( currentGrammar ) +
+ " to grammar " + 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 );
+ }
+
+ break;
+ }
+ }
+ }
+
+ /**
+ * Get the states of the current grammar
+ *
+ * @return Returns the statesEnum.
+ */
+ public IStates getStatesEnum()
+ {
+ return statesEnum;
+ }
+
+ /**
+ * Set the states for this grammar
+ *
+ * @param statesEnum The statesEnum to set.
+ */
+ public void setStatesEnum( IStates statesEnum )
+ {
+ this.statesEnum = statesEnum;
+ }
+}
Added: directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/GrammarAction.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/GrammarAction.java?rev=279865&view=auto
==============================================================================
--- directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/GrammarAction.java (added)
+++ directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/GrammarAction.java Fri Sep 9 13:17:27 2005
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.asn1new.ber.grammar;
+
+/**
+ * A top level grammar class that store meta informations about the actions.
+ *
+ * Those informations are not mandatory, but they can be usefull for debugging.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public abstract class GrammarAction implements IAction
+{
+ //~ Instance fields ----------------------------------------------------------------------------
+
+ /** The action's name */
+ protected String name;
+
+ //~ Constructors -------------------------------------------------------------------------------
+
+ /**
+ * Creates a new GrammarAction object.
+ *
+ * @param name The name of the create daction
+ */
+ public GrammarAction( String name )
+ {
+ this.name = name;
+ }
+
+ //~ Methods ------------------------------------------------------------------------------------
+
+ /**
+ * Print the action's name
+ *
+ * @return The action's name
+ */
+ public String toString()
+ {
+ return name;
+ }
+}
Added: directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/GrammarTransition.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/GrammarTransition.java?rev=279865&view=auto
==============================================================================
--- directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/GrammarTransition.java (added)
+++ directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/GrammarTransition.java Fri Sep 9 13:17:27 2005
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.asn1new.ber.grammar;
+
+/**
+ * Define a transition between two states of a grammar. It stores the
+ * next state, and the action to execute while transiting.
+ *
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class GrammarTransition
+{
+ //~ Instance fields ----------------------------------------------------------------------------
+
+ /** The next state in the grammar */
+ private int nextState;
+
+ /** The action associated to the transition */
+ private GrammarAction action;
+
+ /** The current state */
+ private int currentState;
+
+ //~ Constructors -------------------------------------------------------------------------------
+
+ /**
+ * 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.
+ */
+ public GrammarTransition( int currentState, int nextState, GrammarAction action )
+ {
+ this.currentState = currentState;
+ this.nextState = nextState;
+ this.action = action;
+ }
+
+ //~ Methods ------------------------------------------------------------------------------------
+
+ /**
+ * @return Returns the target state.
+ */
+ public int getNextState()
+ {
+ return nextState;
+ }
+
+ /**
+ * Tells if the transition has an associated action.
+ *
+ * @return <code>true</code> if an action has been asociated to the transition
+ */
+ public boolean hasAction()
+ {
+ return action != null;
+ }
+
+ /**
+ * @return Returns the action associated with the transition
+ */
+ public GrammarAction getAction()
+ {
+ return action;
+ }
+
+ /**
+ * @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)
+ {
+
+ 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( ">" );
+
+ return sb.toString();
+ }
+}
Added: directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/IAction.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/IAction.java?rev=279865&view=auto
==============================================================================
--- directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/IAction.java (added)
+++ directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/IAction.java Fri Sep 9 13:17:27 2005
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.asn1new.ber.grammar;
+
+import org.apache.asn1.codec.DecoderException;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+
+
+/**
+ * IAction interface just contains the method 'action' which must be implemented
+ * in all the implementong classes.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface IAction
+{
+ //~ Methods ------------------------------------------------------------------------------------
+
+ /**
+ * The action to be executed.
+ *
+ * @param container The container which stores the current data
+ *
+ * @throws DecoderException Thrown if something went wrong.
+ */
+ public void action( IAsn1Container container ) throws DecoderException;
+}
Added: directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/IGrammar.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/IGrammar.java?rev=279865&view=auto
==============================================================================
--- directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/IGrammar.java (added)
+++ directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/IGrammar.java Fri Sep 9 13:17:27 2005
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.asn1new.ber.grammar;
+
+import org.apache.asn1.codec.DecoderException;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+
+
+/**
+ * The interface which expose common behavior of a Gramar implementer.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface IGrammar
+{
+ //~ Methods ------------------------------------------------------------------------------------
+
+ /**
+ * This method, when called, execute an action on the current data stored
+ * in the container.
+ *
+ * @param asn1Container Store the data being processed.
+ *
+ * @throws DecoderException Thrown when an unrecoverable error occurs.
+ */
+ void executeAction( IAsn1Container asn1Container ) throws DecoderException;
+
+ /**
+ * Get the grammar name
+ *
+ * @return Return the grammar's name
+ */
+ String getName();
+
+ /**
+ * Get the statesEnum for the current grammar
+ * @return The specific States Enum for the current grammar
+ */
+ IStates getStatesEnum();
+
+ /**
+ * Set the grammar's name
+ * @param name The grammar name
+ */
+ void setName( String name );
+}
Added: directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/IStates.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/IStates.java?rev=279865&view=auto
==============================================================================
--- directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/IStates.java (added)
+++ directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/grammar/IStates.java Fri Sep 9 13:17:27 2005
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.asn1new.ber.grammar;
+
+/**
+ * This interface is used to store the different states of a grammar. While
+ * tracing debugging information, the methods to dump the current state
+ * as a string are called.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface IStates {
+ /** The initial state of every grammar */
+ static int INIT_GRAMMAR_STATE = 0;
+
+ /** The ending state for every grammars */
+ static int GRAMMAR_END = -1;
+
+ /** 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 );
+
+ /** Return the grammar name from a grammar */
+ String getGrammarName(IGrammar grammar);
+
+ /** Return the grammar name from a grammar number */
+ String getGrammarName(int grammar);
+}
Added: directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/tlv/ITLVBerDecoderMBean.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/tlv/ITLVBerDecoderMBean.java?rev=279865&view=auto
==============================================================================
--- directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/tlv/ITLVBerDecoderMBean.java (added)
+++ directory/asn1/branches/elecharny-cleanup/ber-new/src/java/main/org/apache/asn1new/ber/tlv/ITLVBerDecoderMBean.java Fri Sep 9 13:17:27 2005
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.asn1new.ber.tlv;
+
+import org.apache.asn1.codec.DecoderException;
+
+
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface ITLVBerDecoderMBean
+{
+ //~ Methods ------------------------------------------------------------------------------------
+
+ /** Set the number of bytes that can be used to encode the Value length,
+ * including the first byte.
+ * Max is 127 if the Length use a definite form, default is 1
+ *
+ * @param length The number of byte to use
+ */
+ void setMaxLengthLength( int length ) throws DecoderException;
+
+ /** Set the maximum number of bytes that should be used to encode a Tag label,
+ * including the first byte.
+ * Default is 1, no maximum
+ *
+ * @param length The length to use
+ */
+ void setMaxTagLength( int length );
+
+ /** Allow indefinite length. */
+ void allowIndefiniteLength();
+
+ /** Disallow indefinite length. */
+ void disallowIndefiniteLength();
+
+ /** Get the actual maximum number of bytes that can be used to encode the Length
+ *
+ * @return The maximum bytes of the Length
+ */
+ int getMaxLengthLength();
+
+ /** Get the actual maximum number of bytes that can be used to encode the Tag
+ * @return The maximum length of the Tag
+ */
+ int getMaxTagLength();
+
+ /** Tell if indefinite length form could be used for Length
+ * @return <code>true</code> if the Indefinite form is allowed
+ */
+ boolean isIndefiniteLengthAllowed();
+}