harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r548598 [1/2] - in /harmony/enhanced/classlib/trunk/modules/jndi/src: main/java/javax/naming/ldap/ main/java/org/apache/harmony/jndi/asn1/ main/java/org/apache/harmony/jndi/internal/nls/ test/java/org/apache/harmony/jndi/tests/javax/naming/...
Date Tue, 19 Jun 2007 05:58:10 GMT
Author: tonywu
Date: Mon Jun 18 22:58:08 2007
New Revision: 548598

URL: http://svn.apache.org/viewvc?view=rev&rev=548598
Log:
Apply patch HARMONY-4226 ([classlib][jndi] Class SortResponseControl has some failures)

Added:
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Any.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1BitString.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Choice.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Constants.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Constructured.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Enumerated.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Exception.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Explicit.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Implicit.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1OctetString.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Primitive.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Sequence.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1SequenceOf.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Set.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1SetOf.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1StringType.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Time.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Type.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1TypeCollection.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1UTCTime.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1ValueCollection.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/BerInputStream.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/BerOutputStream.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/BitString.java
Modified:
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/ldap/SortResponseControl.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/nls/messages.properties
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/TestSortResponseControl.java

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/ldap/SortResponseControl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/ldap/SortResponseControl.java?view=diff&rev=548598&r1=548597&r2=548598
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/ldap/SortResponseControl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/ldap/SortResponseControl.java Mon Jun 18 22:58:08 2007
@@ -22,13 +22,14 @@
 
 import javax.naming.NamingException;
 
+import org.apache.harmony.jndi.asn1.ASN1Enumerated;
+import org.apache.harmony.jndi.asn1.ASN1Implicit;
+import org.apache.harmony.jndi.asn1.ASN1OctetString;
+import org.apache.harmony.jndi.asn1.ASN1Sequence;
+import org.apache.harmony.jndi.asn1.ASN1Type;
+import org.apache.harmony.jndi.asn1.BerInputStream;
 import org.apache.harmony.jndi.internal.SortResult;
 import org.apache.harmony.jndi.internal.Util;
