directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r440977 - in /directory/sandbox/akarasulu/apacheds-2.0/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber: UniversalTags.java tlv/Value.java tlv/ValueException.java
Date Thu, 07 Sep 2006 05:14:48 GMT
Author: elecharny
Date: Wed Sep  6 22:14:47 2006
New Revision: 440977

URL: http://svn.apache.org/viewvc?view=rev&rev=440977
Log:
Added the class needed to generate the PDUs

Added:
    directory/sandbox/akarasulu/apacheds-2.0/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/UniversalTags.java
    directory/sandbox/akarasulu/apacheds-2.0/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java
    directory/sandbox/akarasulu/apacheds-2.0/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/ValueException.java

Added: directory/sandbox/akarasulu/apacheds-2.0/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/UniversalTags.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/apacheds-2.0/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/UniversalTags.java?view=auto&rev=440977
==============================================================================
--- directory/sandbox/akarasulu/apacheds-2.0/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/UniversalTags.java
(added)
+++ directory/sandbox/akarasulu/apacheds-2.0/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/UniversalTags.java
Wed Sep  6 22:14:47 2006
@@ -0,0 +1,238 @@
+/*
+ *  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.directory.shared.asn1.ber;
+
+/**
+ * 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 enum UniversalTags
+{
+    /** The values */
+    RESERVED_0( (byte)0x00, "RESERVED_0"),
+    BOOLEAN( (byte)0x01, "BOOLEAN"),
+    INTEGER( (byte)0x02, "INTEGER"),
+    BIT_STRING( (byte)0x03, "BIT_STRING"),
+    OCTET_STRING( (byte)0x04, "OCTET_STRING"),
+    NULL( (byte)0x05, "NULL"),
+    OBJECT_IDENTIFIER( (byte)0x06, "OBJECT_IDENTIFIER"),
+    OBJECT_DESCRIPTOR( (byte)0x07, "OBJECT_DESCRIPTOR"),
+    EXTERNAL_INSTANCE_OF( (byte)0x08, "EXTERNAL_INSTANCE_OF"),
+    REAL( (byte)0x09, "REAL"),
+    ENUMERATED( (byte)0x0A, "ENUMERATED"),
+    EMBEDDED_PDV( (byte)0x0B, "EMBEDDED_PDV"),
+    UTF8_STRING( (byte)0x0C, "UTF8_STRING"),
+    RELATIVE_OID( (byte)0x0D, "RELATIVE_OID"),
+    RESERVED_14( (byte)0x0E, "RESERVED_14"),
+    RESERVED_15( (byte)0x0F, "RESERVED_15"),
+    SEQUENCE_SEQUENCE_OF( (byte)0x10, "SEQUENCE_SEQUENCE_OF"),
+    SET_SET_OF( (byte)0x11, "SET_SET_OF"),
+    NUMERIC_STRING( (byte)0x12, "NUMERIC_STRING"),
+    PRINTABLE_STRING( (byte)0x13, "PRINTABLE_STRING"),
+    TELETEX_STRING( (byte)0x14, "TELETEX_STRING"),
+    VIDEOTEX_STRING( (byte)0x15, "VIDEOTEX_STRING"),
+    IA5_STRING( (byte)0x16, "IA5_STRING"),
+    UTC_TIME( (byte)0x17, "UTC_TIME"),
+    GENERALIZED_TIME( (byte)0x18, "GENERALIZED_TIME"),
+    GRAPHIC_STRING( (byte)0x19, "GRAPHIC_STRING"),
+    VISIBLE_STRING( (byte)0x1A, "VISIBLE_STRING"),
+    GENERAL_STRING( (byte)0x1B, "GENERAL_STRING"),
+    UNIVERSAL_STRING( (byte)0x1C, "UNIVERSAL_STRING"),
+    CHARACTER_STRING( (byte)0x1D, "CHARACTER_STRING"),
+    BMP_STRING( (byte)0x1E, "BMP_STRING"),
+    RESERVED_31( (byte)0x1F, "RESERVED_31");
+    
+    /** The byte value for a tag */
+    private byte value;
+    
+    /** The String value of a tag */
+    private String string;
+    
+    /**
+     * Creates a new instance of UniversalTags.
+     *
+     * @param value The byte of the created tag
+     * @param string The String of the created tag
+     */
+    private UniversalTags( byte value, String string )
+    {
+        this.value = value;
+        this.string = string;
+    }
+ 
+    /**
+     * @return The byte associated with this tag
+     */
+    public byte getValue()
+    {
+        return value;
+    }
+    
+    /**
+     * @return The name of this tag
+     */
+    public String getString()
+    {
+        return string;
+    }
+}

