You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by ad...@apache.org on 2007/05/15 17:30:05 UTC

svn commit: r538217 [7/10] - in /labs/dungeon/trunk: ./ asn1-compiler/ asn1-compiler/src/ asn1-compiler/src/main/ asn1-compiler/src/main/antlr/ asn1-compiler/src/main/java/ asn1-compiler/src/main/java/org/ asn1-compiler/src/main/java/org/apache/ asn1-c...

Added: labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/ber/Tag.java
URL: http://svn.apache.org/viewvc/labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/ber/Tag.java?view=auto&rev=538217
==============================================================================
--- labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/ber/Tag.java (added)
+++ labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/ber/Tag.java Tue May 15 08:29:41 2007
@@ -0,0 +1,454 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.asn1.encoding.ber;
+
+import java.nio.BufferOverflowException;
+
+import org.apache.asn1.encoding.DecoderException;
+
+
+/**
+ * The Tag component of a BER TLV Tuple.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">
+ *         Apache Directory Project</a>
+ * @version $Rev: 531147 $
+ */
+class Tag
+{
+    /**
+     * tag flag for the primitive/constructed bit - 0010 0000 - 0x20
+     */
+    private static final int CONSTRUCTED_FLAG = 0x20;
+    /** tag mask for the primitive/constructed bit - 1101 1111 - 0xDF */
+    // private static final int CONSTRUCTED_MASK = ~CONSTRUCTED_FLAG ;
+
+    /**
+     * tag mask for the short tag format - 0001 1111 - 0x1F
+     */
+    static final int SHORT_MASK = 0x1F;
+    /**
+     * tag mask for the long tag format - 0111 1111 - 0x7F
+     */
+    static final int LONG_MASK = 0x7F;
+    /**
+     * tag flag indicating the use of the long tag encoding form
+     */
+    private static final int LONG_FLAG = 0x80;
+
+    /**
+     * the max id size with one tag octet
+     */
+    private static final int ONE_OCTET_IDMAX = 30;
+    /**
+     * the max id size with two tag octets
+     */
+    private static final int TWO_OCTET_IDMAX = ( 1 << 7 ) - 1;
+    /**
+     * the max id size with three tag octets
+     */
+    private static final int THREE_OCTET_IDMAX = ( 1 << 14 ) - 1;
+    /**
+     * the max id size with four tag octets
+     */
+    private static final int FOUR_OCTET_IDMAX = ( 1 << 21 ) - 1;
+
+    /**
+     * tag id
+     */
+    private int id = 0;
+    /**
+     * whether or not this tag represents a primitive type
+     */
+    private boolean isPrimitive = true;
+    /**
+     * whether or not this tag has been fixated
+     */
+    private boolean isFixated = false;
+    /**
+     * the type class of this tag
+     */
+    private TypeClass typeClass = TypeClass.APPLICATION;
+    /**
+     * buffer backed by a Java int to collect the arriving tag octets
+     */
+    private final TagBuffer buf = new TagBuffer();
+
+
+    /**
+     * Clears this tag's data of all bytes and values calculated so all is as it
+     * was when this instance was created.
+     */
+    void clear()
+    {
+        id = 0;
+        isFixated = false;
+        isPrimitive = true;
+        typeClass = TypeClass.APPLICATION;
+        buf.clear();
+    }
+
+
+    /**
+     * Fixates the data within this Tag calculating all the derived
+     * properties from the existing set of octets.  While fixated octets
+     * cannot be added.
+     *
+     * @throws org.apache.asn1.encoding.DecoderException
+     *          if this Tag is invalid
+     */
+    void fixate() throws DecoderException
+    {
+        byte[] rawBytes = buf.toArray();
+
+        isFixated = true;
+        id = getTagId( rawBytes );
+        isPrimitive = isPrimitive( rawBytes[0] );
+        typeClass = TypeClass.getTypeClass( rawBytes[0] );
+    }
+
+
+    /**
+     * Adds an octet to this Tag and as a size effect may fixate the Tag if
+     * all the expected data has arrived.
+     *
+     * @param octet the 8 bit byte to add
+     */
+    void add( byte octet ) throws DecoderException
+    {
+        if ( isFixated )
+        {
+            throw new IllegalStateException( "data added to fixated tag" );
+        }
+
+        buf.put( octet );
+
+        if ( buf.size() == 1 )
+        {
+            // if its the short form so we just fixate now!
+            if ( ( SHORT_MASK & octet ) != SHORT_MASK )
+            {
+                fixate();
+            }
+        }
+        else if ( ( octet & LONG_FLAG ) == 0 )
+        {
+            /*
+             * From here on we're dealing with the long form of the tag.  The
+             * terminating octet for the long form uses a 0 for the most
+             * significant bit to flag the end of the train of octets for the
+             * tag id.
+             */
+            fixate();
+        }
+    }
+
+
+    /**
+     * Gets a copy of the octets composing this Tag.
+     *
+     * @return the octets representing this Tag
+     */
+    byte[] getOctets()
+    {
+        return buf.toArray();
+    }
+
+
+    /**
+     * Gets the number of octets in this Tag.
+     *
+     * @return the number of octets within this Tag
+     */
+    int size()
+    {
+        return buf.size();
+    }
+
+
+    /**
+     * Gets the id.
+     *
+     * @return the id
+     */
+    int getId()
+    {
+        return id;
+    }
+
+
+    /**
+     * Gets the raw tag as it is stuffed into a primitive int.
+     *
+     * @return a primitive int stuffed with the first four octets of the tag
+     */
+    int getRawTag()
+    {
+        return buf.getIntValue();
+    }
+
+
+    /**
+     * Checks to see if the tag represented by this Tag is primitive or
+     * constructed.
+     *
+     * @return true if it is primitive, false if it is constructed
+     */
+    boolean isPrimitive()
+    {
+        return isPrimitive;
+    }
+
+
+    /**
+     * Checks to see if the tag has been fixated.
+     *
+     * @return true if it is fixated, false if not
+     */
+    boolean isFixated()
+    {
+        return isFixated;
+    }
+
+
+    /**
+     * Gets the type class for this Tag.
+     *
+     * @return the typeClass for this Tag
+     */
+    TypeClass getTypeClass()
+    {
+        return typeClass;
+    }
+
+    // ------------------------------------------------------------------------
+    // Utility Methods For Dealing With Tags and Tag Octets
+    // ------------------------------------------------------------------------
+
+
+    /**
+     * @param type
+     * @param id
+     * @param isConstructed
+     * @return
+     */
+    final static int getIntEncodedTag( TypeClass type, int id, boolean isConstructed )
+    {
+        int value = type.getValue() << 24;
+
+        if ( isConstructed )
+        {
+            value |= ( CONSTRUCTED_FLAG << 24 );
+        }
+
+        if ( id <= ONE_OCTET_IDMAX )
+        {
+            value |= ( id << 24 );
+        }
+        else if ( id <= TWO_OCTET_IDMAX )
+        {
+            value |= ( SHORT_MASK << 24 );
+            value |= ( id & 0x0000007F ) << 16;
+        }
+        else if ( id <= THREE_OCTET_IDMAX )
+        {
+            value |= ( SHORT_MASK << 24 );
+            value |= ( id & 0x00003F80 ) << 9;
+            value |= ( id & 0x0000007F ) << 8;
+            value |= 0x00800000;
+        }
+        else if ( id <= FOUR_OCTET_IDMAX )
+        {
+            value |= ( SHORT_MASK << 24 );
+            value |= ( id & 0x001FC000 ) << 2;
+            value |= ( id & 0x00003F80 ) << 1;
+            value |= ( id & 0x0000007F );
+            value |= 0x00808000;
+        }
+        else
+        {
+            String msg = "Id argument value of " + id
+                    + " was greater than the maximum supported id of "
+                    + FOUR_OCTET_IDMAX;
+            throw new IllegalArgumentException( msg );
+        }
+
+        return value;
+    }
+
+
+    /**
+     * Gets the tag id of a TLV from tag octets.
+     *
+     * @param octets the set of octets needed to determine the tag value
+     *               (a.k.a identifier octets)
+     * @return the tag id
+     * @throws org.apache.asn1.encoding.DecoderException
+     *          if the id cannot be determined due to
+     *          type limitations of this method's return type.
+     */
+    final static int getTagId( byte[] octets ) throws DecoderException
+    {
+        if ( octets.length > 4 )
+        {
+            /*
+             * If this exception is ever thrown which is highly unlikely, then
+             * we need to switch to another data type to return because after
+             * 4 bytes the int can no longer hold the number.
+             */
+            throw new DecoderException( "Tag number is too large." );
+        }
+
+        int id = octets[0] & SHORT_MASK;
+
+        // if bits are not all 1's then return the value which is less than 31
+        if ( id != SHORT_MASK && octets.length == 1 )
+        {
+            return id;
+        }
+
+        // clear the id now
+        id = 0;
+
+        // calculate tag value w/ long tag format
+        for ( int i = 1; i < octets.length; i++ )
+        {
+            int shift = ( octets.length - i - 1 ) * 7;
+            id |= ( octets[i] & LONG_MASK ) << shift;
+        }
+
+        return id;
+    }
+
+
+    /**
+     * Checks to see if the tag is a primitive.
+     *
+     * @param octet the first octet of the tag
+     * @return true if this tag is of the simple type, false if constructed
+     */
+    final static boolean isPrimitive( int octet )
+    {
+        return ( octet & CONSTRUCTED_FLAG ) == 0;
+    }
+
+
+    /**
+     * Checks to see if the tag is constructed.
+     *
+     * @param octet the first octet of the tag
+     * @return true if constructed, false if primitive
+     */
+    final static boolean isConstructed( int octet )
+    {
+        return ( octet & CONSTRUCTED_FLAG ) == CONSTRUCTED_FLAG;
+    }
+
+
+    /**
+     * Collects up to 4 tag octets.
+     */
+    protected class TagBuffer
+    {
+        /**
+         * the store the tag octets
+         */
+        private byte[] buffer = new byte[4];
+
+        /**
+         * the number of octets currently stored
+         */
+        private int _size = 0;
+
+
+        /**
+         * Puts an octet into this collector.
+         *
+         * @param octet the octet to put into the collector.
+         */
+        public void put( byte octet )
+        {
+            if ( _size == 4 ) throw new BufferOverflowException();
+
+            buffer[_size++] = octet;
+        }
+
+
+        /**
+         * Clears all the tag octets resetting the tag and size to zero.
+         */
+        public void clear()
+        {
+            buffer[0] = buffer[1] = buffer[2] = buffer[3] = 0;
+            _size = 0;
+        }
+
+
+        /**
+         * Gets the number of octets stored by this TagId
+         *
+         * @return
+         */
+        public int size()
+        {
+            return _size;
+        }
+
+
+        /**
+         * Gets a unique integer value representing the tag octets.
+         *
+         * @return the integer value of the tag.
+         */
+        public int getIntValue()
+        {
+            return (int) ( ( buffer[0] << 24 ) | ( buffer[1] << 16 ) | ( buffer[2] << 8 ) | buffer[3] );
+        }
+
+
+        /**
+         * Gets the 4 octets for the tag.
+         *
+         * @return
+         */
+        public byte[] toArray()
+        {
+            byte[] octets = new byte[_size];
+
+            for ( int i = 0; i < _size; i++ ) octets[i] = buffer[i];
+
+            return octets;
+        }
+
+
+        /**
+         * Gets the byte at a specific index.
+         *
+         * @param index
+         * @return
+         * @throws IndexOutOfBoundsException
+         */
+        public byte get( int index )
+        {
+            if ( index >= _size ) throw new IndexOutOfBoundsException( "accesing index " + index + " with a size of " + _size );
+
+            return buffer[index];
+        }
+
+    }
+}