-import org.apache.harmony.security.asn1.ASN1Enumerated;
-import org.apache.harmony.security.asn1.ASN1OctetString;
-import org.apache.harmony.security.asn1.ASN1Sequence;
-import org.apache.harmony.security.asn1.ASN1Type;
-import org.apache.harmony.security.asn1.BerInputStream;
 
 
 /**
@@ -71,7 +72,7 @@
      */
     static ASN1Type ASN1_SORTRESPONSE = new ASN1Sequence(new ASN1Type[] {
             ASN1Enumerated.getInstance(),   // sortResult
-            ASN1OctetString.getInstance(),  // attributeType
+            new ASN1Implicit(0, ASN1OctetString.getInstance()),   // attributeType
     }) {
         
         {
@@ -108,7 +109,7 @@
      * @ar.org.fitc.spec_ref
      */
     public SortResponseControl(String id, boolean criticality, byte[] value) throws IOException {
-        super(OID,criticality,value);
+        super(id,criticality,value);
         SortResult sr;
         sr = (SortResult) ASN1_SORTRESPONSE.decode(value);
         resultCode = sr.getSortresult();

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Any.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Any.java?view=auto&rev=548598
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Any.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Any.java Mon Jun 18 22:58:08 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.
+ */
+
+/**
+* @author Vladimir N. Molotkov, Stepan M. Mishura
+* @version $Revision$
+*/
+
+package org.apache.harmony.jndi.asn1;
+
+import java.io.IOException;
+
+
+/**
+ * This class represents ASN.1 ANY type.
+ * 
+ * @see http://asn1.elibel.tm.fr/en/standards/index.htm
+ */
+
+public class ASN1Any extends ASN1Type {
+
+    // default implementation
+    private static final ASN1Any ASN1= new ASN1Any();
+
+    /**
+     * Constructs ASN.1 ANY type
+     * 
+     * The constructor is provided for inheritance purposes
+     * when there is a need to create a custom ASN.1 ANY type.
+     * To get a default implementation it is recommended to use
+     * getInstance() method.
+     */
+    public ASN1Any() {
+        super(TAG_ANY); // has not tag number
+    }
+
+    /**
+     * Returns ASN.1 ANY type default implementation
+     * 
+     * The default implementation works with full encoding
+     * that is represented as raw byte array.
+     *
+     * @return ASN.1 ANY type default implementation
+     */
+    public static ASN1Any getInstance() {
+        return ASN1;
+    }
+
+    //
+    //
+    // Decode
+    //
+    //
+
+    /**
+     * Tests provided identifier.
+     *
+     * @param identifier - identifier to be verified
+     * @return - true
+     */
+    public final boolean checkTag(int identifier) {
+        return true; //all tags are OK
+    }
+
+    public Object decode(BerInputStream in) throws IOException {
+
+        // only read content, doesn't check it
+        in.readContent();
+
+        if (in.isVerify) {
+            return null;
+        }
+        return getDecodedObject(in);
+    }
+
+    /**
+     * Extracts array of bytes that represents full encoding from BER input
+     * stream.
+     * 
+     * @param in -
+     *            BER input stream
+     * @return array of bytes
+     */
+    public Object getDecodedObject(BerInputStream in) throws IOException {
+        byte[] bytesEncoded = new byte[in.offset - in.tagOffset];
+        System.arraycopy(in.buffer, in.tagOffset, bytesEncoded, 0,
+                bytesEncoded.length);
+        return bytesEncoded;
+    }
+
+    //
+    //
+    // Encode
+    //
+    //
+
+    public void encodeASN(BerOutputStream out) {
+        out.encodeANY();
+    }
+
+    public void encodeContent(BerOutputStream out) {
+        out.encodeANY();
+    }
+
+    public void setEncodingContent(BerOutputStream out) {
+        out.length = ((byte[]) out.content).length;
+    }
+
+    public int getEncodedLength(BerOutputStream out) {
+        return out.length;
+    }
+}
\ No newline at end of file

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1BitString.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1BitString.java?view=auto&rev=548598
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1BitString.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1BitString.java Mon Jun 18 22:58:08 2007
@@ -0,0 +1,235 @@
+/*
+ *  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.
+ */
+
+/**
+* @author Vladimir N. Molotkov, Stepan M. Mishura
+* @version $Revision$
+*/
+
+package org.apache.harmony.jndi.asn1;
+
+import java.io.IOException;
+
+import org.apache.harmony.jndi.internal.nls.Messages;
+
+/**
+ * This class represents ASN.1 Bitstring type.
+ * 
+ * @see http://asn1.elibel.tm.fr/en/standards/index.htm
+ */
+
+public class ASN1BitString extends ASN1StringType {
+
+    // default implementation
+    private static final ASN1BitString ASN1 = new ASN1BitString();
+
+    /**
+     * Constructs ASN.1 Bitstring type
+     * 
+     * The constructor is provided for inheritance purposes
+     * when there is a need to create a custom ASN.1 Bitstring type.
+     * To get a default implementation it is recommended to use
+     * getInstance() method.
+     */
+    public ASN1BitString() {
+        super(TAG_BITSTRING);
+    }
+
+    /**
+     * Returns ASN.1 Bitstring type default implementation
+     * 
+     * The default implementation works with encoding
+     * that is represented as BitString object.
+     *
+     * @return ASN.1 Bitstring type default implementation
+     * @see org.apache.harmony.security.asn1.BitString
+     */
+    public static ASN1BitString getInstance() {
+        return ASN1;
+    }
+
+    //
+    //
+    // Decode
+    //
+    //
+
+    public Object decode(BerInputStream in) throws IOException {
+
+        in.readBitString();
+
+        if (in.isVerify) {
+            return null;
+        }
+        return getDecodedObject(in);
+    }
+
+    /**
+     * Extracts BitString object from BER input stream.
+     *
+     * @param in - BER input stream
+     * @return BitString object
+     */
+    public Object getDecodedObject(BerInputStream in) throws IOException {
+        byte[] bytes = new byte[in.length - 1];
+        System.arraycopy(in.buffer, in.contentOffset + 1, bytes, 0,
+                in.length - 1);
+        return new BitString(bytes, in.buffer[in.contentOffset]);
+    }
+
+    //
+    // Encode
+    //
+
+    public void encodeContent(BerOutputStream out) {
+        out.encodeBitString();
+    }
+
+    public void setEncodingContent(BerOutputStream out) {
+        out.length = ((BitString) out.content).bytes.length + 1;
+    }
+
+    //
+    //
+    // Named Bit List
+    //
+    //
+
+    /**
+     * Default implementation for ASN.1 Named Bitstring type 
+     * 
+     * The default implementation works with encoding
+     * that is mapped to array of boolean.
+     */
+    public static class ASN1NamedBitList extends ASN1BitString {
+
+        private static final byte[] SET_MASK = { (byte) 128, 64, 32, 16, 8, 4,
+                2, 1 };
+
+        private static final BitString emptyString = new BitString(
+                new byte[] {}, 0);
+
+        private static final int INDEFINITE_SIZE = -1;
+
+        private final int minBits;
+
+        private final int maxBits;
+
+        public ASN1NamedBitList() {
+            this.minBits = INDEFINITE_SIZE;
+            this.maxBits = INDEFINITE_SIZE;
+        }
+
+        public ASN1NamedBitList(int minBits) {
+            this.minBits = minBits;
+            this.maxBits = INDEFINITE_SIZE;
+        }
+
+        public ASN1NamedBitList(int minBits, int maxBits) {
+            this.minBits = minBits;
+            this.maxBits = maxBits;
+        }
+
+        public Object getDecodedObject(BerInputStream in) throws IOException {
+
+            boolean[] value = null;
+
+            int unusedBits = in.buffer[in.contentOffset];
+            int bitsNumber = (in.length - 1) * 8 - unusedBits;
+
+            if (maxBits == INDEFINITE_SIZE) {
+                if (minBits == INDEFINITE_SIZE) {
+                    value = new boolean[bitsNumber];
+                } else {
+                    if (bitsNumber > minBits) {
+                        value = new boolean[bitsNumber];
+                    } else {
+                        value = new boolean[minBits];
+                    }
+                }
+            } else {
+                if (bitsNumber > maxBits) {
+                    throw new ASN1Exception(
+                            Messages.getString("security.97")); //FIXME message //$NON-NLS-1$
+                }
+                value = new boolean[maxBits];
+            }
+
+            if (bitsNumber == 0) {
+                // empty bit string
+                return value;
+            }
+
+            int i = 1;
+            int j = 0;
+            byte octet = in.buffer[in.contentOffset + i];
+            for (int size = in.length - 1; i < size; i++) {
+
+                for (int k = 0; k < 8; k++, j++) {
+                    value[j] = (SET_MASK[k] & octet) != 0;
+                }
+                i++;
+                octet = in.buffer[in.contentOffset + i];
+            }
+
+            // final octet
+            for (int k = 0; k < (8 - unusedBits); k++, j++) {
+                value[j] = (SET_MASK[k] & octet) != 0;
+            }
+
+            return value;
+        }
+
+        public void setEncodingContent(BerOutputStream out) {
+
+            boolean[] toEncode = (boolean[]) out.content;
+
+            int index = toEncode.length - 1;
+            while (index > -1 && !toEncode[index]) {
+                index--;
+            }
+
+            if (index == -1) {
+                out.content = emptyString;
+                out.length = 1;
+            } else {
+                int unusedBits = 7 - index % 8;
+                byte[] bytes = new byte[index / 8 + 1];
+
+                int j = 0;
+                index = bytes.length - 1;
+                for (int i = 0; i < index; i++) {
+                    for (int k = 0; k < 8; k++, j++) {
+                        if (toEncode[j]) {
+                            bytes[i] = (byte) (bytes[i] | SET_MASK[k]);
+                        }
+                    }
+                }
+
+                //final octet
+                for (int k = 0; k < (8 - unusedBits); k++, j++) {
+                    if (toEncode[j]) {
+                        bytes[index] = (byte) (bytes[index] | SET_MASK[k]);
+                    }
+                }
+
+                out.content = new BitString(bytes, unusedBits);
+                out.length = bytes.length + 1;
+            }
+        }
+    }
+}
\ No newline at end of file

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Choice.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Choice.java?view=auto&rev=548598
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Choice.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Choice.java Mon Jun 18 22:58:08 2007
@@ -0,0 +1,360 @@
+/*
+ *  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.
+ */
+/**
+* @author Vladimir N. Molotkov, Stepan M. Mishura
+* @version $Revision$
+*/
+
+package org.apache.harmony.jndi.asn1;
+
+import java.io.IOException;
+import java.math.BigInteger;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.apache.harmony.jndi.internal.nls.Messages;
+
+
+/**
+ * This abstract class represents ASN.1 Choice type.
+ * 
+ * To implement custom ASN.1 choice type an application class
+ * must provide implementation for the following methods:
+ *     getIndex()
+ *     getObjectToEncode()
+ * 
+ * There are two ways to implement custom ASN.1 choice type:
+ * with application class that represents ASN.1 custom choice type or without. 
+ * The key point is how a value of choice type is stored by application classes.
+ * 
+ * For example, let's consider the following ASN.1 notations
+ * (see http://www.ietf.org/rfc/rfc3280.txt)
+ * 
+ * Time ::= CHOICE {
+ *       utcTime        UTCTime,
+ *       generalTime    GeneralizedTime
+ * }
+ * 
+ * Validity ::= SEQUENCE {
+ *       notBefore      Time,
+ *       notAfter       Time 
+ *  }
+ * 
+ * 1)First approach:
+ * No application class to represent ASN.1 Time notation
+ * 
+ * The Time notation is a choice of different time formats: UTC and Generalized.
+ * Both of them are mapped to java.util.Date object, so an application
+ * class that represents ASN.1 Validity notation may keep values
+ * as Date objects.
+ * 
+ * So a custom ASN.1 Time choice type should map its notation to Date object.
+ * 
+ * class Time {
+ * 
+ *     // custom ASN.1 choice class: maps Time to is notation
+ *     public static final ASN1Choice asn1 = new ASN1Choice(new ASN1Type[] {
+ *         ASN1GeneralizedTime.asn1, ASN1UTCTime.asn1 }) {
+ *
+ *         public int getIndex(java.lang.Object object) {
+ *             return 0; // always encode as ASN1GeneralizedTime
+ *         }
+ *
+ *         public Object getObjectToEncode(Object object) {
+ *         
+ *             // A value to be encoded value is a Date object
+ *             // pass it to custom time class  
+ *             return object;
+ *         }
+ *     };
+ * }
+ * 
+ * class Validity {
+ * 
+ *     private Date notBefore;    // choice as Date 
+ *     private Date notAfter;     // choice as Date
+ * 
+ *     ... // constructors and other methods go here
+ * 
+ *     // custom ASN.1 sequence class: maps Validity class to is notation
+ *     public static final ASN1Sequence ASN1
+ *         = new ASN1Sequence(new ASN1Type[] {Time.asn1, Time.asn1 }) {
+ * 
+ *         protected Object getObject(Object[] values) {
+ * 
+ *             // ASN.1 Time choice passed Data object - use it 
+ *             return new Validity((Date) values[0], (Date) values[1]);
+ *         }
+ *
+ *         protected void getValues(Object object, Object[] values) {
+ *
+ *             Validity validity = (Validity) object;
+ *
+ *             // pass Date objects to ASN.1 Time choice
+ *             values[0] = validity.notBefore;
+ *             values[1] = validity.notAfter;
+ *         }
+ *     }
+ * }
+ * 
+ * 2)Second approach:
+ * There is an application class to represent ASN.1 Time notation
+ * 
+ * If it is a matter what time format should be used to decode/encode
+ * Date objects a class to represent ASN.1 Time notation must be created.
+ * 
+ * For example,
+ *  
+ * class Time {
+ * 
+ *     private Date utcTime; 
+ *     private Date gTime;
+ * 
+ *     ... // constructors and other methods go here
+ *  
+ *     // custom ASN.1 choice class: maps Time to is notation
+ *     public static final ASN1Choice asn1 = new ASN1Choice(new ASN1Type[] {
+ *         ASN1GeneralizedTime.asn1, ASN1UTCTime.asn1 }) {
+ *
+ *         public Object getDecodedObject(BerInputStream in) {
+ *
+ *             // create Time object to pass as decoded value
+ *             Time time = new Time();
+ * 
+ *             if (in.choiceIndex==0) {
+ *                 // we decoded GeneralizedTime
+ *                 // store decoded Date value in corresponding field
+ *                 time.gTime = in.content;
+ *                 // return it
+ *                 return time;
+ *             } else {
+ *                 // we decoded UTCTime
+ *                 // store decoded Date value in corresponding field
+ *                 time.utcTime = in.content;
+ *                 // return it
+ *                 return time;
+ *             }
+ *         }
+ *
+ *         public int getIndex(java.lang.Object object) {
+ *             Time time = (Time)object;
+ *             if(time.utcTime!=null){
+ *                 // encode Date as UTCTime
+ *                 return 1;
+ *             } else {
+ *                 // otherwise encode Date as GeneralizedTime
+ *                 return 0;
+ *             } 
+ *         }
+ *
+ *         public Object getObjectToEncode(Object object) {
+ *             Time time = (Time)object;
+ *             if(time.utcTime!=null){
+ *                 // encode Date as UTCTime
+ *                 return 1;
+ *             } else {
+ *                 // otherwise encode Date as GeneralizedTime
+ *                 return 0;
+ *             } 
+ *         }
+ *     };
+ * }
+ *
+ * So now Validity class must keep all values in Time object
+ * and its custom ASN.1 sequence class must handle this class of objects
+ *
+ * class Validity {
+ * 
+ *     private Time notBefore;    // now it is a Time!!! 
+ *     private Time notAfter;     // now it is a Time!!!
+ * 
+ *     ... // constructors and other methods go here
+ * 
+ *     // custom ASN.1 sequence class: maps Validity class to is notation
+ *     public static final ASN1Sequence ASN1
+ *         = new ASN1Sequence(new ASN1Type[] {Time.asn1, Time.asn1 }) {
+ * 
+ *         protected Object getObject(Object[] values) {
+ * 
+ *             // We've gotten Time objects here !!!
+ *             return new Validity((Time) values[0], (Time) values[1]);
+ *         }
+ *
+ *         protected void getValues(Object object, Object[] values) {
+ *
+ *             Validity validity = (Validity) object;
+ *
+ *             // pass Time objects to ASN.1 Time choice
+ *             values[0] = validity.notBefore;
+ *             values[1] = validity.notAfter;
+ *         }
+ *     }
+ * }
+ * 
+ * @see http://asn1.elibel.tm.fr/en/standards/index.htm
+ */
+
+public abstract class ASN1Choice extends ASN1Type {
+
+    public final ASN1Type[] type;
+
+    // identifiers table: [2][number of distinct identifiers]
+    // identifiers[0]: stores identifiers (includes nested choices)
+    // identifiers[1]: stores identifiers' indexes in array of types
+    private final int[][] identifiers;
+
+    /**
+     * Constructs ASN.1 choice type.
+     * 
+     * @param type -
+     *            an array of one or more ASN.1 type alternatives.
+     * @throws IllegalArgumentException -
+     *             type parameter is invalid
+     */
+    @SuppressWarnings("unchecked")
+    public ASN1Choice(ASN1Type[] type) {
+        super(TAG_CHOICE); // has not tag number
+
+        if (type.length == 0) {
+            throw new IllegalArgumentException(Messages.getString("security.10E", //$NON-NLS-1$
+                    getClass().getName()));
+        }
+
+        // create map of all identifiers
+        TreeMap map = new TreeMap();
+        for (int index = 0; index < type.length; index++) {
+
+            ASN1Type t = type[index];
+
+            if (t instanceof ASN1Any) {
+                // ASN.1 ANY is not allowed,
+                // even it is a single component (not good for nested choices)
+                throw new IllegalArgumentException(Messages.getString("security.10F", //$NON-NLS-1$
+                        getClass().getName())); // FIXME name
+            } else if (t instanceof ASN1Choice) {
+
+                // add all choice's identifiers
+                int[][] choiceToAdd = ((ASN1Choice) t).identifiers;
+                for (int j = 0; j < choiceToAdd[0].length; j++) {
+                    addIdentifier(map, choiceToAdd[0][j], index);
+                }
+                continue;
+            }
+
+            // add primitive identifier
+            if (t.checkTag(t.id)) {
+                addIdentifier(map, t.id, index);
+            }
+
+            // add constructed identifier
+            if (t.checkTag(t.constrId)) {
+                addIdentifier(map, t.constrId, index);
+            }
+        }
+
+        // fill identifiers array
+        int size = map.size();
+        identifiers = new int[2][size];
+        Iterator it = map.entrySet().iterator();
+
+        for (int i = 0; i < size; i++) {
+        	Map.Entry entry = (Map.Entry) it.next();
+            BigInteger identifier = (BigInteger) entry.getKey();
+
+            identifiers[0][i] = identifier.intValue();
+            identifiers[1][i] = ((BigInteger) entry.getValue()).intValue();
+        }
+
+        this.type = type;
+    }
+
+    private void addIdentifier(TreeMap<BigInteger, BigInteger> map, int identifier, int index){
+        if (map.put(BigInteger.valueOf(identifier), BigInteger.valueOf(index)) != null) {
+            throw new IllegalArgumentException(Messages.getString("security.10F", //$NON-NLS-1$
+                    getClass().getName())); // FIXME name
+        }
+    }
+    
+    //
+    //
+    // DECODE
+    //
+    //
+
+    /**
+     * Tests whether one of choice alternatives has the same identifier or not.
+     * 
+     * @param identifier -
+     *            ASN.1 identifier to be verified
+     * @return - true if one of choice alternatives has the same identifier,
+     *         otherwise false;
+     */
+    public final boolean checkTag(int identifier) {
+        return Arrays.binarySearch(identifiers[0], identifier) >= 0;
+    }
+
+    public Object decode(BerInputStream in) throws IOException {
+
+        int index = Arrays.binarySearch(identifiers[0], in.tag);
+        if (index < 0) {
+            throw new ASN1Exception(Messages.getString("security.110", //$NON-NLS-1$
+                    getClass().getName()));// FIXME message
+        }
+
+        index = identifiers[1][index];
+
+        in.content = type[index].decode(in);
+
+        // set index for getDecodedObject method
+        in.choiceIndex = index;
+
+        if (in.isVerify) {
+            return null;
+        }
+        return getDecodedObject(in);
+    }
+    
+    //
+    //
+    // ENCODE
+    //
+    //
+
+    public void encodeASN(BerOutputStream out) {
+        encodeContent(out);
+    }
+
+    public final void encodeContent(BerOutputStream out) {
+        out.encodeChoice(this);
+    }
+
+    /**
+     * TODO Put method description here
+     *
+     * @param object - an object to be encoded
+     * @return
+     */
+    public abstract int getIndex(Object object);
+
+    public abstract Object getObjectToEncode(Object object);
+
+    public final void setEncodingContent(BerOutputStream out) {
+        out.getChoiceLength(this);
+    }
+}
\ No newline at end of file

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Constants.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Constants.java?view=auto&rev=548598
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Constants.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Constants.java Mon Jun 18 22:58:08 2007
@@ -0,0 +1,96 @@
+/*
+ *  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.
+ */
+
+/**
+* @author Vladimir N. Molotkov
+* @version $Revision$
+*/
+
+package org.apache.harmony.jndi.asn1;
+
+/**
+ * ASN.1 and some other constants holder interface
+ * 
+ * @see http://asn1.elibel.tm.fr/en/standards/index.htm
+ */
+public interface ASN1Constants {
+    /**
+     * Tag classes
+     */
+    int CLASS_UNIVERSAL = 0;
+    int CLASS_APPLICATION = 64;
+    int CLASS_CONTEXTSPECIFIC = 128;
+    int CLASS_PRIVATE = 192;
+
+    /**
+     * Tag Primitive/Constructed (P/C) flag
+     */
+    int PC_PRIMITIVE = 0;
+    int PC_CONSTRUCTED = 32;
+
+    /**
+     * Universal class tag assignments
+     */
+    int TAG_BOOLEAN = 1;
+    int TAG_INTEGER = 2;
+    int TAG_BITSTRING = 3;
+    int TAG_OCTETSTRING = 4;
+    int TAG_NULL = 5;
+    int TAG_OID = 6;
+    int TAG_OBJDESCRIPTOR = 7;
+    int TAG_EXTERNAL = 8;
+    int TAG_INSTANCEOF = TAG_EXTERNAL;
+    int TAG_REAL = 9;
+    int TAG_ENUM = 10;
+    int TAG_EMBEDDEDPDV = 11;
+    int TAG_UTF8STRING = 12;
+    int TAG_RELATIVEOID = 13;
+    int TAG_SEQUENCE = 16;
+    int TAG_SEQUENCEOF = TAG_SEQUENCE;
+    int TAG_SET = 17;
+    int TAG_SETOF = TAG_SET;
+    int TAG_NUMERICSTRING = 18;
+    int TAG_PRINTABLESTRING = 19;
+    int TAG_TELETEXSTRING = 20;
+    int TAG_T61STRING = TAG_TELETEXSTRING;
+    int TAG_VIDEOTEXSTRING = 21;
+    int TAG_IA5STRING = 22;
+    int TAG_UTCTIME = 23;
+    int TAG_GENERALIZEDTIME = 24;
+    int TAG_GRAPHICSTRING = 25;
+    int TAG_VISIBLESTRING = 26;
+    int TAG_ISO646STRING = TAG_VISIBLESTRING;
+    int TAG_GENERALSTRING = 27;
+    int TAG_UNIVERSALSTRING = 28;
+    int TAG_BMPSTRING = 30;
+
+    int TAG_C_BITSTRING = TAG_BITSTRING | PC_CONSTRUCTED;
+    int TAG_C_OCTETSTRING = TAG_OCTETSTRING | PC_CONSTRUCTED;
+    int TAG_C_UTF8STRING = TAG_UTF8STRING | PC_CONSTRUCTED;
+    int TAG_C_SEQUENCE = TAG_SEQUENCE | PC_CONSTRUCTED;
+    int TAG_C_SEQUENCEOF = TAG_SEQUENCEOF | PC_CONSTRUCTED;
+    int TAG_C_SET = TAG_SET | PC_CONSTRUCTED;
+    int TAG_C_SETOF = TAG_SETOF | PC_CONSTRUCTED;
+    int TAG_C_UTCTIME = TAG_UTCTIME | PC_CONSTRUCTED;
+    int TAG_C_GENERALIZEDTIME = TAG_GENERALIZEDTIME | PC_CONSTRUCTED;
+ 
+    /**
+     * Not from the ASN.1 specs. For implementation purposes.
+     */
+    int TAG_ANY = 0;
+    int TAG_CHOICE = TAG_ANY;
+}

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Constructured.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Constructured.java?view=auto&rev=548598
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Constructured.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Constructured.java Mon Jun 18 22:58:08 2007
@@ -0,0 +1,60 @@
+/*
+ *  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.
+ */
+
+/**
+* @author Vladimir N. Molotkov, Stepan M. Mishura
+* @version $Revision$
+*/
+
+package org.apache.harmony.jndi.asn1;
+
+
+/**
+ * This abstract class is the super class for all constructed ASN.1 types
+ * 
+ * @see http://asn1.elibel.tm.fr/en/standards/index.htm
+ */
+
+public abstract class ASN1Constructured extends ASN1Type {
+
+    public ASN1Constructured(int tagNumber) {
+        super(CLASS_UNIVERSAL, tagNumber);
+    }
+
+    public ASN1Constructured(int tagClass, int tagNumber) {
+        super(tagClass, tagNumber);
+    }
+    
+    /**
+     * Tests provided identifier.
+     *
+     * @param identifier - identifier to be verified
+     * @return - true if identifier correspond to constructed identifier of
+     *           this ASN.1 type, otherwise false
+     */
+    public final boolean checkTag(int identifier) {
+        return this.constrId == identifier;
+    }
+    
+    /**
+     *
+     */
+    public void encodeASN(BerOutputStream out) {
+        out.encodeTag(constrId);
+        encodeContent(out);
+    }
+}
\ No newline at end of file

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Enumerated.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Enumerated.java?view=auto&rev=548598
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Enumerated.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Enumerated.java Mon Jun 18 22:58:08 2007
@@ -0,0 +1,104 @@
+/*
+ *  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.
+ */
+
+/**
+* @author Stepan M. Mishura
+* @version $Revision$
+*/
+
+package org.apache.harmony.jndi.asn1;
+
+import java.io.IOException;
+
+
+/**
+ * This class represents ASN.1 Enumerated type.
+ * 
+ * @see http://asn1.elibel.tm.fr/en/standards/index.htm
+ */
+
+public class ASN1Enumerated extends ASN1Primitive {
+
+    // default implementation
+    private static final ASN1Enumerated ASN1 = new ASN1Enumerated();
+
+    /**
+     * Constructs ASN.1 Enumerated type
+     * 
+     * The constructor is provided for inheritance purposes
+     * when there is a need to create a custom ASN.1 Enumerated type.
+     * To get a default implementation it is recommended to use
+     * getInstance() method.
+     */
+    public ASN1Enumerated() {
+        super(TAG_ENUM);
+    }
+
+    /**
+     * Returns ASN.1 Enumerated type default implementation
+     * 
+     * The default implementation works with encoding
+     * that is represented as byte array.
+     *
+     * @return ASN.1 Enumerated type default implementation
+     */
+    public static ASN1Enumerated getInstance() {
+        return ASN1;
+    }
+
+    //
+    //
+    // Decode
+    //
+    //
+
+    public Object decode(BerInputStream in) throws IOException {
+        in.readEnumerated();
+
+        if (in.isVerify) {
+            return null;
+        }
+        return getDecodedObject(in);
+    }
+
+    /**
+     * Extracts array of bytes from BER input stream.
+     *
+     * @param in - BER input stream
+     * @return array of bytes
+     */
+    public Object getDecodedObject(BerInputStream in) throws IOException {
+        byte[] bytesEncoded = new byte[in.length];
+        System.arraycopy(in.buffer, in.contentOffset, bytesEncoded, 0,
+                in.length);
+        return bytesEncoded;
+    }
+
+    //
+    //
+    // Encode
+    //
+    //
+
+    public void encodeContent(BerOutputStream out) {
+        out.encodeInteger();
+    }
+
+    public void setEncodingContent(BerOutputStream out) {
+        out.length = ((byte[]) out.content).length;
+    }
+}
\ No newline at end of file

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Exception.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Exception.java?view=auto&rev=548598
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Exception.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Exception.java Mon Jun 18 22:58:08 2007
@@ -0,0 +1,52 @@
+/*
+ *  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.
+ */
+
+/**
+* @author Vladimir N. Molotkov, Stepan M. Mishura
+* @version $Revision$
+*/
+
+package org.apache.harmony.jndi.asn1;
+
+import java.io.IOException;
+
+/**
+ * Thrown by decoder/encoder stream to indicate violation of encoding rules.
+ */
+
+public class ASN1Exception extends IOException {
+
+    /**
+     * @serial
+     */
+    private static final long serialVersionUID = -3561981263989123987L;
+
+    /**
+     * Constructs an ASN1Exception without a message. 
+     */
+    public ASN1Exception(){
+    }
+
+    /**
+     * Constructs an ASN1Exception with a message. 
+     * 
+     * @param message - a string that describes encoding violation 
+     */
+    public ASN1Exception(String message){
+        super(message);
+    }
+}

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Explicit.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Explicit.java?view=auto&rev=548598
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Explicit.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Explicit.java Mon Jun 18 22:58:08 2007
@@ -0,0 +1,110 @@
+/*
+ *  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.
+ */
+
+/**
+* @author Vladimir N. Molotkov, Stepan M. Mishura
+* @version $Revision$
+*/
+
+package org.apache.harmony.jndi.asn1;
+
+import java.io.IOException;
+
+import org.apache.harmony.jndi.internal.nls.Messages;
+
+
+/**
+ * This class represents explicitly tagged ASN.1 type.
+ * 
+ * @see http://asn1.elibel.tm.fr/en/standards/index.htm
+ */
+
+public final class ASN1Explicit extends ASN1Constructured {
+
+    /**
+     * Tagged type
+     */
+    public final ASN1Type type;
+
+    /**
+     * Constructs explicitly tagged ASN.1 type
+     * with context-specific tag class and specified tag number. 
+     * 
+     * @param tagNumber - ASN.1 tag number
+     * @param type - ASN.1 type to be tagged
+     * @throws IllegalArgumentException - if tagNumber is invalid
+     */
+    public ASN1Explicit(int tagNumber, ASN1Type type) {
+        this(CLASS_CONTEXTSPECIFIC, tagNumber, type);
+    }
+
+    /**
+     * Constructs explicitly tagged ASN.1 type.
+     * 
+     * @param tagClass - ASN.1 tag class.
+     * @param tagNumber - ASN.1 tag number
+     * @param type - ASN.1 type to be tagged
+     * @throws IllegalArgumentException - if tagClass or tagNumber is invalid
+     */
+    public ASN1Explicit(int tagClass, int tagNumber, ASN1Type type) {
+        super(tagClass, tagNumber);
+
+        this.type = type;
+    }
+
+    //
+    //
+    // Decode
+    //
+    //
+
+    public Object decode(BerInputStream in) throws IOException {
+        if (constrId != in.tag) {
+            throw new ASN1Exception(
+                    Messages.getString("security.13F", //$NON-NLS-1$
+                    new Object[] { in.tagOffset, Integer.toHexString(constrId),
+                            Integer.toHexString(in.tag) }));
+        }
+        in.next();
+
+        in.content = type.decode(in);
+
+        if (in.isVerify) {
+            return null;
+        }
+        return getDecodedObject(in);
+    }
+
+    //
+    //
+    // Encode
+    //
+    //
+
+    public void encodeContent(BerOutputStream out) {
+        out.encodeExplicit(this);
+    }
+
+    public void setEncodingContent(BerOutputStream out) {
+        out.getExplicitLength(this);
+    }
+
+    public String toString() {
+        //FIXME fix performance
+        return super.toString() + " for type " + type; //$NON-NLS-1$
+    }
+}
\ No newline at end of file

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Implicit.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Implicit.java?view=auto&rev=548598
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Implicit.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Implicit.java Mon Jun 18 22:58:08 2007
@@ -0,0 +1,172 @@
+/*
+ *  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.
+ */
+
+/**
+* @author Vladimir N. Molotkov, Stepan M. Mishura
+* @version $Revision$
+*/
+
+package org.apache.harmony.jndi.asn1;
+
+import java.io.IOException;
+
+import org.apache.harmony.jndi.internal.nls.Messages;
+
+
+/**
+ * Implicitly tagged ASN.1 type.
+ * 
+ * @see http://asn1.elibel.tm.fr/en/standards/index.htm
+ */
+public class ASN1Implicit extends ASN1Type {
+
+    // primitive type of tagging
+    private static final int TAGGING_PRIMITIVE = 0;
+
+    // constructed type of tagging
+    private static final int TAGGING_CONSTRUCTED = 1;
+
+    // string type of tagging
+    private static final int TAGGING_STRING = 2;
+
+    // tagged ASN.1 type
+    private final ASN1Type type;
+
+    // type of tagging. There are three of them
+    // 1) primitive: only primitive identifier is valid
+    // 2) constructed: only constructed identifier is valid
+    // 3) string: both identifiers are valid
+    private final int taggingType;
+
+    /**
+     * Constructs implicitly tagged ASN.1 type
+     * with context-specific tag class and specified tag number. 
+     * 
+     * @param tagNumber - ASN.1 tag number
+     * @param type - ASN.1 type to be tagged
+     * @throws IllegalArgumentException - if tagNumber or type is invalid
+     */
+    public ASN1Implicit(int tagNumber, ASN1Type type) {
+        this(CLASS_CONTEXTSPECIFIC, tagNumber, type);
+    }
+
+    /**
+     * Constructs implicitly tagged ASN.1 type
+     * 
+     * @param tagClass - ASN.1 tag class.
+     * @param tagNumber - ASN.1 tag number
+     * @param type - ASN.1 type to be tagged
+     * @throws IllegalArgumentException - if tagNumber, tagClass or type is invalid
+     */
+    public ASN1Implicit(int tagClass, int tagNumber, ASN1Type type) {
+        super(tagClass, tagNumber);
+
+//        if ((type instanceof ASN1Choice) || (type instanceof ASN1Any)) {
+//            // According to X.680:
+//            // 'The IMPLICIT alternative shall not be used if the type
+//            // defined by "Type" is an untagged choice type or an 
+//            // untagged open type'
+//            throw new IllegalArgumentException(
+//                    Messages.getString("security.9F")); //$NON-NLS-1$
+//        }
+
+        this.type = type;
+
+        if (type.checkTag(type.id)) {
+            if (type.checkTag(type.constrId)) {
+                // the base encoding can be primitive ot constructed
+                // use both encodings
+                taggingType = TAGGING_STRING;
+            } else {
+                // if the base encoding is primitive use primitive encoding
+                taggingType = TAGGING_PRIMITIVE;
+            }
+        } else {
+            // if the base encoding is constructed use constructed encoding
+            taggingType = TAGGING_CONSTRUCTED;
+        }
+    }
+
+    //
+    //
+    // Decode
+    //
+    //
+
+    /**
+     * TODO
+     */
+    public final boolean checkTag(int identifier) {
+        switch (taggingType) {
+        case TAGGING_PRIMITIVE:
+            return id == identifier;
+        case TAGGING_CONSTRUCTED:
+            return constrId == identifier;
+        default: // TAGGING_STRING
+            return id == identifier || constrId == identifier;
+        }
+    }
+
+    /**
+     * TODO
+     */
+    public Object decode(BerInputStream in) throws IOException {
+        if (!checkTag(in.tag)) {
+            // FIXME need look for tagging type
+            throw new ASN1Exception(Messages.getString("security.100", //$NON-NLS-1$
+                    new Object[] { in.tagOffset, Integer.toHexString(id),
+                            Integer.toHexString(in.tag) }));
+        }
+
+        // substitute indentifier for further decoding
+        if (id == in.tag) {
+            in.tag = type.id;
+        } else {
+            in.tag = type.constrId;
+        }
+        in.content = type.decode(in);
+
+        if (in.isVerify) {
+            return null;
+        }
+        return getDecodedObject(in);
+    }
+
+    //
+    //
+    // Encode
+    //
+    //
+
+    public void encodeASN(BerOutputStream out) {
+        //FIXME need another way for specifying identifier to be encoded
+        if (taggingType == TAGGING_CONSTRUCTED) {
+            out.encodeTag(constrId);
+        } else {
+            out.encodeTag(id);
+        }
+        encodeContent(out);
+    }
+
+    public void encodeContent(BerOutputStream out) {
+        type.encodeContent(out);
+    }
+
+    public void setEncodingContent(BerOutputStream out) {
+        type.setEncodingContent(out);
+    }
+}
\ No newline at end of file

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1OctetString.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1OctetString.java?view=auto&rev=548598
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1OctetString.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1OctetString.java Mon Jun 18 22:58:08 2007
@@ -0,0 +1,104 @@
+/*
+ *  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.
+ */
+
+/**
+* @author Vladimir N. Molotkov, Stepan M. Mishura
+* @version $Revision$
+*/
+
+package org.apache.harmony.jndi.asn1;
+
+import java.io.IOException;
+
+
+/**
+ * This class represents ASN.1 octet string type.
+ * 
+ * @see http://asn1.elibel.tm.fr/en/standards/index.htm
+ */
+
+public class ASN1OctetString extends ASN1StringType {
+
+    // default implementation
+    private static final ASN1OctetString ASN1 = new ASN1OctetString();
+
+    /**
+     * Constructs ASN.1 octet string type
+     * 
+     * The constructor is provided for inheritance purposes
+     * when there is a need to create a custom ASN.1 octet string type.
+     * To get a default implementation it is recommended to use
+     * getInstance() method.
+     */
+    public ASN1OctetString() {
+        super(TAG_OCTETSTRING);
+    }
+
+    /**
+     * Returns ASN.1 octet string type default implementation
+     * 
+     * The default implementation works with encoding
+     * that is represented as byte array.
+     *
+     * @return ASN.1 octet string type default implementation
+     */
+    public static ASN1OctetString getInstance() {
+        return ASN1;
+    }
+
+    //
+    //
+    // Decode
+    //
+    //
+
+    public Object decode(BerInputStream in) throws IOException {
+        in.readOctetString();
+
+        if (in.isVerify) {
+            return null;
+        }
+        return getDecodedObject(in);
+    }
+
+    /**
+     * Extracts array of bytes from BER input stream.
+     *
+     * @param in - BER input stream
+     * @return array of bytes
+     */
+    public Object getDecodedObject(BerInputStream in) throws IOException {
+        byte[] bytesEncoded = new byte[in.length];
+        System.arraycopy(in.buffer, in.contentOffset, bytesEncoded, 0,
+                in.length);
+        return bytesEncoded;
+    }
+
+    //
+    //
+    // Encode
+    //
+    //
+
+    public void encodeContent(BerOutputStream out) {
+        out.encodeOctetString();
+    }
+
+    public void setEncodingContent(BerOutputStream out) {
+        out.length = ((byte[]) out.content).length;
+    }
+}
\ No newline at end of file

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Primitive.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Primitive.java?view=auto&rev=548598
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Primitive.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Primitive.java Mon Jun 18 22:58:08 2007
@@ -0,0 +1,57 @@
+/*
+ *  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.
+ */
+
+/**
+* @author Vladimir N. Molotkov, Stepan M. Mishura
+* @version $Revision$
+*/
+
+package org.apache.harmony.jndi.asn1;
+
+
+/**
+ * This abstract class is the super class for all primitive ASN.1 types
+ * 
+ * @see http://asn1.elibel.tm.fr/en/standards/index.htm
+ */
+
+public abstract class ASN1Primitive extends ASN1Type {
+
+    public ASN1Primitive(int tagNumber) {
+        super(tagNumber);
+    }
+    
+    /**
+     * Tests provided identifier.
+     * 
+     * @param identifier -
+     *            identifier to be verified
+     * @return - true if identifier correspond to primitive identifier of this
+     *         ASN.1 type, otherwise false
+     */
+    public final boolean checkTag(int identifier) {
+        return this.id == identifier;
+    }
+    
+    /**
+     * TODO
+     */
+    public void encodeASN(BerOutputStream out) {
+        out.encodeTag(id);
+        encodeContent(out);
+    }
+}
\ No newline at end of file

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Sequence.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Sequence.java?view=auto&rev=548598
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Sequence.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Sequence.java Mon Jun 18 22:58:08 2007
@@ -0,0 +1,69 @@
+/*
+ *  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.
+ */
+
+/**
+* @author Vladimir N. Molotkov, Stepan M. Mishura
+* @version $Revision$
+*/
+
+package org.apache.harmony.jndi.asn1;
+
+import java.io.IOException;
+
+
+/**
+ * This class represents ASN.1 Sequence type.
+ * 
+ * @see http://asn1.elibel.tm.fr/en/standards/index.htm
+ */
+
+public class ASN1Sequence extends ASN1TypeCollection {
+
+    public ASN1Sequence(ASN1Type[] type) {
+        super(TAG_SEQUENCE, type);
+
+        //FIXME optional components must be checked for distinct identifiers
+    }
+
+    //
+    //
+    // Decode
+    //
+    //
+
+    public Object decode(BerInputStream in) throws IOException {
+        in.readSequence(this);
+
+        if (in.isVerify) {
+            return null;
+        }
+        return getDecodedObject(in);
+    }
+
+    //
+    //
+    // Encode
+    //
+    //
+    public final void encodeContent(BerOutputStream out) {
+        out.encodeSequence(this);
+    }
+
+    public final void setEncodingContent(BerOutputStream out) {
+        out.getSequenceLength(this);
+    }
+}
\ No newline at end of file

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1SequenceOf.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1SequenceOf.java?view=auto&rev=548598
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1SequenceOf.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1SequenceOf.java Mon Jun 18 22:58:08 2007
@@ -0,0 +1,94 @@
+/*
+ *  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.
+ */
+
+/**
+* @author Vladimir N. Molotkov, Stepan M. Mishura
+* @version $Revision$
+*/
+
+package org.apache.harmony.jndi.asn1;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+
+/**
+ * This class represents ASN.1 Sequence OF type.
+ * 
+ * @see http://asn1.elibel.tm.fr/en/standards/index.htm
+ */
+
+public class ASN1SequenceOf extends ASN1ValueCollection {
+
+    public ASN1SequenceOf(ASN1Type type) {
+        super(TAG_SEQUENCE, type);
+    }
+
+    //
+    //
+    // Decode
+    //
+    //
+
+    public Object decode(BerInputStream in) throws IOException {
+        in.readSequenceOf(this);
+
+        if (in.isVerify) {
+            return null;
+        }
+        return getDecodedObject(in);
+    }
+
+    //
+    //
+    // Encode
+    //
+    //
+
+    public final void encodeContent(BerOutputStream out) {
+        out.encodeSequenceOf(this);
+    }
+
+    public final void setEncodingContent(BerOutputStream out) {
+        out.getSequenceOfLength(this);
+    }
+
+    /**
+     * Creates array wrapper of provided ASN1 type
+     *
+     * @param type - ASN1 type to be wrapped
+     * @return - a wrapper for ASN1 set of type. 
+     * @throws IOException
+     * @see org.apache.harmony.security.asn1.ASN1ValueCollection
+     */
+    public static ASN1SequenceOf asArrayOf(ASN1Type type) {
+
+        return new ASN1SequenceOf(type) {
+            public Object getDecodedObject(BerInputStream in)
+                    throws IOException {
+                return ((List) in.content).toArray();
+            }
+
+            public Collection getValues(Object object) {
+                return Arrays.asList((Object[]) object);
+            }
+        };
+    }
+}
+

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Set.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Set.java?view=auto&rev=548598
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Set.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Set.java Mon Jun 18 22:58:08 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.
+ */
+
+/**
+* @author Vladimir N. Molotkov, Stepan M. Mishura
+* @version $Revision$
+*/
+
+package org.apache.harmony.jndi.asn1;
+
+import java.io.IOException;
+
+
+/**
+ * This class represents ASN.1 Set type.
+ * 
+ * @see http://asn1.elibel.tm.fr/en/standards/index.htm
+ */
+
+public class ASN1Set extends ASN1TypeCollection {
+
+    public ASN1Set(ASN1Type[] type) {
+        super(TAG_SET, type);
+
+        //FIXME implement check for distinct tags
+        //if (!hasDistinctTags(type)) {
+        //    throw new RuntimeException("ASN1 set type: " + getClass().getName()
+        //            + " MUST have alternatives with distinct tags");
+        //}
+    }
+
+    //
+    //
+    // Decode
+    //
+
+    public Object decode(BerInputStream in) throws IOException {
+        in.readSet(this);
+        
+        if(in.isVerify){
+            return null;
+        }
+        return getDecodedObject(in);
+    }
+
+    //
+    //
+    // Encode
+    //
+    //
+    public final void encodeContent(BerOutputStream out) {
+        out.encodeSet(this);
+    }
+
+    public final void setEncodingContent(BerOutputStream out) {
+        out.getSetLength(this);
+    }
+}
\ No newline at end of file

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1SetOf.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1SetOf.java?view=auto&rev=548598
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1SetOf.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1SetOf.java Mon Jun 18 22:58:08 2007
@@ -0,0 +1,92 @@
+/*
+ *  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.
+ */
+
+/**
+* @author Vladimir N. Molotkov, Stepan M. Mishura
+* @version $Revision$
+*/
+
+package org.apache.harmony.jndi.asn1;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+
+/**
+ * This class represents ASN.1 SetOf type.
+ * 
+ * @see http://asn1.elibel.tm.fr/en/standards/index.htm
+ */
+
+public class ASN1SetOf extends ASN1ValueCollection {
+
+    public ASN1SetOf(ASN1Type type) {
+        super(TAG_SETOF, type);
+    }
+
+    //
+    //
+    // Decode
+    //
+
+    public Object decode(BerInputStream in) throws IOException {
+        in.readSetOf(this);
+
+        if (in.isVerify) {
+            return null;
+        }
+        return getDecodedObject(in);
+    }
+
+    //
+    //
+    // Encode
+    //
+    //
+    public final void encodeContent(BerOutputStream out) {
+        out.encodeSetOf(this);
+    }
+
+    public final void setEncodingContent(BerOutputStream out) {
+        out.getSetOfLength(this);
+    }
+
+    /**
+     * Creates array wrapper of provided ASN1 type
+     *
+     * @param type - ASN1 type to be wrapped
+     * @return - a wrapper for ASN1 set of type. 
+     * @throws IOException
+     * @see org.apache.harmony.security.asn1.ASN1ValueCollection
+     */
+    public static ASN1SetOf asArrayOf(ASN1Type type) throws IOException {
+
+        return new ASN1SetOf(type) {
+            public Object getDecodedObject(BerInputStream in)
+                    throws IOException {
+                return ((List) in.content).toArray();
+            }
+
+            public Collection getValues(Object object) {
+                return Arrays.asList((Object[]) object);
+            }
+        };
+    }
+}
+

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1StringType.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1StringType.java?view=auto&rev=548598
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1StringType.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1StringType.java Mon Jun 18 22:58:08 2007
@@ -0,0 +1,147 @@
+/*
+ *  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.
+ */
+
+/**
+* @author Vladimir N. Molotkov, Stepan M. Mishura
+* @version $Revision$
+*/
+
+package org.apache.harmony.jndi.asn1;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+
+
+/**
+ * This class is the super class for all string ASN.1 types
+ * 
+ * @see http://asn1.elibel.tm.fr/en/standards/index.htm
+ */
+
+public abstract class ASN1StringType extends ASN1Type {
+
+    // TODO: what about defining them as separate classes?  
+    // TODO: check decoded/encoded characters
+    public static final ASN1StringType BMPSTRING = new ASN1StringType(
+            TAG_BMPSTRING) {
+    };
+
+    public static final ASN1StringType IA5STRING = new ASN1StringType(
+            TAG_IA5STRING) {
+    };
+
+    public static final ASN1StringType GENERALSTRING = new ASN1StringType(
+            TAG_GENERALSTRING) {
+    };
+
+    public static final ASN1StringType PRINTABLESTRING = new ASN1StringType(
+            TAG_PRINTABLESTRING) {
+    };
+
+    public static final ASN1StringType TELETEXSTRING = new ASN1StringType(
+            TAG_TELETEXSTRING) {
+    };
+
+    public static final ASN1StringType UNIVERSALSTRING = new ASN1StringType(
+            TAG_UNIVERSALSTRING) {
+    };
+
+    public static final ASN1StringType UTF8STRING = new ASN1StringType(
+            TAG_UTF8STRING) {
+
+        public Object getDecodedObject(BerInputStream in) throws IOException {
+            return new String(in.buffer, in.contentOffset, in.length, "UTF-8"); //$NON-NLS-1$
+        }
+
+        public void setEncodingContent(BerOutputStream out) {
+
+            try {
+                byte[] bytes = ((String) out.content).getBytes("UTF-8"); //$NON-NLS-1$
+                out.content = bytes;
+                out.length = bytes.length;
+            } catch (UnsupportedEncodingException e) {
+                throw new RuntimeException(e.getMessage());
+            }
+        }
+    };
+
+    public ASN1StringType(int tagNumber) {
+        super(tagNumber);
+    }
+
+    //
+    //
+    // Decode
+    //
+    //
+
+    /**
+     * Tests provided identifier.
+     * 
+     * @param identifier -
+     *            identifier to be verified
+     * @return - true if identifier correspond to primitive or constructed
+     *         identifier of this ASN.1 string type, otherwise false
+     */
+    public final boolean checkTag(int identifier) {
+        return this.id == identifier || this.constrId == identifier;
+    }
+
+    public Object decode(BerInputStream in) throws IOException {
+
+        in.readString(this);
+        
+        if (in.isVerify) {
+            return null;
+        }
+        return getDecodedObject(in);
+    }
+
+    /**
+     * Extracts String object from BER input stream.
+     *
+     * @param in - BER input stream
+     * @return java.land.String object
+     */
+    public Object getDecodedObject(BerInputStream in) throws IOException {
+        return new String(in.buffer, in.contentOffset, in.length);
+    }
+
+    //
+    //
+    // Encode
+    //
+    //
+    
+    public void encodeASN(BerOutputStream out) {
+        out.encodeTag(id);
+        encodeContent(out);
+    }
+
+    public void encodeContent(BerOutputStream out) {
+        out.encodeString();
+    }
+
+    public void setEncodingContent(BerOutputStream out) {
+
+        byte[] bytes = ((String) out.content).getBytes();
+
+        out.content = bytes;
+        out.length = bytes.length;
+    }
+}
+

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Time.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Time.java?view=auto&rev=548598
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Time.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Time.java Mon Jun 18 22:58:08 2007
@@ -0,0 +1,64 @@
+/*
+ *  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.
+ */
+
+/**
+* @author Stepan M. Mishura
+* @version $Revision$
+*/
+
+package org.apache.harmony.jndi.asn1;
+
+import java.io.IOException;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.TimeZone;
+
+
+/**
+ * Abstract class to represent ASN.1 time types
+ * 
+ * @see http://asn1.elibel.tm.fr/en/standards/index.htm
+ */
+
+public abstract class ASN1Time extends ASN1StringType {
+
+    /**
+     * TODO Put ctor description here
+     * 
+     * @param tagNumber
+     */
+    public ASN1Time(int tagNumber) {
+        super(tagNumber);
+    }
+
+    public Object getDecodedObject(BerInputStream in) throws IOException {
+        
+        // TODO optimize me:
+        // It makes sense use calendar instance instead of times array
+        GregorianCalendar c = new GregorianCalendar(TimeZone.getTimeZone("GMT")); //$NON-NLS-1$
+        
+        c.set(Calendar.YEAR, in.times[0]);
+        c.set(Calendar.MONTH, in.times[1]-1);
+        c.set(Calendar.DAY_OF_MONTH, in.times[2]);
+        c.set(Calendar.HOUR_OF_DAY, in.times[3]);
+        c.set(Calendar.MINUTE, in.times[4]);
+        c.set(Calendar.SECOND, in.times[5]);
+        c.set(Calendar.MILLISECOND, in.times[6]);
+        
+        return c.getTime();
+    }
+}

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Type.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Type.java?view=auto&rev=548598
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Type.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1Type.java Mon Jun 18 22:58:08 2007
@@ -0,0 +1,208 @@
+/*
+ *  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.
+ */
+
+/**
+* @author Vladimir N. Molotkov, Stepan M. Mishura
+* @version $Revision$
+*/
+
+package org.apache.harmony.jndi.asn1;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.harmony.jndi.internal.nls.Messages;
+
+
+/**
+ * This abstract class is the super class for all ASN.1 types
+ * 
+ * @see http://asn1.elibel.tm.fr/en/standards/index.htm
+ */
+
+public abstract class ASN1Type implements ASN1Constants {
+
+    /**
+     * Integer representation of primitive identifier.
+     */
+    public final int id;
+
+    /**
+     * Integer representation of constructed identifier.
+     */
+    public final int constrId;
+
+    /**
+     * Constructs a primitive, universal ASN.1 type.
+     * 
+     * @param tagNumber - ASN.1 tag number
+     * @throws IllegalArgumentException - if tagNumber is invalid
+     */
+    public ASN1Type(int tagNumber) {
+        this(CLASS_UNIVERSAL, tagNumber);
+    }
+
+    /**
+     * Constructs an ASN.1 type.
+     * 
+     * @param tagClass - tag class. MUST be
+     *     CLASS_UNIVERSAL, CLASS_APPLICATION, CLASS_CONTEXTSPECIFIC, CLASS_PRIVATE
+     * @param isConstructed - is ASN.1 type is a constructed type.
+     * @param tagNumber - ASN.1 tag number.
+     * @throws IllegalArgumentException - if tagClass or tagNumber is invalid
+     */
+    public ASN1Type(int tagClass, int tagNumber) {
+
+        if (tagNumber < 0) {
+            throw new IllegalArgumentException(Messages.getString("security.102")); //$NON-NLS-1$
+        }
+
+        if (tagClass != CLASS_UNIVERSAL && tagClass != CLASS_APPLICATION
+                && tagClass != CLASS_CONTEXTSPECIFIC
+                && tagClass != CLASS_PRIVATE) {
+            throw new IllegalArgumentException(Messages.getString("security.103")); //$NON-NLS-1$
+        }
+
+        if (tagNumber < 31) {
+            // short form
+            this.id = tagClass + tagNumber;
+        } else {
+            // long form
+            throw new IllegalArgumentException(
+                    Messages.getString("security.104")); //$NON-NLS-1$
+        }
+        this.constrId = this.id + PC_CONSTRUCTED;
+    }
+
+    //
+    //
+    // Stubs for DER
+    //
+    //
+
+    public final Object decode(byte[] encoded) throws IOException {
+        return decode(new BerInputStream(encoded));
+    }
+
+    public final Object decode(byte[] encoded, int offset, int encodingLen)
+            throws IOException {
+        return decode(new BerInputStream(encoded, offset, encodingLen));
+    }
+
+    public final Object decode(InputStream in) throws IOException {
+        return decode(new BerInputStream(in));
+    }
+
+    public final void verify(byte[] encoded) throws IOException {
+        BerInputStream decoder = new BerInputStream(encoded);
+        decoder.setVerify();
+        decode(decoder);
+    }
+
+    public final void verify(InputStream in) throws IOException {
+        BerInputStream decoder = new BerInputStream(in);
+        decoder.setVerify();
+        decode(decoder);
+    }
+
+    //
+    //
+    // Decode
+    //
+    //
+
+    /**
+     * Decodes ASN.1 type.
+     * 
+     * @param in -
+     *            BER input stream
+     * @throws IOException -
+     *             if an I/O error occurs or the end of the stream is reached
+     */
+    public abstract Object decode(BerInputStream in) throws IOException;
+
+    /**
+     * Tests provided identifier.
+     * 
+     * @param identifier -
+     *            identifier to be verified
+     * @return - true if identifier is associated with this ASN.1 type,
+     *         otherwise false
+     */
+    public abstract boolean checkTag(int identifier);
+
+    /**
+     * Creates decoded object.
+     * 
+     * Derived classes should override this method to provide creation for a
+     * selected class of objects during decoding.
+     * 
+     * The default implementation returns an object created by decoding stream.
+     * 
+     * @param -
+     *            input stream
+     * @return - created object
+     */
+    //FIXME make me public
+    protected Object getDecodedObject(BerInputStream in) throws IOException {
+        return in.content;
+    }
+
+    //
+    //
+    // Encode
+    //
+    //
+
+    /**
+     * Encodes ASN.1 type.
+     *
+     * @param out - BER output stream
+     */
+    public abstract void encodeASN(BerOutputStream out);
+
+    public abstract void encodeContent(BerOutputStream out);
+
+    public abstract void setEncodingContent(BerOutputStream out);
+
+    public int getEncodedLength(BerOutputStream out) { //FIXME name
+
+        //tag length
+        int len = 1; //FIXME tag length = 1. what about long form?
+        //for (; tag > 0; tag = tag >> 8, len++);
+
+        // length length :-)
+        len++;
+        if (out.length > 127) {
+
+            len++;
+            for (int cur = out.length >> 8; cur > 0; len++) {
+                cur = cur >> 8;
+            }
+        }
+        len += out.length;
+
+        return len;
+    }
+
+    public String toString() {
+        // TODO decide whether this method is necessary
+        //FIXME fix performance
+        return this.getClass().getName() + "(tag: 0x" //$NON-NLS-1$
+                + Integer.toHexString(0xff & this.id) + ")"; //$NON-NLS-1$
+    }
+}
\ No newline at end of file

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1TypeCollection.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1TypeCollection.java?view=auto&rev=548598
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1TypeCollection.java (added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/asn1/ASN1TypeCollection.java Mon Jun 18 22:58:08 2007
@@ -0,0 +1,98 @@
+/*
+ *  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.
+ */
+
+/**
+* @author Vladimir N. Molotkov, Stepan M. Mishura
+* @version $Revision$
+*/
+
+package org.apache.harmony.jndi.asn1;
+
+import org.apache.harmony.jndi.internal.nls.Messages;
+
+
+/**
+ * This abstract class represents ASN.1 type that is a collection of ASN.1 types.
+ * 
+ * @see http://asn1.elibel.tm.fr/en/standards/index.htm
+ */
+
+public abstract class ASN1TypeCollection extends ASN1Constructured {
+
+    public final ASN1Type[] type; //TODO comment me
+
+    public final boolean[] OPTIONAL; //TODO comment me
+
+    public final Object[] DEFAULT; //TODO comment me
+
+    /**
+     * Constructs ASN.1 collection type.
+     * 
+     * @param tagNumber - ASN.1 tag number
+     * @param type - a collection of one or more ASN.1 types. 
+     * @throws IllegalArgumentException - if tagNumber is invalid
+     */
+    public ASN1TypeCollection(int tagNumber, ASN1Type[] type) {
+        super(tagNumber);
+        // FIXME what about empty sequence?
+        //        if (type.length == 0) {
+        //            throw new ASN1Exception("ASN1 collection type: "
+        //                    + getClass().getName()
+        //                    + " MUST have at least one component");
+        //        }
+
+        this.type = type;
+        this.OPTIONAL = new boolean[type.length];
+        this.DEFAULT = new Object[type.length];
+    }
+
+    /**
+     * Sets a collection component as optional
+     *
+     * @param index - an index of a component
+     */
+    protected final void setOptional(int index) {
+        OPTIONAL[index] = true;
+    }
+
+    /**
+     * Sets a default value for a collection component.
+     * The component also became an optional component.
+     *
+     * @param object - a component's default value
+     * @param index - an index of a component
+     */
+    protected final void setDefault(Object object, int index) {
+        OPTIONAL[index] = true;
+        DEFAULT[index] = object;
+    }
+
+    /**
+     * Provides an object's values to be encoded
+     * 
+     * Derived classes should override this method to provide
+     * encoding for a selected class of objects. 
+     * 
+     * The default implementation throws RuntimeException.
+     *
+     * @param object - an object to be encoded
+     * @param values - an array to store an object's values to be encoded
+     */
+    protected void getValues(Object object, Object[] values) {
+        throw new RuntimeException(Messages.getString("security.101", getClass().getName())); //$NON-NLS-1$
+    }
+}
\ No newline at end of file



Mime
View raw message