Added: directory/sandbox/akarasulu/apacheds-2.0/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/apacheds-2.0/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java?view=auto&rev=440977
==============================================================================
--- directory/sandbox/akarasulu/apacheds-2.0/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java
(added)
+++ directory/sandbox/akarasulu/apacheds-2.0/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java
Wed Sep  6 22:14:47 2006
@@ -0,0 +1,81 @@
+/*
+ *  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.directory.shared.asn1.ber.tlv;
+
+
+import org.apache.directory.shared.asn1.ber.UniversalTags;
+import org.apache.directory.shared.asn1.ber.tlv.Length;
+
+import java.io.Serializable;
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
+
+/**
+ * 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
+{
+    /**
+     * Declares the Serial Version Uid.
+     *
+     * @see <a
+     *      href="http://c2.com/cgi/wiki?AlwaysDeclareSerialVersionUid">Always
+     *      Declare Serial Version Uid</a>
+     */
+    static final long serialVersionUID = 2L;
+
+    /**
+     * Encode an OctetString value
+     * 
+     * @param buffer The PDU in which the value will be put
+     * @param byte[] The bytes to be encoded
+     */
+    public static void encode( ByteBuffer buffer, byte[] bytes ) throws ValueException
+    {
+        if ( buffer == null )
+        {
+            throw new ValueException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        try
+        {
+            buffer.put( UniversalTags.OCTET_STRING.getValue() );
+
+            if ( ( bytes == null ) || ( bytes.length == 0 ) )
+            {
+                buffer.put( ( byte ) 0 );
+            }
+            else
+            {
+                buffer.put( Length.getBytes( bytes.length ) );
+                buffer.put( bytes );
+            }
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new ValueException( "The PDU buffer size is too small !" );
+        }
+
+        return;
+    }
+}

Added: directory/sandbox/akarasulu/apacheds-2.0/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/ValueException.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/apacheds-2.0/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/ValueException.java?view=auto&rev=440977
==============================================================================
--- directory/sandbox/akarasulu/apacheds-2.0/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/ValueException.java
(added)
+++ directory/sandbox/akarasulu/apacheds-2.0/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/ValueException.java
Wed Sep  6 22:14:47 2006
@@ -0,0 +1,54 @@
+/*
+ *  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.directory.shared.asn1.ber.tlv;
+
+
+/**
+ * Thrown when there is a failure condition during the encoding process. This
+ * exception is thrown when an Encoder encounters a encoding specific exception
+ * such as invalid data, inability to calculate a checksum, characters outside
+ * of the expected range.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ValueException extends Exception
+{
+
+    /**
+     * Declares the Serial Version Uid.
+     * 
+     * @see <a
+     *      href="http://c2.com/cgi/wiki?AlwaysDeclareSerialVersionUid">Always
+     *      Declare Serial Version Uid</a>
+     */
+    private static final long serialVersionUID = 2L;
+
+
+    /**
+     * Creates a new instance of this exception with an useful message.
+     * 
+     * @param message a useful message relating to the encoder specific error.
+     */
+    public ValueException(String message)
+    {
+        super( message );
+    }
+}



Mime
View raw message