Added: labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/ber/Tuple.java
URL: http://svn.apache.org/viewvc/labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/ber/Tuple.java?view=auto&rev=538217
==============================================================================
--- labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/ber/Tuple.java (added)
+++ labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/ber/Tuple.java Tue May 15 08:29:41 2007
@@ -0,0 +1,666 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.asn1.encoding.ber;
+
+
+import java.nio.ByteBuffer;
+import java.util.List;
+
+
+/**
+ * TLV Tuple used by the value chunking decoder.  Because the length field is
+ * a primitive int it's maximum value is 2,147,483,647 a single TLV's tuple
+ * cannot have a length over this amount or a value size over 2 GB.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory Project</a>
+ * @version $Rev: 531147 $
+ */
+public class Tuple
+{
+    /**
+     * mask for bit 5 with 0-based index
+     */
+    private static final int BIT_5 = 0x20;
+    /**
+     * mask for bit 6 with 0-based index
+     */
+    private static final int BIT_6 = 0x40;
+    /**
+     * mask for bit 7 with 0-based index
+     */
+    private static final int BIT_7 = 0x80;
+
+    /**
+     * precalculated left shift of 1 by 14 places
+     */
+    private static final int BIT_13 = 1 << 14;
+    /**
+     * precalculated left shift of 1 by 16 places
+     */
+    private static final int BIT_15 = 1 << 16;
+    /**
+     * precalculated left shift of 1 by 21 places
+     */
+    private static final int BIT_20 = 1 << 21;
+    /**
+     * precalculated left shift of 1 by 24 places
+     */
+    private static final int BIT_23 = 1 << 24;
+    /**
+     * precalculated left shift of 1 by 28 places
+     */
+    private static final int BIT_27 = 1 << 28;
+
+    /**
+     * the raw tag data
+     */
+    int rawTag = 0;
+    /**
+     * the tag id for this TLV tuple
+     */
+    int id = 0;
+    /**
+     * the flag for whether or not this TLV is constructed or primitive
+     */
+    boolean isPrimitive = true;
+    /**
+     * the type class for this TLV
+     */
+    TypeClass typeClass = TypeClass.APPLICATION;
+    /**
+     * the length for this TLV tuple
+     */
+    int length = 0;
+
+    /**
+     * tlv byte index
+     */
+    int index = 0;
+
+    // ------------------------------------------------------------------------
+    // C O N S T R U C T O R S
+    // ------------------------------------------------------------------------
+
+
+    /**
+     * Empty do nothing tuple.
+     */
+    public Tuple()
+    {
+    }
+
+    public Tuple( Tag tag )
+    {
+        rawTag = tag.getRawTag();
+        id = tag.getId();
+        isPrimitive = tag.isPrimitive();
+        typeClass = tag.getTypeClass();
+    }
+
+    /**
+     * Creates constructed application type tlv tuples.  Constructed TLV's with
+     * a definate length will use this constructor predominantly.  The TypeClass
+     * defualts to APPLICATION.
+     *
+     * @param id     the tag id of the tlv
+     * @param length the length of the value which is the length of all the
+     *               nested tuples.
+     */
+    public Tuple( int id, int length )
+    {
+        this( id, length, TypeClass.APPLICATION );
+    }
+
+
+    /**
+     * Creates constructed application type tlv tuples.  Constructed TLV's with
+     * a definate length will use this constructor predominantly.
+     *
+     * @param id        the tag id of the tlv
+     * @param length    the length of the value which is the length of all the
+     *                  nested tuples.
+     * @param typeClass the type class of this tlv tuple
+     */
+    public Tuple( int id, int length, TypeClass typeClass )
+    {
+        this.id = id;
+        this.length = length;
+        isPrimitive = false;
+
+        if ( typeClass != null )
+        {
+            this.typeClass = typeClass;
+        }
+    }
+
+
+    /**
+     * Creates constructed application type tlv tuples.  Constructed TLV's with
+     * a definate length will use this constructor predominantly.
+     *
+     * @param id          the tag id of the tlv
+     * @param length      the length of the value which is the length of all the
+     *                    nested tuples.
+     * @param isPrimitive whether or not this Tuple is primitive or constructed
+     * @param typeClass   the type class of this tlv tuple
+     */
+    public Tuple( int id, int length, boolean isPrimitive, TypeClass typeClass )
+    {
+        this.id = id;
+        this.length = length;
+        isPrimitive = false;
+
+        if ( typeClass != null )
+        {
+            this.typeClass = typeClass;
+        }
+    }
+
+
+    /**
+     * Creates a tuple where the length is indefinate.  The tuple according to
+     * the BER encoding must be of the constructed type.
+     *
+     * @param id        the tag id of the tlv
+     * @param typeClass the type class for the tlv
+     */
+    public Tuple( int id, TypeClass typeClass )
+    {
+        this.id = id;
+        this.isPrimitive = false;
+        length = Length.INDEFINITE;
+
+        if ( typeClass != null )
+        {
+            this.typeClass = typeClass;
+        }
+    }
+
+    // ------------------------------------------------------------------------
+    // Public Accessors
+    // ------------------------------------------------------------------------
+
+
+    /**
+     * Gets the tag id for this TLV Tuple.
+     *
+     * @return the tag id
+     */
+    public int getId()
+    {
+        return id;
+    }
+
+    /**
+     * Sets the tag id for this TLV Tuple.
+     *
+     * @param id the tag id
+     */
+    public void setId( int id )
+    {
+        this.id = id;
+    }
+
+    /**
+     * Gets the raw tag as it is stuffed into a primitive int.
+     *
+     * @return a primitive int stuffed with the first four octets of the tag
+     */
+    public int getRawTag()
+    {
+        return rawTag;
+    }
+
+
+    /**
+     * Gets the raw tag with the primitive/constructed flag dubbed out.
+     * Effectively this makes every tag appear primitive and is done
+     * to remove encoding ambiguities that could interfere with pattern
+     * matching.
+     *
+     * @return the raw tag with the primitive/constructed flag dubbed out
+     */
+    public int getRawPrimitiveTag()
+    {
+        return rawTag & 0xDFFFFFFF;
+    }
+
+
+    /**
+     * Get's whether or not this tuples's length is indefinite.
+     *
+     * @return whether or not this tuple's length is indefinite
+     */
+    public boolean isIndefinite()
+    {
+        return length == Length.INDEFINITE;
+    }
+
+
+    /**
+     * Get's whether or not this tuple terminates an indefinite constructed
+     * tuple.  This means that length == 0 && isPrimitive = true && id == 0
+     * and the type class is universal.
+     *
+     * @return whether or not this node's length is indefinate
+     */
+    public boolean isIndefiniteTerminator()
+    {
+        return isPrimitive && ( id + length ) == 0 &&
+                typeClass.equals( TypeClass.UNIVERSAL );
+    }
+
+
+    /**
+     * Gets whether or not this TLV tuple is primitive or constructed.
+     *
+     * @return true if it is primitive, false if it is constructed
+     */
+    public boolean isPrimitive()
+    {
+        return isPrimitive;
+    }
+
+    /**
+     * Sets whether or not this TLV tuple is primitive or constructed.
+     *
+     * @param primitive
+     */
+    public void setPrimitive( boolean primitive )
+    {
+        isPrimitive = primitive;
+    }
+
+    /**
+     * Gets the value length for this TLV Tuple.
+     *
+     * @return the length in bytes of the value field for this TLV tuple
+     */
+    public int getLength()
+    {
+        return length;
+    }
+
+    /**
+     * Sets the value length for this TLV Tuple.
+     *
+     * @param length the length in bytes of the value field for this TLV tuple
+     */
+    public void setLength( int length )
+    {
+        this.length = length;
+    }
+
+    /**
+     * Gets the BER TLV TypeClass for this TLV Tuple.
+     *
+     * @return the BER TLV TypeClass for this TLV Tuple
+     */
+    public TypeClass getTypeClass()
+    {
+        return typeClass;
+    }
+
+    /**
+     * Sets the BER TLV TypeClass for this TLV Tuple.
+     *
+     * @param typeClass the BER TLV TypeClass for this TLV Tuple
+     */
+    public void setTypeClass( TypeClass typeClass )
+    {
+        this.typeClass = typeClass;
+    }
+
+    /**
+     * Gets the total size of this TLV tuple in bytes.  This includes the
+     * length of the tag field, the length of the length field and the length
+     * of the value filed.
+     *
+     * @return the total TLV size in bytes
+     */
+    public int size()
+    {
+        if ( this.length == Length.INDEFINITE )
+        {
+            return getTagLength() + getLengthLength();
+        }
+        else
+        {
+            return getTagLength() + getLengthLength() + length;
+        }
+    }
+
+    public int remaining()
+    {
+        return size() - index;
+    }
+
+    public void update( int amount )
+    {
+        index += amount;
+    }
+
+    public int getIndex()
+    {
+        return index;
+    }
+
+    public void setIndex( int index )
+    {
+        this.index = index;
+    }
+
+    // ------------------------------------------------------------------------
+    // Utility methods and java.lang.Object overrides
+    // ------------------------------------------------------------------------
+
+
+    /**
+     * Clears the values of this tuple.
+     */
+    public void clear()
+    {
+        this.id = 0;
+        this.index = 0;
+        this.rawTag = 0;
+        this.isPrimitive = true;
+        this.length = Length.UNDEFINED;
+        this.typeClass = TypeClass.APPLICATION;
+    }
+
+
+    /**
+     * Does not take into account the value, index or the valueIndex values when
+     * checking for equality.  Technically if both are being constructed by
+     * the decoder then they should only be equal when these values are equal
+     * because the tag, length or value would not be correct.  Plus since this
+     * is a chunking tuple the valueChunk means nothing with respect to the
+     * final value.
+     *
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    public boolean equals( Object o )
+    {
+        if ( o == this )
+        {
+            return true;
+        }
+
+        if ( o instanceof Tuple )
+        {
+            Tuple t = (Tuple) o;
+
+            if ( t.id != id )
+            {
+                return false;
+            }
+
+            if ( t.isPrimitive != isPrimitive )
+            {
+                return false;
+            }
+
+            if ( t.length != length )
+            {
+                return false;
+            }
+
+            if ( t.typeClass != typeClass )
+            {
+                return false;
+            }
+
+            return true;
+        }
+
+        return false;
+    }
+
+    // ------------------------------------------------------------------------
+    // Tuple encoding operations
+    // ------------------------------------------------------------------------
+
+
+    /**
+     * @return partial encoded image if constructed or complete TLV if primitive
+     * @todo this should produce chunking output and needs to be removed from
+     * here actually and made into a standalone encoder.  You give it a buffer
+     * and it fills it as much as it can remembering where the encode stopped.
+     * Hence it is stateful as expected from the statemachine.
+     * <p/>
+     * If this is a primitive TLV then the valueBytes argument is used to
+     * produce an encoded image of this TLV.  If it is constructed then
+     * only the TL part of the tuple is encoded leaving the value to be encoded
+     * by the set of child TLVs.
+     */
+    public ByteBuffer toEncodedBuffer( List valueChunks )
+    {
+        ByteBuffer octets = null;
+        int tagLength = getTagLength();
+        int lengthLength = getLengthLength();
+        int total = tagLength + lengthLength;
+
+        if ( isPrimitive )
+        {
+            total += length;
+        }
+
+        octets = ByteBuffer.allocate( total );
+        setTag( octets, tagLength );
+        setLength( octets, lengthLength );
+
+        if ( isPrimitive )
+        {
+            for ( int ii = 0; ii < valueChunks.size(); ii++ )
+            {
+                octets.put( (ByteBuffer) valueChunks.get( ii ) );
+            }
+        }
+
+        return (ByteBuffer) octets.flip();
+    }
+
+
+    /**
+     * Sets the tag section within the buffer.
+     *
+     * @param octets    the buffer to set the tag in
+     * @param tagLength the length of the tag section
+     */
+    public void setTag( ByteBuffer octets, int tagLength )
+    {
+        if ( tagLength >= 6 )
+        {
+            throw new IllegalArgumentException( "cannot support id's as large as " + id + " unless we start using longs for the id" );
+        }
+
+        octets.put( (byte) typeClass.getValue() );
+
+        if ( !isPrimitive )
+        {
+            octets.put( 0, (byte) ( octets.get( 0 ) | BIT_5 ) );
+        }
+
+        if ( tagLength == 1 )
+        {
+            octets.put( 0, (byte) ( octets.get( 0 ) | id ) );
+            return;
+        }
+
+        octets.put( 0, (byte) ( octets.get( 0 ) | Tag.SHORT_MASK ) );
+
+        for ( int i = 0; i < tagLength - 1; i++ )
+        {
+            int shift = ( tagLength - i - 2 ) * 7;
+            octets.put( (byte) ( id >> shift & Tag.LONG_MASK | ( shift == 0 ? 0 : BIT_7 ) ) );
+        }
+    }
+
+
+    /**
+     * Sets the length bytes.
+     *
+     * @param octets      the byte [] to set length in
+     * @param lengthBytes the number bytes for the length section
+     */
+    public void setLength( ByteBuffer octets, int lengthBytes )
+    {
+        if ( length == Length.INDEFINITE )
+        {
+            octets.put( (byte) BIT_7 );
+            return;
+        }
+        else if ( lengthBytes == 1 )
+        {
+            octets.put( (byte) length );
+            return;
+        }
+        else
+        {
+            /*
+             * the lengthBytes argument is the number of octets for the L field
+             * total which for the long form includes the first octet for the 
+             * length of length (N) value where N < 127.  Technically with the 
+             * 7 bits we can specify an N of up to 127 but this value of N is 
+             * reserved.  Anyway below we subtract one from lengthBytes to get
+             * N which is set as the last 7 bits of the first octet of the L
+             * field. 
+             */
+            octets.put( (byte) ( BIT_7 | ( lengthBytes - 1 ) ) );
+        }
+
+        if ( lengthBytes >= 2 )
+        {
+            octets.put( (byte) ( 0xff & length ) );
+        }
+        else
+        {
+            return;
+        }
+
+        if ( lengthBytes >= 3 )
+        {
+            octets.put( (byte) ( ( 0xff00 & length ) >> 8 ) );
+        }
+        else
+        {
+            return;
+        }
+
+        if ( lengthBytes >= 4 )
+        {
+            octets.put( (byte) ( ( 0xff0000 & length ) >> 16 ) );
+        }
+        else
+        {
+            return;
+        }
+
+        if ( lengthBytes >= 5 )
+        {
+            octets.put( (byte) ( ( 0xff000000 & length ) >> 24 ) );
+        }
+        else
+        {
+            return;
+        }
+
+        if ( lengthBytes >= 6 )
+        {
+            throw new IllegalArgumentException( "cannot support lengths as "
+                    + "large as " + length
+                    + " unless we start using longs for the length" );
+        }
+    }
+
+
+    /**
+     * Gets the length in bytes of the tag section for this TLV tuple.
+     *
+     * @return the length in bytes of the tag section for this TLV tuple
+     */
+    public int getTagLength()
+    {
+        if ( id < 31 )
+        {
+            return 1;
+        }
+        else if ( id < BIT_6 )
+        {
+            return 2;
+        }
+
+        else if ( id < BIT_13 )
+        {
+            return 3;
+        }
+        else if ( id < BIT_20 )
+        {
+            return 4;
+        }
+        else if ( id < BIT_27 )
+        {
+            return 5;
+        }
+
+        throw new IllegalArgumentException( "cannot support id's larger than "
+                + id + " unless we start using longs for the id" );
+    }
+
+
+    /**
+     * Gets the length in bytes of the length section of this TLV Tuple.
+     *
+     * @return the length in bytes of the length section
+     */
+    public int getLengthLength()
+    {
+        if ( length == Length.INDEFINITE )
+        {
+            return 1;
+        }
+
+        if ( length < 0 )
+        {
+            throw new IllegalArgumentException( "integer overflow makes id "
+                    + "negative with a value of " + id
+                    + " - unless we start using longs for"
+                    + " the id there you've hit a limitation" );
+        }
+        else if ( length < BIT_7 )
+        {
+            return 1;
+        }
+        else if ( length < 256 )
+        {
+            return 2;
+        }
+        else if ( length < BIT_15 )
+        {
+            return 3;
+        }
+        else if ( length < BIT_23 )
+        {
+            return 4;
+        }
+        else
+        {
+            return 5;
+        }
+    }
+}

