directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r159166 - in directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv: ./ ITLVBerDecoderMBean.java Length.java TLV.java TLVFactory.java TLVStateEnum.java Tag.java UniversalTag.java Value.java
Date Sun, 27 Mar 2005 18:41:34 GMT
Author: elecharny
Date: Sun Mar 27 10:41:32 2005
New Revision: 159166

URL: http://svn.apache.org/viewcvs?view=rev&rev=159166
Log: (empty)


Added:
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/ITLVBerDecoderMBean.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Length.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/TLV.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/TLVFactory.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/TLVStateEnum.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Tag.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/UniversalTag.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Value.java

Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/ITLVBerDecoderMBean.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/ITLVBerDecoderMBean.java?view=auto&rev=159166
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/ITLVBerDecoderMBean.java
(added)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/ITLVBerDecoderMBean.java
Sun Mar 27 10:41:32 2005
@@ -0,0 +1,66 @@
+/*
+ *   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.asn1.ber.tlv;
+
+import org.apache.asn1.ldap.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 
+    */
+    public 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 
+    */
+    public void setMaxTagLength( int length );
+
+    /** Allow indefinite length. */
+    public void allowIndefiniteLength();
+
+    /** Disallow indefinite length. */
+    public void disallowIndefiniteLength();
+
+    /** Get the actual maximum number of bytes that can be used to encode the Length
+     *  
+     * @return The maximum bytes of the Length
+    */
+    public int getMaxLengthLength();
+
+    /** Get the actual maximum number of bytes that can be used to encode the Tag 
+     * @return The maximum length of the Tag
+    */
+    public int getMaxTagLength();
+
+    /** Tell if indefinite length form could be used for Length 
+     * @return <code>true</code> if the Indefinite form is allowed
+    */
+    public boolean isIndefiniteLengthAllowed();
+}

Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Length.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Length.java?view=auto&rev=159166
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Length.java (added)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Length.java Sun
Mar 27 10:41:32 2005
@@ -0,0 +1,200 @@
+/*
+ *   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.asn1.ber.tlv;
+
+import java.io.Serializable;
+
+
+/**
+ * The Length part of a TLV.
+ * 
+ * @author   <a href="mailto:dev@directory.apache.org">Apache
+ *           Directory Project</a>
+ */
+public class Length implements Cloneable, Serializable
+{
+    //~ Static fields/initializers -----------------------------------------------------------------
+
+    /** A mask to get the Length form */
+    public static final transient int LENGTH_LONG_FORM          = 0x0080;
+
+    /** Value of the reserved extension */
+    public static final transient int LENGTH_EXTENSION_RESERVED = 0x7F;
+
+    /** A mask to get the long form value */
+    public static final transient int SHORT_MASK = 0x007F;
+
+    //~ Instance fields ----------------------------------------------------------------------------
+
+    /** The expected length of the following value */
+    private int length;
+
+    /** The size of the Length part */
+    private int size;
+
+    /** If the Length is in a long form, this variable store the expected
+     * number of bytes to be read to obtain the length */
+    private transient int expectedLength;
+
+    /** Stores the number of bytes already read for a long Length form */
+    private int currentLength;
+
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new object.
+    */
+    public Length()
+    {
+        length         = 0;
+        expectedLength = 1;
+        currentLength  = 0;
+        size           = 0;
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Reset the Length object
+     */
+    public void reset()
+    {
+        length         = 0;
+        expectedLength = 0;
+        currentLength  = 0;
+        size           = 0;
+    }
+
+    /**
+     * @return Returns the length of the value part.
+     */
+    public int getLength()
+    {
+
+        return length;
+    }
+
+    /**
+     * Set the length of the Value part 
+     *
+     * @param length The length of the Value part.
+     */
+    public void setLength( int length )
+    {
+        this.length = length;
+    }
+
+    /**
+     * @return Returns the currentLength.
+     */
+    public int getCurrentLength()
+    {
+
+        return currentLength;
+    }
+
+    /**
+     * Set the current length of the Length
+     *
+     * @param currentLength The currentLength to set.
+     */
+    public void setCurrentLength( int currentLength )
+    {
+        this.currentLength = currentLength;
+    }
+
+    /**
+     * Increment the Length being read
+     */
+    public void incCurrentLength()
+    {
+        this.currentLength++;
+    }
+
+    /**
+     * @return Returns the expected Length of the Length.
+     */
+    public int getExpectedLength()
+    {
+        return expectedLength;
+    }
+
+    /**
+     * Set the expected length
+     *
+     * @param expectedLength The expectedLength to set.
+     */
+    public void setExpectedLength( int expectedLength )
+    {
+        this.expectedLength = expectedLength;
+    }
+
+    /**
+     * Clone the object
+     *
+     * @return A deep copy of the Length
+     *
+     * @throws CloneNotSupportedException Thrown if any problem occurs.
+     */
+    public Object clone() throws CloneNotSupportedException
+    {
+
+        return super.clone();
+    }
+
+    /**
+     * @return Returns the size of the Length element.
+     */
+    public int getSize()
+    {
+
+        return size;
+    }
+
+    /**
+     * Increment the size of the Length element.
+     */
+    public void incSize()
+    {
+        this.size++;
+    }
+
+    /**
+     * Return a String representing the Length
+     *
+     * @return The length
+     */
+    public String toString()
+    {
+
+        StringBuffer sb = new StringBuffer();
+        sb.append( "LENGTH[" ).append( length ).append( "](size=" ).append( size ).append(
+            ")" );
+
+        return sb.toString();
+    }
+
+    /**
+     * Set the Length's size
+     *
+     * @param size The lengthSize to set.
+     */
+    public void setSize( int size )
+    {
+        this.size = size;
+    }
+}

Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/TLV.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/TLV.java?view=auto&rev=159166
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/TLV.java (added)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/TLV.java Sun Mar
27 10:41:32 2005
@@ -0,0 +1,149 @@
+/*
+ *   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.asn1.ber.tlv;
+
+import org.apache.asn1.util.pools.PoolObject;
+
+/**
+ * This class is used to store Tag, Length and Value decoded from a PDU.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class TLV extends PoolObject
+{
+    //~ Static fields/initializers -----------------------------------------------------------------
+
+
+    //~ Instance fields ----------------------------------------------------------------------------
+
+    /** The current Tag being processed */
+    private Tag tag;
+
+    /** The current Length being processed */
+    private Length length;
+
+    /** The current Value being processed */
+    private Value value;
+
+    /** The expected Length is the addition of the Tag length, the Length
+     * length and the expected Value length.
+     * The TLV size is calculated by adding the Tag's size, the Length's
+     * size and the Value's size, if any */
+    private int size;
+
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new TLV object.
+     */
+    public TLV()
+    {
+        tag      = new Tag();
+
+        length   = new Length();
+        value    = new Value();
+        size = 0;
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Reset the TLV, so it can be reused for the next PDU decoding.
+     */
+    public void reset()
+    {
+        tag.reset();
+        length.reset();
+        value.reset();
+        size = 0;
+    }
+
+    /**
+     * @return Returns the length.
+     */
+    public Length getLength()
+    {
+        return length;
+    }
+
+    /**
+     * Add the TLV Length part
+     *
+     * @param length The length to set.
+     */
+    public void setLength1( Length length )
+    {
+        this.length = length;
+        
+        // The TLV size will be equal to this sum :
+        //	Tag size + Length size
+        //  + Value size which is given by the Length length.
+        size += length.getSize() + length.getLength();
+    }
+
+    /**
+     *  @return Returns the tag.
+     */
+    public Tag getTag()
+    {
+        return tag;
+    }
+
+    /**
+     * @return Returns the value.
+     */
+    public Value getValue()
+    {
+        return value;
+    }
+
+    /**
+     * Get a String representation of the TLV
+     *
+     * @return A String
+     */
+    public String toString()
+    {
+
+        StringBuffer sb = new StringBuffer();
+
+        sb.append( "TLV[ " );
+        sb.append( tag.toString() ).append( ", " );
+        sb.append( length.toString() ).append( ", " );
+        sb.append( value.toString() );
+
+        sb.append( "]" );
+
+        return sb.toString();
+    }
+
+    /**
+     * Free the TLV.
+     */
+    public void free()
+    {
+    	reset();
+        super.free();
+    }
+
+	/**
+	 * @return Returns the size of the TLV.
+	 */
+	public int getSize() {
+		return tag.getSize() + length.getSize() + length.getExpectedLength();
+	}
+}

Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/TLVFactory.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/TLVFactory.java?view=auto&rev=159166
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/TLVFactory.java
(added)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/TLVFactory.java
Sun Mar 27 10:41:32 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.asn1.ber.tlv;
+
+import org.apache.asn1.util.ObjectFactory;
+import org.apache.asn1.util.pools.PoolObject;
+
+
+/**
+ * Create a TLV object
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class TLVFactory implements ObjectFactory
+{
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * The method that creates the object
+     *
+     * @return The created object
+     */
+    public PoolObject makeObject()
+    {
+        return new TLV();
+    }
+}

Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/TLVStateEnum.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/TLVStateEnum.java?view=auto&rev=159166
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/TLVStateEnum.java
(added)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/TLVStateEnum.java
Sun Mar 27 10:41:32 2005
@@ -0,0 +1,64 @@
+/*
+ *   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.asn1.ber.tlv;
+
+/**
+ * Stores the different states of a PDU parsing.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class TLVStateEnum
+{
+    //~ Static fields/initializers -----------------------------------------------------------------
+
+    /** Start means that the deconding hasn't read the first byte */
+    public static final int TAG_STATE_START = 0x00;
+
+    /** Pending means that the Type Tag is contained in more that one byte */
+    public static final int TAG_STATE_PENDING = 0x01;
+
+    /** End means that the Type is totally read */
+    public static final int TAG_STATE_END = 0x02;
+
+    /**
+     * Overflow could have two meaning : either there are more than 5 bytes to
+     * encode the value (5 bytes = 5bits + 4*7 bits = 33 bits) or the value that
+     * is represented by those bytes is over MAX_INTEGER
+     */
+    public static final int TAG_STATE_OVERFLOW = 0x04;
+
+    /** Start means that the decoding hasn't read the first byte */
+    public static final int LENGTH_STATE_START = 0x08;
+
+    /** Pending means that the Type length is contained in more that one byte */
+    public static final int LENGTH_STATE_PENDING = 0x10;
+
+    /** End means that the Length is totally read */
+    public static final int LENGTH_STATE_END    = 0x20;
+
+    /** Start means that the decoding hasn't read the first byte */
+    public static final int VALUE_STATE_START   = 0x40;
+
+    /** Pending means that the Type Value is contained in more that one byte */
+    public static final int VALUE_STATE_PENDING = 0x80;
+
+    /** End means that the Value is totally read */
+    public static final int VALUE_STATE_END = 0x100;
+
+    /** The decoding of a TLV is done */
+    public static final int TLV_STATE_DONE = 0x200;
+}

Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Tag.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Tag.java?view=auto&rev=159166
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Tag.java (added)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Tag.java Sun Mar
27 10:41:32 2005
@@ -0,0 +1,378 @@
+/*
+ *   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.asn1.ber.tlv;
+
+import org.apache.asn1.util.pools.PoolObject;
+
+import java.io.Serializable;
+
+
+/**
+ * The Tag component of a BER TLV Tuple.
+ *
+ * @author   <a href="mailto:dev@directory.apache.org">Apache
+ *           Directory Project</a>
+ */
+public class Tag extends PoolObject implements Cloneable, Serializable
+{
+    //~ Static fields/initializers -----------------------------------------------------------------
+
+    /** tag flag for the primitive/constructed bit - 0010 0000 - 0x20 */
+    public static final transient int CONSTRUCTED_FLAG = 0x20;
+
+    /** tag mask for the short tag format - 0001 1111 - 0x1F */
+    public static final transient int SHORT_MASK = 0x1F;
+
+    /** tag mask for the long tag format - 0111 1111 - 0x7F */
+    public static final transient int LONG_MASK = 0x7F;
+
+    /** tag flag indicating the use of the long tag encoding form */
+    public static final transient int LONG_FLAG = 0x80;
+
+    /** the max id size with one tag octet */
+    public static final transient int ONE_OCTET_IDMAX = 30;
+
+    /** the max id size with two tag octets */
+    public static final transient int TWO_OCTET_IDMAX = ( 1 << 7 ) - 1;
+
+    /** the max id size with three tag octets */
+    public static final transient int THREE_OCTET_IDMAX = ( 1 << 14 ) - 1;
+
+    /** the max id size with four tag octets */
+    public static final transient int FOUR_OCTET_IDMAX = ( 1 << 21 ) - 1;
+
+    /** the bit that signal that the value will overflow */
+    public static final transient int TAG_MAX_FLAG = ( 1 << 26 );
+
+    /** value for the universal type class */
+    public static final transient int TYPE_CLASS_UNIVERSAL = 0;
+
+    /** value for the application type class */
+    public static final transient int TYPE_CLASS_APPLICATION = 1;
+
+    /** value for the context specific type class */
+    public static final transient int TYPE_CLASS_CONTEXT_SPECIFIC = 2;
+
+    /** value for the private type class */
+    public static final transient int TYPE_CLASS_PRIVATE = 3;
+
+    /** mask to get the type class value */
+    public static final transient int TYPE_CLASS_MASK = 0xC0;
+
+    /**
+     * The maximum bytes number that could be used to hold the value. Actually,
+     * it's five : - 7 bits x 4 bytes = 28 bits, which is not enough to
+     * represent an int. - 7 bits x 5 bytes = 35 bits, which is just above int's
+     * number of bits Note : the higher bit is not used.
+     */
+    public static final transient int MAX_TAG_BYTES = 5;
+
+    /** array of the different Type classes */
+    public static final int[] TYPE_CLASS =
+    {
+        Tag.TYPE_CLASS_UNIVERSAL, Tag.TYPE_CLASS_APPLICATION, Tag.TYPE_CLASS_CONTEXT_SPECIFIC,
+        Tag.TYPE_CLASS_PRIVATE
+    };
+
+    //~ Instance fields ----------------------------------------------------------------------------
+
+    /** the int used to store the tag octets */
+    private int id;
+
+    /** the number of octets currently read */
+    private int size;
+
+    /** whether or not this tag represents a primitive type */
+    private boolean isPrimitive;
+
+    /** the type class of this tag */
+    private int typeClass;
+
+    /** The bytes read from the PDU. We store only 5 bytes, so we can't have tag that are
+     * above 2^28 */
+    private byte[] tagBytes = new byte[] { 0, 0, 0, 0, 0 };
+
+    /** Current position in the tagBytes */
+    private int bytePos = 0;
+
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new Tag object.
+     */
+    public Tag()
+    {
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Reset the tag so that it can be reused. 
+     */
+    public void reset()
+    {
+        id          = 0;
+        size        = 0;
+        isPrimitive = false;
+        typeClass   = Tag.TYPE_CLASS_APPLICATION;
+        tagBytes[0] = 0;
+        tagBytes[1] = 0;
+        tagBytes[2] = 0;
+        tagBytes[3] = 0;
+        tagBytes[4] = 0;
+        bytePos     = 0;
+    }
+
+    /**
+     * Gets the id which represent the tag.
+     *
+     * @return  the id
+     */
+    public int getId()
+    {
+        return id;
+    }
+
+    /**
+     * Set the id.
+     *
+     * @param id The id to be set
+    */
+    public void setId( int id )
+    {
+        this.id = id;
+    }
+
+    /**
+     * Gets the number of octets of this Tag.
+     *
+     * @return  the number of octets of this Tag
+     */
+    public int getSize()
+    {
+        return size;
+    }
+
+    /**
+     * Gets the number of octets in this Tag.
+     *
+     * @param size The size of the tag
+    */
+    public void setSize( int size )
+    {
+        this.size = size;
+    }
+
+    /**
+     * Gets the number of octets in this Tag.
+     *
+     * */
+    public void incTagSize()
+    {
+        this.size++;
+    }
+
+    /**
+     * Gets the type class for this Tag.
+     *
+     * @return  The typeClass for this Tag
+     */
+    public int getTypeClass()
+    {
+        return typeClass;
+    }
+
+    /**
+     * Gets the type class for this Tag.
+     *
+     * @param typeClass The TypeClass to set
+    */
+    public void setTypeClass( int typeClass )
+    {
+        this.typeClass = typeClass;
+    }
+
+    /**
+     * Checks to see if the tag is constructed.
+     *
+     * @return  true if constructed, false if primitive
+     */
+    public boolean isConstructed()
+    {
+        return ! isPrimitive;
+    }
+
+    /**
+     * 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
+     */
+    public boolean isPrimitive()
+    {
+        return isPrimitive;
+    }
+
+    /**
+     * Tells if the tag is Universal or not
+     * @return  true if it is primitive, false if it is constructed
+     */
+    public boolean isUniversal()
+    {
+        return typeClass == TYPE_CLASS_UNIVERSAL;
+    }
+
+    /**
+     * Tells if the tag class is Application or not
+     *
+     * @return  true if it is Application, false otherwise.
+     */
+    public boolean isApplication()
+    {
+        return typeClass == TYPE_CLASS_APPLICATION;
+    }
+
+    /**
+     * Tells if the tag class is Private or not
+     *
+     * @return  true if it is Private, false otherwise.
+     */
+    public boolean isPrivate()
+    {
+        return typeClass == TYPE_CLASS_PRIVATE;
+    }
+
+    /**
+     * Tells if the tag class is Contextual or not
+     *
+     * @return  true if it is Contextual, false otherwise.
+     */
+    public boolean isContextual()
+    {
+        return typeClass == TYPE_CLASS_CONTEXT_SPECIFIC;
+    }
+
+    /**
+     * Set the tag type to Primitive or Constructed
+     *
+     * @param isPrimitive The type to set
+    */
+    public void setPrimitive( boolean isPrimitive )
+    {
+        this.isPrimitive = isPrimitive;
+    }
+
+    /**
+     * Add a byte to the inner representation of the tag.
+     *
+     * @param octet The byte to add.
+     */
+    public void addByte( byte octet )
+    {
+        tagBytes[bytePos++] = octet;
+    }
+
+    /**
+     * Get the first byte of the tag.
+     *
+     * @return The first byte of the tag.
+     */
+    public byte getTagByte()
+    {
+        return tagBytes[0];
+    }
+
+    /**
+     * @return Get all the bytes of the tag
+     */
+    public byte[] getTagBytes()
+    {
+        return tagBytes;
+    }
+
+    /**
+     * Get the byte at a specific position of the tag's bytes
+     *
+     * @param pos The position
+     *
+     * @return The byte found
+     */
+    public byte getTagBytes( int pos )
+    {
+        return tagBytes[pos];
+    }
+
+    /**
+     * Clone the Tag
+     *
+     * @return A copy of the tag
+     *
+     * @throws CloneNotSupportedException Thrown if we have a cloning problem 
+     */
+    public Object clone() throws CloneNotSupportedException
+    {
+        return super.clone();
+    }
+
+    /**
+     * A string representation of a Tag
+     *
+     * @return A string representation of a Tag
+     */
+    public String toString()
+    {
+        StringBuffer sb = new StringBuffer();
+        sb.append( "TAG[" );
+
+        if ( isPrimitive )
+        {
+            sb.append( "PRIMITIVE, " );
+        }
+        else
+        {
+            sb.append( "CONSTRUCTED, " );
+        }
+
+        switch ( typeClass )
+        {
+
+            case TYPE_CLASS_APPLICATION :
+                sb.append( "APPLICATION, " );
+
+                break;
+
+            case TYPE_CLASS_UNIVERSAL :
+                sb.append( "UNIVERSAL, " ).append( UniversalTag.toString( id ) );
+
+                break;
+
+            case TYPE_CLASS_PRIVATE :
+                sb.append( "PRIVATE, " ).append( id );
+
+                break;
+
+            case TYPE_CLASS_CONTEXT_SPECIFIC :
+                sb.append( "CONTEXTUAL, " ).append( id );
+
+                break;
+        }
+
+        sb.append( "](size=" ).append( size ).append( ")" );
+
+        return sb.toString();
+    }
+} // end interface ITag

Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/UniversalTag.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/UniversalTag.java?view=auto&rev=159166
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/UniversalTag.java
(added)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/UniversalTag.java
Sun Mar 27 10:41:32 2005
@@ -0,0 +1,353 @@
+/*
+ *   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.asn1.ber.tlv;
+
+/**
+ * Enum for ASN.1 UNIVERSAL class tags.  The tags values are
+ * constructed using the SNACC representation for tags without the
+ * primitive/constructed bit.  This is done because several bit, octet and
+ * character string types can be encoded as primitives or as constructed types
+ * to chunk the value out.
+ *
+ * <p>These tags can have one of the following values:</p>
+ *
+ * <p></p>
+ *
+ * <table border="1" cellspacing="1" width="60%">
+ *   <tr>
+ *     <th>Id</th>
+ *     <th>Usage</th>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 0]</td>
+ *     <td>reserved for BER</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 1]</td>
+ *     <td>BOOLEAN</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 2]</td>
+ *     <td>INTEGER</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 3]</td>
+ *     <td>BIT STRING</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 4]</td>
+ *     <td>OCTET STRING</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 5]</td>
+ *     <td>NULL</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 6]</td>
+ *     <td>OBJECT IDENTIFIER</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 7]</td>
+ *     <td>ObjectDescriptor</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 8]</td>
+ *     <td>EXTERNAL, INSTANCE OF</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 9]</td>
+ *     <td>REAL</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 10]</td>
+ *     <td>ENUMERATED</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 11]</td>
+ *     <td>EMBEDDED PDV</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 12]</td>
+ *     <td>UTF8String</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 13]</td>
+ *     <td>RELATIVE-OID</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 14]</td>
+ *     <td>reserved for future use</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 15]</td>
+ *     <td>reserved for future use</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 16]</td>
+ *     <td>SEQUENCE, SEQUENCE OF</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 17]</td>
+ *     <td>SET, SET OF</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 18]</td>
+ *     <td>NumericString</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 19]</td>
+ *     <td>PrintableString</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 20]</td>
+ *     <td>TeletexString, T61String</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 21]</td>
+ *     <td>VideotexString</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 22]</td>
+ *     <td>IA5String</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 23]</td>
+ *     <td>UTCTime</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 24]</td>
+ *     <td>GeneralizedTime</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 25]</td>
+ *     <td>GraphicString</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 26]</td>
+ *     <td>VisibleString, ISO646String</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 27]</td>
+ *     <td>GeneralString</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 28]</td>
+ *     <td>UniversalString</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 29]</td>
+ *     <td>CHARACTER STRING</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 30]</td>
+ *     <td>BMPString</td>
+ *   </tr>
+ *
+ *   <tr>
+ *     <td>[UNIVERSAL 31]</td>
+ *     <td>reserved for future use</td>
+ *   </tr>
+ * </table>
+ *
+ * @author   <a href="mailto:dev@directory.apache.org">Apache
+ *           Directory Project</a>
+ */
+public class UniversalTag
+{
+    //~ Static fields/initializers -----------------------------------------------------------------
+
+    /** value for the tag */
+    public static final int RESERVED_0 = 0;
+
+    /** value for the tag */
+    public static final int BOOLEAN = 1;
+
+    /** value for the tag */
+    public static final int INTEGER = 2;
+
+    /** value for the tag */
+    public static final int BIT_STRING = 3;
+
+    /** value for the tag */
+    public static final int OCTET_STRING = 4;
+
+    /** value for the tag */
+    public static final int NULL = 5;
+
+    /** value for the tag */
+    public static final int OBJECT_IDENTIFIER = 6;
+
+    /** value for the tag */
+    public static final int OBJECT_DESCRIPTOR = 7;
+
+    /** value for the tag */
+    public static final int EXTERNAL_INSTANCE_OF = 8;
+
+    /** value for the tag */
+    public static final int REAL = 9;
+
+    /** value for the tag */
+    public static final int ENUMERATED = 10;
+
+    /** value for the tag */
+    public static final int EMBEDDED_PDV = 11;
+
+    /** value for the tag */
+    public static final int UTF8_STRING = 12;
+
+    /** value for the tag */
+    public static final int RELATIVE_OID = 13;
+
+    /** value for the tag */
+    public static final int RESERVED_14 = 14;
+
+    /** value for the tag */
+    public static final int RESERVED_15 = 15;
+
+    /** value for the tag */
+    public static final int SEQUENCE_SEQUENCE_OF = 16;
+
+    /** value for the tag */
+    public static final int SET_SET_OF = 17;
+
+    /** value for the tag */
+    public static final int NUMERIC_STRING = 18;
+
+    /** value for the tag */
+    public static final int PRINTABLE_STRING = 19;
+
+    /** value for the tag */
+    public static final int TELETEX_STRING = 20;
+
+    /** value for the tag */
+    public static final int VIDEOTEX_STRING = 21;
+
+    /** value for the tag */
+    public static final int IA5_STRING = 22;
+
+    /** value for the tag */
+    public static final int UTC_TIME = 23;
+
+    /** value for the tag */
+    public static final int GENERALIZED_TIME = 24;
+
+    /** value for the tag */
+    public static final int GRAPHIC_STRING = 25;
+
+    /** value for the tag */
+    public static final int VISIBLE_STRING = 26;
+
+    /** value for the tag */
+    public static final int GENERAL_STRING = 27;
+
+    /** value for the tag */
+    public static final int UNIVERSAL_STRING = 28;
+
+    /** value for the tag */
+    public static final int CHARACTER_STRING = 29;
+
+    /** value for the tag */
+    public static final int BMP_STRING = 30;
+
+    /** value for the tag */
+    public static final int       RESERVED_31          = 31;
+
+    /** String representation of the tags */
+    private static final String[] UNIVERSAL_TAG_STRING =
+    {
+        "RESERVED_0", 
+		"BOOLEAN", 
+		"INTEGER", 
+		"BIT_STRING", 
+		"OCTET_STRING", 
+		"NULL",
+        "OBJECT_IDENTIFIER", 
+		"OBJECT_DESCRIPTOR", 
+		"EXTERNAL_INSTANCE_OF", 
+		"REAL", 
+		"ENUMERATED",
+        "EMBEDDED_PDV", 
+		"UTF8_STRING", 
+		"RELATIVE_OID", 
+		"RESERVED_14", 
+		"RESERVED_15",
+        "SEQUENCE_SEQUENCE_OF", 
+		"SET_SET_OF", 
+		"NUMERIC_STRING", 
+		"PRINTABLE_STRING",
+        "TELETEX_STRING", 
+		"VIDEOTEX_STRING", 
+		"IA5_STRING", 
+		"UTC_TIME", 
+		"GENERALIZED_TIME",
+        "GRAPHIC_STRING", 
+		"VISIBLE_STRING", 
+		"GENERAL_STRING", 
+		"UNIVERSAL_STRING",
+        "CHARACTER_STRING", 
+		"BMP_STRING", 
+		"RESERVED_31"
+    };
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    // -----------------------------------------------------------------------
+    // Members
+    // -----------------------------------------------------------------------
+    /**
+     * Gets the ASN.1 UNIVERSAL type tag's enum using a tag value.
+     *
+     * @param   tag  the first octet of the TLV
+     *
+     * @return  the valued enum for the ASN.1 UNIVERSAL type tag
+     */
+    public static String toString( int tag )
+    {
+        return UNIVERSAL_TAG_STRING[tag & 0x1F];
+    }
+} // end class UniversalTag

Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Value.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Value.java?view=auto&rev=159166
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Value.java (added)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/tlv/Value.java Sun
Mar 27 10:41:32 2005
@@ -0,0 +1,155 @@
+/*
+ *   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.asn1.ber.tlv;
+
+import org.apache.asn1.util.StringUtils;
+
+import java.io.Serializable;
+
+
+/**
+ * This class stores the data decoded from a TLV.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class Value implements Cloneable, Serializable
+{
+    //~ Instance fields ----------------------------------------------------------------------------
+
+    /** The data buffer.  
+     * TODO Create a streamed data to store large data */
+    private byte[] data;
+
+    /** The current position of the last byte in the data buffer */
+    private int    currentPos;
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Initialize the Value
+     *
+     * @param size The data size to allocate.
+     */
+    public void init( int size )
+    {
+        data       = new byte[size];
+        currentPos = 0;
+    }
+
+    /**
+     * Reset the Value so that it can be reused
+     */
+    public void reset()
+    {
+        data       = null;
+        currentPos = 0;
+    }
+
+    /**
+     * Clone the Value
+     *
+     * @return An object that is a copy of this Value
+     *
+     * @throws CloneNotSupportedException Thrown when the cloning failed
+     */
+    public Object clone() throws CloneNotSupportedException
+    {
+
+        return super.clone();
+    }
+
+    /**
+     * Get the Values'data
+     *
+     * @return Returns the data.
+     */
+    public byte[] getData()
+    {
+        return data;
+    }
+
+    /**
+     * Set a block of bytes in the Value
+     *
+     * @param data The data to set.
+     */
+    public void setData( byte[] data )
+    {
+        System.arraycopy( data, 0, this.data, 0, data.length );
+        currentPos = data.length;
+    }
+
+    /**
+     * Append some bytes to the data buffer. 
+     *
+     * @param data The data to append.
+     */
+    public void addData( byte[] data )
+    {
+        System.arraycopy( data, 0, this.data, currentPos, data.length );
+        currentPos += data.length;
+    }
+
+    /**
+     * @return The number of bytes actually stored
+     */
+    public int getCurrentLength()
+    {
+        return currentPos;
+    }
+
+    /**
+     * Return a string representing the Value
+     *
+     * @return A string representing the value
+     */
+    public String toString()
+    {
+
+        StringBuffer sb = new StringBuffer();
+        sb.append( "DATA" );
+
+        if ( data != null )
+        {
+            sb.append( '[' );
+
+            for ( int i = 0; i < data.length; i++ )
+            {
+
+                int b = ( data[i] & 0x00FF );
+
+                if ( ( b < 32 ) || ( b > 127 ) )
+                {
+                    sb.append( "0x" ).append( StringUtils.dumpByte( ( byte ) b ) );
+                }
+                else
+                {
+                    sb.append( ' ' ).append( ( char ) b );
+                }
+            }
+
+            sb.append( ']' );
+        }
+        else
+        {
+
+            return "[]";
+        }
+
+        return sb.toString();
+    }
+}



Mime
View raw message