Added: labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/ber/TupleNode.java
URL: http://svn.apache.org/viewvc/labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/ber/TupleNode.java?view=auto&rev=538217
==============================================================================
--- labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/ber/TupleNode.java (added)
+++ labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/ber/TupleNode.java Tue May 15 08:29:41 2007
@@ -0,0 +1,120 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.asn1.encoding.ber;
+
+
+import java.nio.ByteBuffer;
+import java.util.Iterator;
+import java.util.List;
+
+
+/**
+ * A TLV Tuple tree node modeled in the likeness of a TreeNode.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">
+ *         Apache Directory Project</a>
+ * @version $Rev: 531142 $
+ */
+public interface TupleNode
+{
+    /**
+     * Gets the parent tuple node to this node or null if a parent does not
+     * exist.  The analogous method on the <code>TreeNode</code> interface
+     * would be <code>getParent()</code>.
+     *
+     * @return the parent node or null if one does not exist
+     */
+    TupleNode getParentTupleNode();
+
+    /**
+     * Gets an iterator over this node's children.  The analogous interface on
+     * the <code>TreeNode</code> interface would be <code>children</code> which
+     * returns an <code>Enumeration</code> instead of an <code>Iterator</code>.
+     *
+     * @return an iterator over this node's children
+     */
+    Iterator getChildren();
+
+    /**
+     * Gets a tuple node at an index.  The analogous interface on <code>TreeNode
+     * </code> would be the <code>getChildAt</code> method.
+     *
+     * @param index the index of the child to get
+     * @return the child node at the specified index
+     */
+    TupleNode getChildTupleNodeAt( int index );
+
+    /**
+     * Gets the chunked value buffer fragments collected within this node.
+     *
+     * @return the value buffer parts for this node
+     */
+    List getValueChunks();
+
+    /**
+     * Gets the index of a child if the child node if it exists.  The analog
+     * within <code>TreeNode<code> takes a <code>TreeNode</code> instead of a
+     * <code>TupleNode</code>.
+     *
+     * @param node the child node to get the index for
+     * @return the index of the child node or -1 if the node does not exist
+     */
+    int getIndex( TupleNode node );
+
+    /**
+     * Gets the number of child nodes contained.  This is the same as in
+     * <code>TreeNode.getChildCount()</code> as well.
+     *
+     * @return the number of child nodes contained.
+     */
+    int getChildCount();
+
+    /**
+     * Gets the number of child nodes contained.  This is the same as in
+     * <code>TreeNode.size()</code> as well.
+     *
+     * @return the number of children
+     */
+    int size();
+
+    /**
+     * Gets the Tuple this node represents.   This is the analogous to <code>
+     * TreeNode.getUserObject()</code>.
+     *
+     * @return the tuple this node represents or null if one has not been
+     *         assigned
+     */
+    Tuple getTuple();
+
+    /**
+     * Recursively encodes the tree rooted at this node.
+     *
+     * @param buf the buffer populated with the BER encoded tlv tree contents
+     */
+    void encode( ByteBuffer buf );
+
+    /**
+     * Checks to see if two trees are equal.  Note that the order of children
+     * within the tree as well as the tuples and their contents make a
+     * difference to <code>equals()</code>.
+     *
+     * @param obj the object to compare this node to
+     * @return true if the obj and this node are exact replicas of one another
+     */
+    boolean equals( Object obj );
+}

Added: labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/ber/TupleStack.java
URL: http://svn.apache.org/viewvc/labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/ber/TupleStack.java?view=auto&rev=538217
==============================================================================
--- labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/ber/TupleStack.java (added)
+++ labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/ber/TupleStack.java Tue May 15 08:29:41 2007
@@ -0,0 +1,240 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.asn1.encoding.ber;
+
+import java.nio.ByteBuffer;
+import java.util.Stack;
+
+
+/**
+ * @version $Revision: 531142 $ $Date: $
+ */
+class TupleStack
+{
+    /**
+     * this decoder's callback
+     */
+    private DecoderCallback callback = new BERDecoderCallbackAdapter();
+
+    /**
+     * this decoder's callback
+     */
+    private DecoderCallback BERcallback = new BERDecoderCallbackAdapter();
+
+    /**
+     * the monitor used by this decoder
+     */
+    private DecoderMonitor monitor = new DecoderMonitorAdapter();
+
+    /**
+     * a reference to the stack's decoder which is used used to report status
+     * with monitor
+     */
+    private final AOKDecoder decoder;
+
+    /**
+     * internal stack used to track incomplete tuples
+     */
+    private final Stack stack = new Stack();
+
+
+    /**
+     * Constructs a tuple stack
+     *
+     * @param decoder the stack's decoder which is used used to report status
+     *                with monitor
+     */
+    TupleStack( AOKDecoder decoder )
+    {
+        this.decoder = decoder;
+    }
+
+    /**
+     * Obtain the stack's DecoderCallback
+     *
+     * @return the stack's DecoderCallback
+     */
+    DecoderCallback getCallback()
+    {
+        return callback;
+    }
+
+    /**
+     * Set the stack's DecoderCallback
+     *
+     * @param callback the stack's DecoderCallback
+     */
+    void setCallback( DecoderCallback callback )
+    {
+        this.callback = callback;
+
+        if ( callback instanceof DecoderCallback ) BERcallback = (DecoderCallback) callback;
+    }
+
+    /**
+     * Obtain the stack's DecoderMonitor
+     *
+     * @return the stack's DecoderMonitor
+     */
+    DecoderMonitor getMonitor()
+    {
+        return monitor;
+    }
+
+    /**
+     * Set the stack's DecoderMonitor
+     *
+     * @param monitor the stack's DecoderMonitor
+     */
+    void setMonitor( DecoderMonitor monitor )
+    {
+        this.monitor = monitor;
+    }
+
+    /**
+     * Take a peek at the incomplete TLV that is on the top of the stack
+     *
+     * @return the incomplete TLV that is on the top of the stack
+     */
+    Tuple peek()
+    {
+        return (Tuple) stack.peek();
+    }
+
+    /**
+     * Method used tp push an incomplete TLV that is on the top of the stack.
+     * This TLV will be managed by the stack and events about its condition
+     * will be sent by this stack. <p/>
+     * <p/>
+     * The following tagBuffer properties of the TLV tuple are valid at this
+     * point:
+     * <ul>
+     * <li>id</li>
+     * <li>isPrimitive</li>
+     * <li>typeClass</li>
+     * <li>lengthBuffer</li>
+     * </ul>
+     *
+     * @param tlv
+     */
+    public void push( Tuple tlv )
+    {
+
+        if ( tlv.isIndefiniteTerminator() )
+        {
+            Tuple itlv = (Tuple) stack.pop();
+
+            if ( !itlv.isIndefinite() )
+            {
+                /**
+                 * Since this TLV is the indefinite terminator, the top of the
+                 * stack should be its indefinite pair.
+                 */
+                IllegalStateException ise = new IllegalStateException( "No matching TAG for indefinite terminator" );
+                monitor.fatalError( decoder, ise );
+                throw ise;
+            }
+
+            /**
+             * Original indefinite events
+             */
+            if ( BERcallback != null ) BERcallback.end();
+            callback.decodeOccurred( decoder, itlv );
+        }
+        else
+        {
+            if ( tlv.isIndefinite() )
+            {
+                /**
+                 * Since this TLV is indefinite, all remaing TLVs on the stack
+                 * must be constructive and indefinite.
+                 */
+                for ( int i = stack.size() - 1; i >= 0; i-- )
+                {
+                    Tuple stlv = (Tuple) stack.get( i );
+
+                    if ( !stlv.isIndefinite() )
+                    {
+                        IllegalStateException ise = new IllegalStateException( "Containing constructive TLV not indefinite" );
+                        monitor.fatalError( decoder, ise );
+                        throw ise;
+                    }
+                }
+            }
+
+            if ( BERcallback != null ) BERcallback.start( tlv );
+
+            stack.push( tlv );
+
+            received( tlv.getTagLength() );
+            received( tlv.getLengthLength() );
+        }
+    }
+
+    /**
+     * Update the contents of the incomplete TLV that is on the top of the
+     * stack.  One side effect of this method is that elements that are on
+     * the top of the stack and complete are popped off after the proper
+     * notifications are sent.
+     *
+     * @param buffer the NIO byte buffer
+     */
+    void contents( ByteBuffer buffer )
+    {
+        if ( BERcallback != null ) BERcallback.contents( buffer.slice() );
+
+        received( buffer.remaining() );
+    }
+
+    /**
+     * This protected method manages the stack and pops off completed TLVs
+     * after the proper notifications are sent.
+     *
+     * @param amount
+     */
+    protected void received( int amount )
+    {
+        for ( int i = stack.size() - 1; i >= 0; i-- )
+        {
+            Tuple tlv = (Tuple) stack.get( i );
+
+            tlv.update( amount );
+
+            if ( !tlv.isIndefinite() )
+            {
+                if ( tlv.remaining() == 0 )
+                {
+                    if ( tlv != stack.pop() )
+                    {
+                        /**
+                         * All prior TLVs on the stack should have been popped
+                         * and so, this should be the top element.
+                         */
+                        IllegalStateException ise = new IllegalStateException( "Complete TLV is not on top of stack" );
+                        monitor.fatalError( decoder, ise );
+                        throw ise;
+                    }
+
+                    callback.decodeOccurred( decoder, tlv );
+                    if ( BERcallback != null ) BERcallback.end();
+                }
+            }
+        }
+    }
+
+}

Added: labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/ber/TypeClass.java
URL: http://svn.apache.org/viewvc/labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/ber/TypeClass.java?view=auto&rev=538217
==============================================================================
--- labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/ber/TypeClass.java (added)
+++ labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/ber/TypeClass.java Tue May 15 08:29:41 2007
@@ -0,0 +1,174 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.asn1.encoding.ber;
+
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.asn1.runtime.ValuedEnum;
+import org.apache.asn1.runtime.EnumUtils;
+
+
+/**
+ * Type safe enum for an ASN.1 type class.  This can be take one of the
+ * following four values:
+ * <ul>
+ * <li>UNIVERSAL</li>
+ * <li>APPLICATION</li>
+ * <li>CONTEXT_SPECIFIC</li>
+ * <li>PRIVATE</li>
+ * </ul>
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org" Apache Directory Project</a>
+ * @version $Rev: 531149 $
+ */
+public class TypeClass extends ValuedEnum
+{
+    /**
+     * value for the universal type class
+     */
+    public static final int UNIVERSAL_VAL = 0;
+    /**
+     * value for the application type class
+     */
+    public static final int APPLICATION_VAL = 0x40;
+    /**
+     * value for the context specific type class
+     */
+    public static final int CONTEXT_SPECIFIC_VAL = 0x80;
+    /**
+     * value for the private type class
+     */
+    public static final int PRIVATE_VAL = 0xc0;
+
+    /**
+     * enum for the universal type class
+     */
+    public static final TypeClass UNIVERSAL = new TypeClass( "UNIVERSAL", UNIVERSAL_VAL );
+    /**
+     * enum for the application type class
+     */
+    public static final TypeClass APPLICATION = new TypeClass( "APPLICATION", APPLICATION_VAL );
+    /**
+     * enum for the context specific type class
+     */
+    public static final TypeClass CONTEXT_SPECIFIC = new TypeClass( "CONTEXT_SPECIFIC", CONTEXT_SPECIFIC_VAL );
+    /**
+     * enum for the private type class
+     */
+    public static final TypeClass PRIVATE = new TypeClass( "PRIVATE", PRIVATE_VAL );
+
+    private static final TypeClass[] map = {UNIVERSAL, null, null, null, APPLICATION, null, null, null, CONTEXT_SPECIFIC, null, null, null, PRIVATE, null, null, null};
+
+    /**
+     * Private constructor so no other instances can be created other than the
+     * public static constants in this class.
+     *
+     * @param name  a string name for the enumeration value.
+     * @param value the integer value of the enumeration.
+     */
+    private TypeClass( final String name, final int value )
+    {
+        super( name, value );
+    }
+
+
+    /**
+     * Gets the enumeration type for the type class regardless of case.
+     *
+     * @param className the type class name
+     * @return the TypeClass for the name
+     */
+    public static TypeClass getTypeClass( String className )
+    {
+        // check first using == since it will be the predominate use case
+        if ( className == APPLICATION.getName() )
+        {
+            return APPLICATION;
+        }
+        else if ( className == CONTEXT_SPECIFIC.getName() )
+        {
+            return CONTEXT_SPECIFIC;
+        }
+        else if ( className == PRIVATE.getName() )
+        {
+            return PRIVATE;
+        }
+        else if ( className == UNIVERSAL.getName() )
+        {
+            return UNIVERSAL;
+        }
+
+        if ( className.equalsIgnoreCase( TypeClass.PRIVATE.getName() ) )
+        {
+            return TypeClass.PRIVATE;
+        }
+
+        if ( className.equalsIgnoreCase( TypeClass.UNIVERSAL.getName() ) )
+        {
+            return TypeClass.UNIVERSAL;
+        }
+
+        if ( className.equalsIgnoreCase( TypeClass.APPLICATION.getName() ) )
+        {
+            return TypeClass.APPLICATION;
+        }
+
+        if ( className.equalsIgnoreCase( TypeClass.CONTEXT_SPECIFIC.getName() ) )
+        {
+            return TypeClass.CONTEXT_SPECIFIC;
+        }
+
+        throw new IllegalArgumentException( "Unknown type class name" + className );
+    }
+
+
+    /**
+     * Gets a List of the enumerations for ASN.1 type classes.
+     *
+     * @return the List of enumerations possible for ASN.1 type classes
+     */
+    public static List list()
+    {
+        return EnumUtils.getEnumList( TypeClass.class );
+    }
+
+
+    /**
+     * Gets the Map of TypeClass objects by name using the TypeClass class.
+     *
+     * @return the Map by name of TypeClass
+     */
+    public static Map map()
+    {
+        return EnumUtils.getEnumMap( TypeClass.class );
+    }
+
+
+    /**
+     * Gets the ASN.1 type's class using a TLV tag.
+     *
+     * @param octet the first octet of the TLV
+     * @return the TypeClass enumeration for the ASN.1 type's class
+     */
+    public static TypeClass getTypeClass( int octet )
+    {
+        return map[( octet & PRIVATE_VAL ) >> 4];
+    }
+}

Added: labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/ber/Util.java
URL: http://svn.apache.org/viewvc/labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/ber/Util.java?view=auto&rev=538217
==============================================================================
--- labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/ber/Util.java (added)
+++ labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/ber/Util.java Tue May 15 08:29:41 2007
@@ -0,0 +1,118 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.asn1.encoding.ber;
+
+/**
+ * Utility methods for BER encoding/decoding.
+ *
+ * @version $Revision: 531142 $ $Date: $
+ */
+public final class Util
+{
+    /**
+     * Increment the length, given the current length and increment.
+     * <p/>
+     * If either are less than zero, meaning that the length is indefinite,
+     * then the incremented length is also less than zero.
+     *
+     * @param original  the current length
+     * @param increment the increment length
+     * @return the incremented length
+     */
+    public static int incrementLength( int original, int increment )
+    {
+        if ( original < 0 || increment < 0 ) return -1;
+        return original + increment;
+    }
+
+    /**
+     * Calculate the total length, which would include the identifier octests
+     * and length octets as well as the contents octets.
+     * <p/>
+     * If length is less than zero, meaning that the length is indefinite,
+     * then the calculated length is also less than zero.
+     *
+     * @param length
+     * @return total length
+     */
+    public static int calculateLength( int tag, int length )
+    {
+        if ( length < 0 ) return -1;
+
+        int result = 1;
+
+        /**
+         * length of tag
+         */
+        if ( tag >= 0x10000000 )
+        {
+            result += 5;
+        }
+        else if ( tag >= 0x200000 )
+        {
+            result += 4;
+        }
+        else if ( tag >= 0x4000 )
+        {
+            result += 3;
+        }
+        else if ( tag >= 0x80 )
+        {
+            result += 2;
+        }
+        else if ( tag >= 0x1F )
+        {
+            result += 1;
+        }
+
+        /**
+         * length of length octets
+         */
+        if ( length >= 0x1000000 )
+        {
+            result += 5;
+        }
+        else if ( length >= 0x10000 )
+        {
+            result += 4;
+        }
+        else if ( length >= 0x100 )
+        {
+            result += 3;
+        }
+        else if ( length >= 0x80 )
+        {
+            result += 2;
+        }
+        else
+        {
+            result++;
+        }
+
+        /**
+         * length of contents
+         */
+        result += length;
+
+        return result;
+    }
+
+    private Util()
+    {
+    }
+}

Added: labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/ber/package.html
URL: http://svn.apache.org/viewvc/labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/ber/package.html?view=auto&rev=538217
==============================================================================
--- labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/ber/package.html (added)
+++ labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/ber/package.html Tue May 15 08:29:41 2007
@@ -0,0 +1,40 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+    <!--
+     * Licensed to the Apache Software Foundation (ASF) under one or more
+     * contributor license agreements.  See the NOTICE file distributed with
+     * this work for additional information regarding copyright ownership.
+     * The ASF licenses this file to You 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.
+    -->
+</head>
+
+<body bgcolor="white">
+
+Provides the codec foundation for Basic Encoding Rules based on a Tag, Length
+and Value (TLV) field tuples.
+
+<h2>Package Specification</h2>
+
+<h2>Related Documentation</h2>
+
+For overviews, tutorials, examples, guides, and tool documentation, please see:
+<ul>
+    <li><a href="http://incubator.apache.org/directory/subprojects/asn1/index.html">ASN1 Project</a>
+    <li><a href="http://incubator.apache.org/directory/subprojects/asn1/ber-codec/index.html">ASN1 BER Codecs</a>
+</ul>
+
+<!-- Put @see and @since tags down here. -->
+
+</body>
+</html>

Added: labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/der/DERDecoder.java
URL: http://svn.apache.org/viewvc/labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/der/DERDecoder.java?view=auto&rev=538217
==============================================================================
--- labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/der/DERDecoder.java (added)
+++ labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/der/DERDecoder.java Tue May 15 08:29:41 2007
@@ -0,0 +1,34 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.asn1.encoding.der;
+
+import org.apache.asn1.encoding.ber.AOKDecoder;
+
+
+/**
+ * A decoder that decodes DER encoded bytes to Tag Value Length (TLV) tuples.
+ * <p/>
+ * Since DER decoding is the same as BER decoding, this decoder simply extends
+ * <code>BERDecoder</code>.
+ *
+ * @version $Revision: 531142 $ $Date: $
+ * @see AOKDecoder
+ */
+public class DERDecoder extends AOKDecoder
+{
+}

Added: labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/der/DERDecoderCallbackAdapter.java
URL: http://svn.apache.org/viewvc/labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/der/DERDecoderCallbackAdapter.java?view=auto&rev=538217
==============================================================================
--- labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/der/DERDecoderCallbackAdapter.java (added)
+++ labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/der/DERDecoderCallbackAdapter.java Tue May 15 08:29:41 2007
@@ -0,0 +1,33 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.asn1.encoding.der;
+
+import org.apache.asn1.encoding.ber.BERDecoderCallbackAdapter;
+
+
+/**
+ * A do nothing callback adapter.
+ * <p/>
+ * Since DER decoding is the same as BER decoding, this callback adaptor simply
+ * extends <code>BERDecoderCallbackAdapter</code>.
+ *
+ * @version $Revision: 531142 $ $Date: $
+ */
+public class DERDecoderCallbackAdapter extends BERDecoderCallbackAdapter
+{
+}

Added: labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/der/DERDecoderMonitor.java
URL: http://svn.apache.org/viewvc/labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/der/DERDecoderMonitor.java?view=auto&rev=538217
==============================================================================
--- labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/der/DERDecoderMonitor.java (added)
+++ labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/der/DERDecoderMonitor.java Tue May 15 08:29:41 2007
@@ -0,0 +1,34 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.asn1.encoding.der;
+
+import org.apache.asn1.encoding.ber.BERDecoderMonitor;
+
+
+/**
+ * A monitor designed for extended DER decoder functionality with greater
+ * detail to specific DER decoder events.
+ * <p/>
+ * Since DER decoding is the same as BER decoding, this monitor simply extends
+ * <code>BERDecoderMonitor</code>.
+ *
+ * @version $Revision: 531142 $ $Date: $
+ */
+public interface DERDecoderMonitor extends BERDecoderMonitor
+{
+}

Added: labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/der/package.html
URL: http://svn.apache.org/viewvc/labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/der/package.html?view=auto&rev=538217
==============================================================================
--- labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/der/package.html (added)
+++ labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/encoding/der/package.html Tue May 15 08:29:41 2007
@@ -0,0 +1,40 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+    <!--
+     * Licensed to the Apache Software Foundation (ASF) under one or more
+     * contributor license agreements.  See the NOTICE file distributed with
+     * this work for additional information regarding copyright ownership.
+     * The ASF licenses this file to You 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.
+    -->
+</head>
+
+<body bgcolor="white">
+
+Provides the codec foundation for Distinguished Encoding Rules based on a Tag, Length
+and Value (TLV) field tuples.
+
+<h2>Package Specification</h2>
+
+<h2>Related Documentation</h2>
+
+For overviews, tutorials, examples, guides, and tool documentation, please see:
+<ul>
+    <li><a href="http://incubator.apache.org/directory/subprojects/asn1/index.html">ASN1 Project</a>
+    <li><a href="http://incubator.apache.org/directory/subprojects/asn1/der-codec/index.html">ASN1 DER Codecs</a>
+</ul>
+
+<!-- Put @see and @since tags down here. -->
+
+</body>
+</html>

Added: labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1BMPString.java
URL: http://svn.apache.org/viewvc/labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1BMPString.java?view=auto&rev=538217
==============================================================================
--- labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1BMPString.java (added)
+++ labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1BMPString.java Tue May 15 08:29:41 2007
@@ -0,0 +1,30 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.asn1.runtime;
+
+
+/**
+ * @version $Revision: 531142 $ $Date: $
+ */
+public class ASN1BMPString implements ASN1Type
+{
+    public boolean isConsistent()
+    {
+        return false;  //todo: consider this autogenerated code
+    }
+}

Added: labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1BitString.java
URL: http://svn.apache.org/viewvc/labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1BitString.java?view=auto&rev=538217
==============================================================================
--- labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1BitString.java (added)
+++ labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1BitString.java Tue May 15 08:29:41 2007
@@ -0,0 +1,76 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.asn1.runtime;
+
+import java.util.BitSet;
+
+
+/**
+ * Implementation of an ASN1 bit string
+ *
+ * @version $Revision: 531142 $ $Date: $
+ */
+public class ASN1BitString extends BitSet implements ASN1Type
+{
+    private final int nbits;
+    private final int nbytes;
+
+    /**
+     * @param nbits
+     * @param nbytes
+     */
+    public ASN1BitString( int nbits, int nbytes )
+    {
+        super( nbits );
+
+        if ( nbits / 8 > nbytes ) throw new IllegalArgumentException( "Number if bits will not fit in given number of bytes" );
+
+        this.nbits = nbits;
+        this.nbytes = nbytes;
+    }
+
+    public final boolean isConsistent()
+    {
+        return length() <= nbits;
+    }
+
+    public final int getNumBits()
+    {
+        return nbytes;
+    }
+
+    public final int getNumBytes()
+    {
+        return nbytes;
+    }
+
+    public final byte[] getBytes()
+    {
+        byte[] result = new byte[nbytes];
+
+        for ( int i = 0; i < nbits + 1; i++ )
+        {
+            if ( get( i ) )
+            {
+                result[i / 8] |= 1 << ( 7 - ( i % 8 ) );
+            }
+        }
+
+        return result;
+    }
+}

Added: labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1GeneralString.java
URL: http://svn.apache.org/viewvc/labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1GeneralString.java?view=auto&rev=538217
==============================================================================
--- labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1GeneralString.java (added)
+++ labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1GeneralString.java Tue May 15 08:29:41 2007
@@ -0,0 +1,30 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.asn1.runtime;
+
+
+/**
+ * @version $Revision: 531142 $ $Date: $
+ */
+public class ASN1GeneralString implements ASN1Type
+{
+    public boolean isConsistent()
+    {
+        return false;  //todo: consider this autogenerated code
+    }
+}

Added: labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1GraphicString.java
URL: http://svn.apache.org/viewvc/labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1GraphicString.java?view=auto&rev=538217
==============================================================================
--- labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1GraphicString.java (added)
+++ labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1GraphicString.java Tue May 15 08:29:41 2007
@@ -0,0 +1,30 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.asn1.runtime;
+
+
+/**
+ * @version $Revision: 531142 $ $Date: $
+ */
+public class ASN1GraphicString implements ASN1Type
+{
+    public boolean isConsistent()
+    {
+        return false;  //todo: consider this autogenerated code
+    }
+}

Added: labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1IA5String.java
URL: http://svn.apache.org/viewvc/labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1IA5String.java?view=auto&rev=538217
==============================================================================
--- labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1IA5String.java (added)
+++ labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1IA5String.java Tue May 15 08:29:41 2007
@@ -0,0 +1,30 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.asn1.runtime;
+
+
+/**
+ * @version $Revision: 531142 $ $Date: $
+ */
+public class ASN1IA5String implements ASN1Type
+{
+    public boolean isConsistent()
+    {
+        return false;  //todo: consider this autogenerated code
+    }
+}

Added: labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1NumericString.java
URL: http://svn.apache.org/viewvc/labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1NumericString.java?view=auto&rev=538217
==============================================================================
--- labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1NumericString.java (added)
+++ labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1NumericString.java Tue May 15 08:29:41 2007
@@ -0,0 +1,30 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.asn1.runtime;
+
+
+/**
+ * @version $Revision: 531142 $ $Date: $
+ */
+public class ASN1NumericString implements ASN1Type
+{
+    public boolean isConsistent()
+    {
+        return false;  //todo: consider this autogenerated code
+    }
+}

Added: labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1ObjectIdentifier.java
URL: http://svn.apache.org/viewvc/labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1ObjectIdentifier.java?view=auto&rev=538217
==============================================================================
--- labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1ObjectIdentifier.java (added)
+++ labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1ObjectIdentifier.java Tue May 15 08:29:41 2007
@@ -0,0 +1,72 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.asn1.runtime;
+
+import java.util.StringTokenizer;
+
+
+/**
+ * @version $Revision: 531142 $ $Date: $
+ */
+public class ASN1ObjectIdentifier implements ASN1Type
+{
+    private final int id[];
+
+    public ASN1ObjectIdentifier( ASN1ObjectIdentifier oid )
+    {
+        this.id = oid.id;
+    }
+
+    public ASN1ObjectIdentifier( String oid )
+    {
+        StringTokenizer tokenizer = new StringTokenizer( oid, "." );
+        this.id = new int[tokenizer.countTokens()];
+        for ( int i = 0; tokenizer.hasMoreTokens(); i++ )
+        {
+            id[i] = Integer.parseInt( tokenizer.nextToken() );
+        }
+    }
+
+    public ASN1ObjectIdentifier( int id[] )
+    {
+        this.id = new int[id.length];
+        System.arraycopy( id, 0, this.id, 0, id.length );
+    }
+
+    public ASN1ObjectIdentifier( ASN1ObjectIdentifier oid, int id[] )
+    {
+        this.id = new int[oid.id.length + id.length];
+        System.arraycopy( oid.id, 0, this.id, 0, oid.id.length );
+        System.arraycopy( id, 0, this.id, oid.id.length, id.length );
+    }
+
+    public int getId( int index )
+    {
+        return id[index];
+    }
+
+    public int size()
+    {
+        return id.length;
+    }
+
+    public boolean isConsistent()
+    {
+        return true;
+    }
+}

Added: labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1OctetString.java
URL: http://svn.apache.org/viewvc/labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1OctetString.java?view=auto&rev=538217
==============================================================================
--- labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1OctetString.java (added)
+++ labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1OctetString.java Tue May 15 08:29:41 2007
@@ -0,0 +1,55 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.asn1.runtime;
+
+/**
+ * @version $Revision: 531142 $ $Date: $
+ */
+public class ASN1OctetString implements ASN1Type
+{
+    private byte[] octetString;
+
+    public ASN1OctetString( byte[] octetString )
+    {
+        this.octetString = octetString;
+    }
+
+    public byte[] getOctetString()
+    {
+        return octetString;
+    }
+
+    public boolean isConsistent()
+    {
+        return true;
+    }
+
+    public boolean equals( Object obj )
+    {
+        if ( !( obj instanceof ASN1OctetString ) ) return false;
+
+        ASN1OctetString ASN1OctetString = (ASN1OctetString) obj;
+
+        return ASN1Util.equals( octetString, ASN1OctetString.octetString );
+    }
+
+    public int hashCode()
+    {
+        return ASN1Util.hashCode( octetString );
+    }
+}

Added: labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1PrintableString.java
URL: http://svn.apache.org/viewvc/labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1PrintableString.java?view=auto&rev=538217
==============================================================================
--- labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1PrintableString.java (added)
+++ labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1PrintableString.java Tue May 15 08:29:41 2007
@@ -0,0 +1,30 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.asn1.runtime;
+
+
+/**
+ * @version $Revision: 531142 $ $Date: $
+ */
+public class ASN1PrintableString implements ASN1Type
+{
+    public boolean isConsistent()
+    {
+        return false;  //todo: consider this autogenerated code
+    }
+}

Added: labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1SequenceOf.java
URL: http://svn.apache.org/viewvc/labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1SequenceOf.java?view=auto&rev=538217
==============================================================================
--- labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1SequenceOf.java (added)
+++ labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1SequenceOf.java Tue May 15 08:29:41 2007
@@ -0,0 +1,126 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.asn1.runtime;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedList;
+
+
+/**
+ * @version $Revision: 531142 $ $Date: $
+ */
+abstract public class ASN1SequenceOf extends LinkedList implements ASN1Type
+{
+    abstract protected boolean instanceOf( Object o );
+
+    /**
+     * Ensures that this collection contains the specified element (optional
+     * operation).  Returns <tt>true</tt> if this collection changed as a
+     * result of the call.  (Returns <tt>false</tt> if this collection does
+     * not permit duplicates and already contains the specified element.)<p>
+     * <p/>
+     * Collections that support this operation may place limitations on what
+     * elements may be added to this collection.  In particular, some
+     * collections will refuse to add <tt>null</tt> elements, and others will
+     * impose restrictions on the type of elements that may be added.
+     * Collection classes should clearly specify in their documentation any
+     * restrictions on what elements may be added.<p>
+     * <p/>
+     * If a collection refuses to add a particular element for any reason
+     * other than that it already contains the element, it <i>must</i> throw
+     * an exception (rather than returning <tt>false</tt>).  This preserves
+     * the invariant that a collection always contains the specified element
+     * after this call returns.
+     *
+     * @param o element whose presence in this collection is to be ensured.
+     * @return <tt>true</tt> if this collection changed as a result of the
+     *         call
+     * @throws UnsupportedOperationException <tt>add</tt> is not supported by
+     *                                       this collection.
+     * @throws ClassCastException            class of the specified element prevents it
+     *                                       from being added to this collection.
+     * @throws NullPointerException          if the specified element is null and this
+     *                                       collection does not support null elements.
+     * @throws IllegalArgumentException      some aspect of this element prevents
+     *                                       it from being added to this collection.
+     */
+    public boolean add( Object o )
+    {
+        if ( !instanceOf( o ) ) throw new IllegalArgumentException( "Not a valid instance" );
+        return super.add( o );
+    }
+
+    /**
+     * Removes a single instance of the specified element from this
+     * collection, if it is present (optional operation).  More formally,
+     * removes an element <tt>e</tt> such that <tt>(o==null ?  e==null :
+     * o.equals(e))</tt>, if this collection contains one or more such
+     * elements.  Returns true if this collection contained the specified
+     * element (or equivalently, if this collection changed as a result of the
+     * call).
+     *
+     * @param o element to be removed from this collection, if present.
+     * @return <tt>true</tt> if this collection changed as a result of the
+     *         call
+     * @throws ClassCastException            if the type of the specified element
+     *                                       is incompatible with this collection (optional).
+     * @throws NullPointerException          if the specified element is null and this
+     *                                       collection does not support null elements (optional).
+     * @throws UnsupportedOperationException remove is not supported by this
+     *                                       collection.
+     */
+    public boolean remove( Object o )
+    {
+        if ( !instanceOf( o ) ) throw new IllegalArgumentException( "Not a valid instance" );
+        return super.add( o );
+    }
+
+    /**
+     * Adds all of the elements in the specified collection to this collection
+     * (optional operation).  The behavior of this operation is undefined if
+     * the specified collection is modified while the operation is in progress.
+     * (This implies that the behavior of this call is undefined if the
+     * specified collection is this collection, and this collection is
+     * nonempty.)
+     *
+     * @param c elements to be inserted into this collection.
+     * @return <tt>true</tt> if this collection changed as a result of the
+     *         call
+     * @throws UnsupportedOperationException if this collection does not
+     *                                       support the <tt>addAll</tt> method.
+     * @throws ClassCastException            if the class of an element of the specified
+     *                                       collection prevents it from being added to this collection.
+     * @throws NullPointerException          if the specified collection contains one
+     *                                       or more null elements and this collection does not support null
+     *                                       elements, or if the specified collection is <tt>null</tt>.
+     * @throws IllegalArgumentException      some aspect of an element of the
+     *                                       specified collection prevents it from being added to this
+     *                                       collection.
+     * @see #add(Object)
+     */
+    public boolean addAll( Collection c )
+    {
+        Iterator iter = c.iterator();
+        while ( iter.hasNext() )
+        {
+            if ( !instanceOf( iter.next() ) ) throw new IllegalArgumentException( "Not a valid instance" );
+        }
+        return super.addAll( c );
+    }
+}

Added: labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1TeletexString.java
URL: http://svn.apache.org/viewvc/labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1TeletexString.java?view=auto&rev=538217
==============================================================================
--- labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1TeletexString.java (added)
+++ labs/dungeon/trunk/asn1-runtime/src/main/java/org/apache/asn1/runtime/ASN1TeletexString.java Tue May 15 08:29:41 2007
@@ -0,0 +1,30 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.asn1.runtime;
+
+
+/**
+ * @version $Revision: 531142 $ $Date: $
+ */
+public class ASN1TeletexString implements ASN1Type
+{
+    public boolean isConsistent()
+    {
+        return true;
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org