harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r370554 - /incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/
Date Thu, 19 Jan 2006 17:50:29 GMT
Author: geirm
Date: Thu Jan 19 09:50:26 2006
New Revision: 370554

URL: http://svn.apache.org/viewcvs?rev=370554&view=rev
Log:
from com.openintel.drl - eclipse seems to have messed up 
the .svn stuff, so deleted and doing a fresh add

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/
    incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/AttributeType.java
    incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/AttributeTypeAndValue.java
    incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/AttributeTypeAndValueComparator.java
    incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/AttributeValue.java
    incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/Attributes.java
    incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/DirectoryString.java
    incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/Name.java
    incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/svn-commit.tmp

Added: incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/AttributeType.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/AttributeType.java?rev=370554&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/AttributeType.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/AttributeType.java Thu Jan 19 09:50:26 2006
@@ -0,0 +1,45 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+* @author Stepan M. Mishura
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.x501;
+
+import org.apache.harmony.security.asn1.ASN1Type;
+import org.apache.harmony.security.asn1.ObjectIdentifier;
+
+
+/**
+ * X.501 Attribute Type
+ * 
+ * This is a draft class for Module InformationFramework (X.501).
+ * 
+ * @see http://www.itu.int/ITU-T/asn1/database/itu-t/x/x501/2001/InformationFramework.html 
+ */
+
+public class AttributeType {
+
+    public final ObjectIdentifier oid;
+
+    public final ASN1Type type;
+
+    public AttributeType(ObjectIdentifier oid, ASN1Type type) {
+        this.oid = oid;
+        this.type = type;
+    }
+}
\ No newline at end of file

Added: incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/AttributeTypeAndValue.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/AttributeTypeAndValue.java?rev=370554&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/AttributeTypeAndValue.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/AttributeTypeAndValue.java Thu Jan 19 09:50:26 2006
@@ -0,0 +1,578 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+* @author Alexander V. Esin, Stepan M. Mishura
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.x501;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import javax.security.auth.x500.X500Principal;
+
+import org.apache.harmony.security.asn1.ASN1Constants;
+import org.apache.harmony.security.asn1.ASN1Oid;
+import org.apache.harmony.security.asn1.ASN1Sequence;
+import org.apache.harmony.security.asn1.ASN1StringType;
+import org.apache.harmony.security.asn1.ASN1Type;
+import org.apache.harmony.security.asn1.BerInputStream;
+import org.apache.harmony.security.asn1.BerOutputStream;
+import org.apache.harmony.security.utils.ObjectIdentifier;
+
+
+/**
+ * X.501 AttributeTypeAndValue
+ */
+public class AttributeTypeAndValue {
+
+    // Country code attribute (name from RFC 1779)
+    private static final ObjectIdentifier C;
+
+    // Common name attributem (name from RFC 1779)
+    private static final ObjectIdentifier CN;
+
+    // Domain component attribute (name from RFC 2253)
+    private static final ObjectIdentifier DC;
+
+    // DN qualifier attribute (name from API spec)
+    private static final ObjectIdentifier DNQ;
+
+    private static final ObjectIdentifier DNQUALIFIER;
+
+    // Email Address attribute (name from API spec)
+    private static final ObjectIdentifier EMAILADDRESS;
+
+    // Generation attribute (qualifies an individual's name)
+    // (name from API spec)
+    private static final ObjectIdentifier GENERATION;
+
+    // Given name attribute (name from API spec)
+    private static final ObjectIdentifier GIVENNAME;
+
+    // Initials attribute (initials of an individual's name)
+    // (name from API spec)
+    private static final ObjectIdentifier INITIALS;
+
+    // Name of a locality attribute (name from RFC 1779)
+    private static final ObjectIdentifier L;
+
+    // Organization name attribute (name from RFC 1779)
+    private static final ObjectIdentifier O;
+
+    // Organizational unit name attribute (name from RFC 1779)
+    private static final ObjectIdentifier OU;
+
+    // Serial number attribute (serial number of a device)
+    // (name from API spec)
+    private static final ObjectIdentifier SERIALNUMBER;
+
+    // Attribute for the full name of a state or province
+    // (name from RFC 1779)
+    private static final ObjectIdentifier ST;
+
+    // Street attribute (name from RFC 1779)
+    private static final ObjectIdentifier STREET;
+
+    // Surname attribute (comes from an individual's parent name) 
+    // (name from API spec)
+    private static final ObjectIdentifier SURNAME;
+
+    // Title attribute (object in an organzation)(name from API spec)
+    private static final ObjectIdentifier T;
+
+    // User identifier attribute (name from RFC 2253)
+    private static final ObjectIdentifier UID;
+
+    //
+    // OID's pool
+    //
+
+    // pool's capacity
+    private static final int CAPACITY;
+
+    // pool's size
+    private static final int SIZE;
+
+    // pool: contains all recognizable attribute type keywords
+    private static final ObjectIdentifier[][] KNOWN_OIDS;
+
+    // known keywords attribute
+    private static final HashMap KNOWN_NAMES = new HashMap(30);
+
+    // known attribute types for RFC1779 (see Table 1)
+    private static final HashMap RFC1779_NAMES = new HashMap(10);
+
+    // known attribute types for RFC2253
+    // (see 2.3.  Converting AttributeTypeAndValue)
+    private static final HashMap RFC2253_NAMES = new HashMap(10);
+
+    // known attribute types for RFC2459 (see API spec.)
+    private static final HashMap RFC2459_NAMES = new HashMap(10);
+
+    static {
+
+        // pool initialization
+        CAPACITY = 10;
+        SIZE = 10;
+        KNOWN_OIDS = new ObjectIdentifier[SIZE][CAPACITY];
+
+        // init known attribute type keywords
+        C = new ObjectIdentifier(new int[] { 2, 5, 4, 6 }, "C", RFC1779_NAMES);
+        CN = new ObjectIdentifier(new int[] { 2, 5, 4, 3 }, "CN", RFC1779_NAMES);
+
+        DC = new ObjectIdentifier(
+                new int[] { 0, 9, 2342, 19200300, 100, 1, 25 }, "DC",
+                RFC2253_NAMES);
+        // DN qualifier aliases
+        DNQ = new ObjectIdentifier(new int[] { 2, 5, 4, 46 }, "DNQ",
+                RFC2459_NAMES);
+        DNQUALIFIER = new ObjectIdentifier(new int[] { 2, 5, 4, 46 },
+                "DNQUALIFIER", RFC2459_NAMES);
+
+        EMAILADDRESS = new ObjectIdentifier(new int[] { 1, 2, 840, 113549, 1,
+                9, 1 }, "EMAILADDRESS", RFC2459_NAMES);
+
+        GENERATION = new ObjectIdentifier(new int[] { 2, 5, 4, 44 },
+                "GENERATION", RFC2459_NAMES);
+        GIVENNAME = new ObjectIdentifier(new int[] { 2, 5, 4, 42 },
+                "GIVENNAME", RFC2459_NAMES);
+
+        INITIALS = new ObjectIdentifier(new int[] { 2, 5, 4, 43 }, "INITIALS",
+                RFC2459_NAMES);
+
+        L = new ObjectIdentifier(new int[] { 2, 5, 4, 7 }, "L", RFC1779_NAMES);
+
+        O = new ObjectIdentifier(new int[] { 2, 5, 4, 10 }, "O", RFC1779_NAMES);
+        OU = new ObjectIdentifier(new int[] { 2, 5, 4, 11 }, "OU",
+                RFC1779_NAMES);
+
+        SERIALNUMBER = new ObjectIdentifier(new int[] { 2, 5, 4, 5 },
+                "SERIALNUMBER", RFC2459_NAMES);
+        ST = new ObjectIdentifier(new int[] { 2, 5, 4, 8 }, "ST", RFC1779_NAMES);
+        STREET = new ObjectIdentifier(new int[] { 2, 5, 4, 9 }, "STREET",
+                RFC1779_NAMES);
+        SURNAME = new ObjectIdentifier(new int[] { 2, 5, 4, 4 }, "SURNAME",
+                RFC2459_NAMES);
+
+        T = new ObjectIdentifier(new int[] { 2, 5, 4, 12 }, "T", RFC2459_NAMES);
+
+        UID = new ObjectIdentifier(
+                new int[] { 0, 9, 2342, 19200300, 100, 1, 1 }, "UID",
+                RFC2253_NAMES);
+
+        //
+        // RFC1779
+        //
+        RFC1779_NAMES.put(CN.getName(), CN);
+        RFC1779_NAMES.put(L.getName(), L);
+        RFC1779_NAMES.put(ST.getName(), ST);
+        RFC1779_NAMES.put(O.getName(), O);
+        RFC1779_NAMES.put(OU.getName(), OU);
+        RFC1779_NAMES.put(C.getName(), C);
+        RFC1779_NAMES.put(STREET.getName(), STREET);
+
+        //
+        // RFC2253: includes all from RFC1779
+        //
+        RFC2253_NAMES.putAll(RFC1779_NAMES);
+
+        RFC2253_NAMES.put(DC.getName(), DC);
+        RFC2253_NAMES.put(UID.getName(), UID);
+
+        //
+        // RFC2459
+        //
+        RFC2459_NAMES.put(DNQ.getName(), DNQ);
+        RFC2459_NAMES.put(DNQUALIFIER.getName(), DNQUALIFIER);
+        RFC2459_NAMES.put(EMAILADDRESS.getName(), EMAILADDRESS);
+        RFC2459_NAMES.put(GENERATION.getName(), GENERATION);
+        RFC2459_NAMES.put(GIVENNAME.getName(), GIVENNAME);
+        RFC2459_NAMES.put(INITIALS.getName(), INITIALS);
+        RFC2459_NAMES.put(SERIALNUMBER.getName(), SERIALNUMBER);
+        RFC2459_NAMES.put(SURNAME.getName(), SURNAME);
+        RFC2459_NAMES.put(T.getName(), T);
+
+        //
+        // Init KNOWN_OIDS pool
+        //
+
+        // add from RFC2253 (includes RFC1779) 
+        Iterator it = RFC2253_NAMES.values().iterator();
+        while (it.hasNext()) {
+            addOID((ObjectIdentifier) it.next());
+        }
+
+        // add attributes from RFC2459
+        it = RFC2459_NAMES.values().iterator();
+        while (it.hasNext()) {
+            Object o = it.next();
+
+            //don't add DNQUALIFIER because it has the same oid as DNQ
+            if (!(o == DNQUALIFIER)) {
+                addOID((ObjectIdentifier) o);
+            }
+        }
+
+        //
+        // Init KNOWN_NAMES pool
+        //
+
+        KNOWN_NAMES.putAll(RFC2253_NAMES); // RFC2253 includes RFC1779
+        KNOWN_NAMES.putAll(RFC2459_NAMES);
+    }
+
+    //Attribute type
+    private final ObjectIdentifier oid;
+
+    //Attribute value
+    private AttributeValue value;
+
+    // for decoder only
+    private AttributeTypeAndValue(int[] oid, AttributeValue value)
+            throws IOException {
+
+        ObjectIdentifier thisOid = getOID(oid);
+        if (thisOid == null) {
+            thisOid = new ObjectIdentifier(oid);
+        }
+        this.oid = thisOid;
+        this.value = value;
+    }
+
+    /**
+     * Creates AttributeTypeAndValue with OID and AttributeValue. Parses OID
+     * string representation
+     * 
+     * @param sOid
+     *            string representation of OID
+     * @param value
+     *            attribute value
+     * @throws IOException
+     *             if OID can not be created from its string representation
+     */
+    public AttributeTypeAndValue(String sOid, AttributeValue value) {
+        if (sOid.charAt(0) >= '0' && sOid.charAt(0) <= '9') {
+
+            int[] array = org.apache.harmony.security.asn1.ObjectIdentifier
+                    .toIntArray(sOid);
+
+            ObjectIdentifier thisOid = getOID(array);
+            if (thisOid == null) {
+                thisOid = new ObjectIdentifier(array);
+            }
+            this.oid = thisOid;
+
+        } else {
+            this.oid = (ObjectIdentifier) KNOWN_NAMES.get(sOid.toUpperCase());
+            if (this.oid == null) {
+                throw new IllegalArgumentException(
+                        "Unrecognizable attribute name: " + sOid);
+            }
+        }
+        this.value = value;
+    }
+
+    /**
+     * Appends AttributeTypeAndValue string representation
+     * 
+     * @param attrFormat - format of DN
+     * @param buf - string buffer to be used
+     */
+    public void appendName(String attrFormat, StringBuffer buf) {
+
+        boolean hexFormat = false;
+        if (attrFormat == X500Principal.RFC1779) {
+            if (RFC1779_NAMES == oid.getGroup()) {
+                buf.append(oid.getName());
+            } else {
+                buf.append(oid.toOIDString());
+            }
+
+            buf.append('=');
+            if (value.escapedString == value.getHexString()) {
+                //FIXME all chars in upper case
+                buf.append(value.getHexString().toUpperCase());
+            } else if (value.escapedString.length() != value.rawString.length()) {
+                // was escaped
+                value.appendQEString(buf);
+            } else {
+                buf.append(value.escapedString);
+            }
+        } else {
+            Object group = oid.getGroup();
+            // RFC2253 includes names from RFC1779
+            if (RFC1779_NAMES == group || RFC2253_NAMES == group) {
+                buf.append(oid.getName());
+
+                if (attrFormat == X500Principal.CANONICAL) {
+                    // only PrintableString and UTF8String in string format
+                    // all others are output in hex format
+                    int tag = value.getTag();
+                    if (!ASN1StringType.UTF8STRING.checkTag(tag)
+                            && !ASN1StringType.PRINTABLESTRING.checkTag(tag)) {
+                        hexFormat = true;
+                    }
+                }
+
+            } else {
+                buf.append(oid.toString());
+                hexFormat = true;
+            }
+
+            buf.append('=');
+
+            if (hexFormat) {
+                buf.append(value.getHexString());
+            } else {
+                if (attrFormat == X500Principal.CANONICAL) {
+                    buf.append(value.makeCanonical());
+                } else {
+                    buf.append(value.escapedString);
+                }
+            }
+        }
+    }
+
+    /**
+     * Gets type of the AttributeTypeAndValue
+     * 
+     * @return ObjectIdentifier
+     */
+    public ObjectIdentifier getType() {
+        return oid;
+    }
+
+    /**
+     * According to RFC 3280 (http://www.ietf.org/rfc/rfc3280.txt) 
+     * X.501 AttributeTypeAndValue structure is defined as follows:
+     *  
+     *   AttributeTypeAndValue ::= SEQUENCE {
+     *      type     AttributeType,
+     *      value    AttributeValue }
+     *   
+     *    AttributeType ::= OBJECT IDENTIFIER
+     *  
+     *    AttributeValue ::= ANY DEFINED BY AttributeType
+     *    ...
+     *    DirectoryString ::= CHOICE {
+     *          teletexString           TeletexString (SIZE (1..MAX)),
+     *          printableString         PrintableString (SIZE (1..MAX)),
+     *          universalString         UniversalString (SIZE (1..MAX)),
+     *          utf8String              UTF8String (SIZE (1.. MAX)),
+     *          bmpString               BMPString (SIZE (1..MAX)) }
+     *  
+     */
+
+    public static ASN1Type AttributeValue = new ASN1Type(
+            ASN1Constants.TAG_PRINTABLESTRING) {
+
+        public boolean checkTag(int tag) {
+            return true;
+        }
+
+        public void verify(BerInputStream in) throws IOException {
+
+            switch (in.tag) {
+            case ASN1Constants.TAG_TELETEXSTRING:
+                ASN1StringType.TELETEXSTRING.verify(in);
+                break;
+            case ASN1Constants.TAG_PRINTABLESTRING:
+                ASN1StringType.PRINTABLESTRING.verify(in);
+                break;
+            case ASN1Constants.TAG_UNIVERSALSTRING:
+                ASN1StringType.UNIVERSALSTRING.verify(in);
+                break;
+            case ASN1Constants.TAG_UTF8STRING:
+                ASN1StringType.UTF8STRING.verify(in);
+                break;
+            case ASN1Constants.TAG_BMPSTRING:
+                ASN1StringType.BMPSTRING.verify(in);
+                break;
+            }
+            in.readContent();
+        }
+
+        public Object decode(BerInputStream in) throws IOException {
+
+            // FIXME what about constr???
+            String str = null;
+
+            switch (in.tag) {
+            case ASN1Constants.TAG_TELETEXSTRING:
+                str = (String) ASN1StringType.TELETEXSTRING.decode(in);
+                break;
+            case ASN1Constants.TAG_PRINTABLESTRING:
+                str = (String) ASN1StringType.PRINTABLESTRING.decode(in);
+                break;
+            case ASN1Constants.TAG_UNIVERSALSTRING:
+                str = (String) ASN1StringType.UNIVERSALSTRING.decode(in);
+                break;
+            case ASN1Constants.TAG_UTF8STRING:
+                str = (String) ASN1StringType.UTF8STRING.decode(in);
+                break;
+            case ASN1Constants.TAG_BMPSTRING:
+                str = (String) ASN1StringType.BMPSTRING.decode(in);
+                break;
+            default:
+                in.readContent();
+            }
+
+            byte[] bytesEncoded = new byte[in.getOffset() - in.getTagOffset()];
+            System.arraycopy(in.getBuffer(), in.getTagOffset(), bytesEncoded,
+                    0, bytesEncoded.length);
+
+            return new AttributeValue(str, bytesEncoded, in.tag);
+        }
+
+        public Object getDecodedObject(BerInputStream in) throws IOException {
+            // stub to avoid wrong decoder usage
+            throw new RuntimeException(
+                    "AttributeValue getDecodedObject MUST not be invoked");
+        }
+
+        //
+        // Encode
+        //
+        public void encodeASN(BerOutputStream out) {
+
+            AttributeValue av = (AttributeValue) out.content;
+
+            if (av.encoded != null) {
+                out.content = av.encoded;
+                out.encodeANY();
+            } else {
+                out.encodeTag(av.getTag());
+                out.content = av.bytes;
+                out.encodeString();
+            }
+        }
+
+        public void setEncodingContent(BerOutputStream out) {
+            
+            AttributeValue av = (AttributeValue) out.content;
+
+            if (av.encoded != null) {
+                out.length = av.encoded.length;
+            } else {
+
+                if (av.getTag() == ASN1Constants.TAG_UTF8STRING) {
+
+                    out.content = av.rawString;
+
+                    ASN1StringType.UTF8STRING.setEncodingContent(out);
+
+                    av.bytes = (byte[]) out.content;
+                    out.content = av;
+                } else {
+                    av.bytes = av.rawString.getBytes();
+                    out.length = av.bytes.length;
+                }
+            }
+        }
+
+        public void encodeContent(BerOutputStream out) {
+            // stub to avoid wrong encoder usage
+            throw new RuntimeException(
+                    "AttributeValue encodeContent MUST not be invoked");
+        }
+
+        public int getEncodedLength(BerOutputStream out) { //FIXME name
+
+            AttributeValue av = (AttributeValue) out.content;
+
+            if (av.encoded != null) {
+                return out.length;
+            } else {
+                return super.getEncodedLength(out);
+            }
+        }
+    };
+
+    public static final ASN1Sequence ASN1 = new ASN1Sequence(new ASN1Type[] {
+            ASN1Oid.getInstance(), AttributeValue }) {
+
+        protected Object getDecodedObject(BerInputStream in) throws IOException {
+            Object[] values = (Object[]) in.content;
+            return new AttributeTypeAndValue((int[]) values[0],
+                    (AttributeValue) values[1]);
+        }
+
+        protected void getValues(Object object, Object[] values) {
+            AttributeTypeAndValue atav = (AttributeTypeAndValue) object;
+
+            values[0] = atav.oid.getOid();
+            values[1] = atav.value;
+        }
+    };
+
+    // returns known OID or null
+    private static ObjectIdentifier getOID(int[] oid) {
+
+        int index = hashIntArray(oid) % CAPACITY;
+
+        // look for OID in the pool 
+        ObjectIdentifier[] list = KNOWN_OIDS[index];
+        for (int i = 0; list[i] != null; i++) {
+            if (Arrays.equals(oid, list[i].getOid())) {
+                return list[i];
+            }
+        }
+        return null;
+    }
+
+    // adds known OID to pool
+    // for static AttributeTypeAndValue initialization only
+    private static void addOID(ObjectIdentifier oid) {
+
+        int[] newOid = oid.getOid();
+        int index = hashIntArray(newOid) % CAPACITY;
+
+        // look for OID in the pool 
+        ObjectIdentifier[] list = KNOWN_OIDS[index];
+        int i = 0;
+        for (; list[i] != null; i++) {
+
+            // check wrong static initialization: no duplicate OIDs
+            if (Arrays.equals(newOid, list[i].getOid())) {
+                throw new Error(
+                        "ObjectIdentifier: invalid static initialization"
+                                + " - duplicate OIDs:" + oid.getName() + ", "
+                                + list[i].getName());
+            }
+        }
+
+        // check : to avoid NPE
+        if (i == (CAPACITY - 1)) {
+            throw new Error("ObjectIdentifier: invalid static initialization"
+                    + " - small OID pool capacity");
+        }
+        list[i] = oid;
+    }
+
+    // returns hash for array of integers
+    private static int hashIntArray(int[] oid) {
+        int intHash = 0;
+        for (int i = 0; i < oid.length && i < 4; i++) {
+            intHash += oid[i] << (8 * i); //TODO what about to find better one?
+        }
+        return intHash & 0x7FFFFFFF; // only positive
+    }
+}
\ No newline at end of file

Added: incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/AttributeTypeAndValueComparator.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/AttributeTypeAndValueComparator.java?rev=370554&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/AttributeTypeAndValueComparator.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/AttributeTypeAndValueComparator.java Thu Jan 19 09:50:26 2006
@@ -0,0 +1,107 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+* @author Alexander V. Esin
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.x501;
+
+import java.util.Comparator;
+
+import org.apache.harmony.security.utils.ObjectIdentifier;
+
+/**
+ * AttributeTypeAndValue comparator
+ * 
+ */
+public class AttributeTypeAndValueComparator implements Comparator {
+
+    /**
+     * compares two AttributeTypeAndValues
+     * 
+     * @param obj1
+     *            first AttributeTypeAndValue
+     * @param obj2
+     *            second AttributeTypeAndValue
+     * @return -1 of first AttributeTypeAndValue "less" than second
+     *         AttributeTypeAndValue 1 otherwise, 0 if they are equal
+     */
+    public int compare(Object obj1, Object obj2) {
+        if (obj1 == obj2) {
+            return 0;
+        }
+
+        AttributeTypeAndValue atav1 = (AttributeTypeAndValue) obj1;
+        AttributeTypeAndValue atav2 = (AttributeTypeAndValue) obj2;
+        String kw1 = atav1.getType().getName();
+        String kw2 = atav2.getType().getName();
+        if (kw1 != null && kw2 == null) {
+            return -1;
+        }
+        if (kw1 == null && kw2 != null) {
+            return 1;
+        }
+        if (kw1 != null && kw2 != null) {
+            return kw1.compareTo(kw2);
+        }
+
+        return compateOids(atav1.getType(), atav2.getType());
+    }
+
+    /**
+     * @return false
+     */
+    public boolean equals(Object obj) {
+        return false;
+    }
+
+    /**
+     * compares two Object identifiers
+     * 
+     * @param oid1
+     *            first OID
+     * @param oid2
+     *            second OID
+     * @return -1 of first OID "less" than second OID 1 otherwise, 0 if they are
+     *         equal
+     */
+    private static int compateOids(ObjectIdentifier oid1, ObjectIdentifier oid2) {
+        if (oid1 == oid2) {
+            return 0;
+        }
+
+        int[] ioid1 = oid1.getOid();
+        int[] ioid2 = oid2.getOid();
+        int min = ioid1.length < ioid2.length ? ioid1.length : ioid2.length;
+        for (int i = 0; i < min; ++i) {
+            if (ioid1[i] < ioid2[i]) {
+                return -1;
+            }
+            if (ioid1[i] > ioid2[i]) {
+                return 1;
+            }
+            if ((i + 1) == ioid1.length && (i + 1) < ioid2.length) {
+                return -1;
+            }
+            if ((i + 1) < ioid1.length && (i + 1) == ioid2.length) {
+                return 1;
+            }
+        }
+        return 0;
+    }
+}
\ No newline at end of file

Added: incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/AttributeValue.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/AttributeValue.java?rev=370554&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/AttributeValue.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/AttributeValue.java Thu Jan 19 09:50:26 2006
@@ -0,0 +1,295 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+* @author Alexander V. Esin
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.x501;
+
+import java.io.IOException;
+
+import org.apache.harmony.security.asn1.ASN1Constants;
+import org.apache.harmony.security.asn1.ASN1StringType;
+import org.apache.harmony.security.asn1.ASN1Type;
+import org.apache.harmony.security.asn1.DerInputStream;
+import org.apache.harmony.security.x509.Utils;
+
+
+/**
+ * X.501 Attribute Value
+ */
+public class AttributeValue {
+
+    public final boolean wasEncoded;
+
+    public String escapedString;
+
+    private String hexString;
+
+    private int tag = -1;
+
+    public byte[] encoded;
+
+    public byte[] bytes; //FIXME remove??? bytes to be encoded
+
+    public boolean hasQE; // raw string contains '"' or '\'
+
+    public AttributeValue(String parsedString, boolean hasQorE) {
+
+        wasEncoded = false;
+
+        this.hasQE = hasQorE;
+
+        this.rawString = parsedString;
+        this.escapedString = makeEscaped(rawString);
+    }
+
+    public AttributeValue(String hexString, byte[] encoded) {
+
+        wasEncoded = true;
+
+        this.hexString = hexString;
+        this.encoded = encoded;
+
+        try {
+            DerInputStream in = new DerInputStream(encoded);
+            ASN1Type decoder = null;
+            switch (in.tag) {
+            case ASN1Constants.TAG_TELETEXSTRING:
+                decoder = ASN1StringType.TELETEXSTRING;
+                break;
+            case ASN1Constants.TAG_PRINTABLESTRING:
+                decoder = ASN1StringType.PRINTABLESTRING;
+                break;
+            case ASN1Constants.TAG_UNIVERSALSTRING:
+                decoder = ASN1StringType.UNIVERSALSTRING;
+                break;
+            case ASN1Constants.TAG_UTF8STRING:
+                decoder = ASN1StringType.UTF8STRING;
+                break;
+            case ASN1Constants.TAG_BMPSTRING:
+                decoder = ASN1StringType.BMPSTRING;
+                break;
+            }
+
+            if (in.getEndOffset() != encoded.length) {
+                // length of parsed hexString is greater than encoded length
+                throw new IllegalArgumentException();//FIXME message
+            }
+
+            tag = in.tag;
+
+            if (decoder != null) {
+                this.rawString = (String) decoder.decode(in);
+                this.escapedString = makeEscaped(rawString);
+            } else {
+                this.rawString = hexString;
+                this.escapedString = hexString;
+            }
+        } catch (IOException e) {
+            IllegalArgumentException iae = new IllegalArgumentException(); //FIXME message
+            iae.initCause(e);
+            throw iae;
+        }
+    }
+
+    public String rawString;
+
+    public AttributeValue(String rawString, byte[] encoded, int tag) {
+
+        wasEncoded = true;
+
+        this.encoded = encoded;
+        this.tag = tag;
+
+        if (rawString == null) {
+            this.rawString = getHexString();
+            this.escapedString = hexString;
+        } else {
+            this.rawString = rawString;
+            this.escapedString = makeEscaped(rawString);
+        }
+    }
+
+    public int getTag() {
+        if (tag == -1) {
+            if (Utils.isPrintableString(rawString)) {
+                tag = ASN1StringType.PRINTABLESTRING.tag;
+            } else {
+                tag = ASN1StringType.UTF8STRING.tag;
+            }
+        }
+        return tag;
+    }
+
+    public String getHexString() {
+        if (hexString == null) {
+
+            if (!wasEncoded) {
+                //FIXME optimize me: what about reusable OutputStream???
+                if (Utils.isPrintableString(rawString)) {
+                    encoded = ASN1StringType.PRINTABLESTRING.encode(rawString);
+                } else {
+                    encoded = ASN1StringType.UTF8STRING.encode(rawString);
+                }
+            }
+
+            StringBuffer buf = new StringBuffer(encoded.length * 2 + 1);
+            buf.append('#');
+
+            for (int i = 0, c; i < encoded.length; i++) {
+                c = (encoded[i] >> 4) & 0x0F;
+                if (c < 10) {
+                    buf.append((char) (c + 48));
+                } else {
+                    buf.append((char) (c + 87));
+                }
+
+                c = encoded[i] & 0x0F;
+                if (c < 10) {
+                    buf.append((char) (c + 48));
+                } else {
+                    buf.append((char) (c + 87));
+                }
+            }
+            hexString = buf.toString();
+        }
+        return hexString;
+    }
+
+    public void appendQEString(StringBuffer buf) {
+        buf.append('"');
+        if (hasQE) {
+            char c;
+            for (int i = 0; i < rawString.length(); i++) {
+                c = rawString.charAt(i);
+                if (c == '"' || c == '\\') {
+                    buf.append('\\');
+                }
+                buf.append(c);
+            }
+        } else {
+            buf.append(rawString);
+        }
+        buf.append('"');
+    }
+
+    //
+    // Escapes:
+    // 1) chars ",", "+", """, "\", "<", ">", ";" (RFC 2253) 
+    // 2) chars "#", "=" (required by RFC 1779)
+    // 3) a space char at the beggining or end
+    // 4) according to the requirement to be RFC 1779 compatible:
+    //    '#' char is escaped in any position
+    //
+    private String makeEscaped(String name) {
+
+        int length = name.length();
+        if (length == 0) {
+            return name;
+        }
+        StringBuffer buf = new StringBuffer(length * 2);
+
+        for (int index = 0; index < length; index++) {
+
+            char ch = name.charAt(index);
+
+            switch (ch) {
+
+            case ' ':
+                if (index == 0 || index == (length - 1)) {
+                    // escape first or last space 
+                    buf.append('\\');
+                }
+                buf.append(' ');
+                break;
+
+            case '"':
+            case '\\':
+                hasQE = true;
+
+            case ',':
+            case '+':
+            case '<':
+            case '>':
+            case ';':
+            case '#': // required by RFC 1779
+            case '=': // required by RFC 1779
+                buf.append('\\');
+
+            default:
+                buf.append(ch);
+            }
+        }
+
+        return buf.toString();
+    }
+
+    public String makeCanonical() {
+
+        int length = rawString.length();
+        if (length == 0) {
+            return rawString;
+        }
+        StringBuffer buf = new StringBuffer(length * 2);
+
+        int index = 0;
+        if (rawString.charAt(0) == '#') {
+            buf.append('\\');
+            buf.append('#');
+            index++;
+        }
+
+        int bufLength;
+        for (; index < length; index++) {
+
+            char ch = rawString.charAt(index);
+
+            switch (ch) {
+
+            case ' ':
+                bufLength = buf.length();
+                if (bufLength == 0 || buf.charAt(bufLength - 1) == ' ') {
+                    break;
+                }
+                buf.append(' ');
+                break;
+
+            case '"':
+            case '\\':
+            case ',':
+            case '+':
+            case '<':
+            case '>':
+            case ';':
+                buf.append('\\');
+
+            default:
+                buf.append(ch);
+            }
+        }
+
+        //remove trailing spaces
+        for (bufLength = buf.length() - 1; bufLength > -1
+                && buf.charAt(bufLength) == ' '; bufLength--) {
+        }
+        buf.setLength(bufLength + 1);
+
+        return buf.toString();
+    }
+}
\ No newline at end of file

Added: incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/Attributes.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/Attributes.java?rev=370554&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/Attributes.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/Attributes.java Thu Jan 19 09:50:26 2006
@@ -0,0 +1,59 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+* @author Stepan M. Mishura
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.x501;
+
+import org.apache.harmony.security.asn1.ASN1OpenType;
+import org.apache.harmony.security.asn1.ASN1Sequence;
+import org.apache.harmony.security.asn1.ASN1SetOf;
+import org.apache.harmony.security.asn1.ASN1Type;
+import org.apache.harmony.security.asn1.InformationObjectSet;
+
+
+/**
+ * X.501 Attributes
+ * 
+ * This is a draft class for Module InformationFramework (X.501).
+ * 
+ * @see http://www.itu.int/ITU-T/asn1/database/itu-t/x/x501/2001/InformationFramework.html 
+ */
+
+public class Attributes {
+
+    
+    /**
+     * The class corresponds to following ASN.1 type:
+     * 
+     * Attribute ::= SEQUENCE {
+     *     type  AttributeType,
+     *     values SET SIZE (0..MAX) OF AttributeValue }
+     * 
+     * AttributeType ::= OBJECT IDENTIFIER
+     * 
+     * AttributeValue ::= ANY DEFINED BY AttributeType
+     * 
+     */
+    public static ASN1Sequence getASN1(InformationObjectSet set) {
+        ASN1OpenType.Id id = new ASN1OpenType.Id();
+        ASN1OpenType any = new ASN1OpenType(id, set);
+
+        return new ASN1Sequence(new ASN1Type[] { id, new ASN1SetOf(any) });
+    }
+}
\ No newline at end of file

Added: incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/DirectoryString.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/DirectoryString.java?rev=370554&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/DirectoryString.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/DirectoryString.java Thu Jan 19 09:50:26 2006
@@ -0,0 +1,71 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+* @author Alexander Y. Kleymenov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.x501;
+
+import org.apache.harmony.security.asn1.ASN1Choice;
+import org.apache.harmony.security.asn1.ASN1StringType;
+import org.apache.harmony.security.asn1.ASN1Type;
+import org.apache.harmony.security.asn1.BerInputStream;
+
+
+/**
+ * The class incapsulates the ASN.1 DER encoding/decoding work 
+ * with the DirectoryString structure
+ * (as specified in RFC 3280 -
+ *  Internet X.509 Public Key Infrastructure.
+ *  Certificate and Certificate Revocation List (CRL) Profile.
+ *  http://www.ietf.org/rfc/rfc3280.txt):
+ *
+ * <pre>
+ *   DirectoryString ::= CHOICE {
+ *        teletexString             TeletexString   (SIZE (1..MAX)),
+ *        printableString           PrintableString (SIZE (1..MAX)),
+ *        universalString           UniversalString (SIZE (1..MAX)),
+ *        utf8String              UTF8String      (SIZE (1..MAX)),
+ *        bmpString               BMPString       (SIZE (1..MAX)) 
+ *   }
+ * </pre>
+ */
+public class DirectoryString {
+    
+    public static final ASN1Choice ASN1 = new ASN1Choice(new ASN1Type[] {
+           ASN1StringType.TELETEXSTRING,
+           ASN1StringType.PRINTABLESTRING,
+           ASN1StringType.UNIVERSALSTRING,
+           ASN1StringType.UTF8STRING,
+           ASN1StringType.BMPSTRING }) {
+
+        public Object getDecodedObject(BerInputStream in) {
+            return /*(String)*/ in.content;
+        }
+
+        public int getIndex(java.lang.Object object) {
+            return 1; // always code as ASN1 printableString
+            //return 4; // always code as ASN1 utf8String
+        }
+
+        public Object getObjectToEncode(Object object) {
+            return /*(String)*/ object;
+        }
+    };
+}
+

Added: incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/Name.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/Name.java?rev=370554&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/Name.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/Name.java Thu Jan 19 09:50:26 2006
@@ -0,0 +1,281 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+* @author Alexander V. Esin
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.x501;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Locale;
+
+import javax.security.auth.x500.X500Principal;
+
+import org.apache.harmony.security.asn1.ASN1Exception;
+import org.apache.harmony.security.asn1.ASN1SequenceOf;
+import org.apache.harmony.security.asn1.ASN1SetOf;
+import org.apache.harmony.security.asn1.BerInputStream;
+import org.apache.harmony.security.asn1.DerInputStream;
+import org.apache.harmony.security.x509.DNParser;
+
+
+/**
+ * X.501 Name
+ */
+public class Name {
+
+    //ASN.1 DER encoding of Name
+    private volatile byte[] encoded;
+
+    // RFC1779 string
+    private String rfc1779String;
+
+    // RFC2253 string
+    private String rfc2253String;
+
+    //CANONICAL string
+    private String canonicalString;
+
+    //Collection of RDNs
+    private List rdn;
+
+    /**
+     * Creates new <code>Name</code> instance from its DER encoding
+     * 
+     * @param encoding - ASN.1 DER encoding
+     * @throws IOException - if encoding is wrong
+     */
+    public Name(byte[] encoding) throws IOException {
+
+        DerInputStream in = new DerInputStream(encoding);
+
+        if (in.getEndOffset() != encoding.length) {
+            throw new IllegalArgumentException("Wrong content length");
+        }
+
+        ASN1.decode(in);
+
+        this.rdn = (List) in.content;
+    }
+
+    /**
+     * Creates new <code>Name</code> instance from its DER encoding obtained
+     * from <code>InputStream</code>
+     * 
+     * @param is
+     *            <code>InputStream</code> containing DER encoding
+     * @throws IOException
+     *             if encoding is wrong
+     */
+    public Name(InputStream is) throws IOException {
+
+        try {
+            this.rdn = (List) ASN1.getValues(is);
+        } catch (ASN1Exception e) {
+            throw new IOException(e.getMessage());
+        }
+    }
+
+    /**
+     * Creates new <code>Name</code> instance
+     * 
+     * @param name - Name as String
+     * @throws IOException - if string is wrong
+     */
+    public Name(String name) throws IOException {
+        rdn = new DNParser(name).parse();
+    }
+
+    // Creates Name instance
+    private Name(List rdn) {
+        this.rdn = rdn;
+    }
+
+    /**
+     * Returns Relative Distinguished Name as <code>String</code> according
+     * the format requested
+     * 
+     * @param format
+     *            Name format requested
+     * @return Relative Distinguished Name as <code>String</code> according
+     *         the format requested
+     */
+    public String getName(String format) {
+
+        //
+        // check X500Principal constants first
+        //
+        if (format == X500Principal.RFC1779) {
+
+            if (rfc1779String == null) {
+                rfc1779String = getName0(format);
+            }
+            return rfc1779String;
+
+        } else if (format == X500Principal.RFC2253) {
+
+            if (rfc2253String == null) {
+                rfc2253String = getName0(format);
+            }
+            return rfc2253String;
+
+        } else if (format == X500Principal.CANONICAL) {
+
+            if (canonicalString == null) {
+                canonicalString = getName0(format);
+            }
+            return canonicalString;
+
+        }
+        //
+        // compare ignore case
+        //
+        else if (X500Principal.RFC1779.equalsIgnoreCase(format)) {
+
+            if (rfc1779String == null) {
+                rfc1779String = getName0(X500Principal.RFC1779);
+            }
+            return rfc1779String;
+
+        } else if (X500Principal.RFC2253.equalsIgnoreCase(format)) {
+
+            if (rfc2253String == null) {
+                rfc2253String = getName0(X500Principal.RFC2253);
+            }
+            return rfc2253String;
+
+        } else if (X500Principal.CANONICAL.equalsIgnoreCase(format)) {
+
+            if (canonicalString == null) {
+                canonicalString = getName0(X500Principal.CANONICAL);
+            }
+            return canonicalString;
+
+        } else {
+            throw new IllegalArgumentException("Illegal format: " + format);
+        }
+    }
+
+    /**
+     * Returns Relative Distinguished Name as <code>String</code> according
+     * the format requested, format is int value
+     * 
+     * @param format
+     *            Name format requested
+     * @return Relative Distinguished Name as <code>String</code> according
+     *         the format requested
+     */
+    private String getName0(String format) {
+        
+        StringBuffer name = new StringBuffer();
+
+        // starting with the last element and moving to the first.
+        for (int i = rdn.size() - 1; i >= 0; i--) {
+            List atavList = (List) rdn.get(i);
+
+            if (X500Principal.CANONICAL == format) {
+                List sortedList = new LinkedList(atavList);
+                Collections.sort(sortedList,
+                        new AttributeTypeAndValueComparator());
+                atavList = sortedList;
+            }
+
+            // Relative Distinguished Name to string
+            Iterator it = atavList.iterator();
+            while (it.hasNext()) {
+                AttributeTypeAndValue _ava = (AttributeTypeAndValue) it.next();
+                _ava.appendName(format, name);
+                if (it.hasNext()) {
+                    // multi-valued RDN
+                    if (X500Principal.RFC1779 == format) {
+                        name.append(" + ");
+                    } else {
+                        name.append('+');
+                    }
+                }
+            }
+
+            if (i != 0) {
+                name.append(',');
+                if (format == X500Principal.RFC1779) {
+                    name.append(' ');
+                }
+            }
+        }
+
+        String sName = name.toString();
+        if (format == X500Principal.CANONICAL) {
+            sName = sName.toLowerCase(Locale.US);
+        }
+        return sName;
+    }
+
+    /**
+     * Gets encoded form of DN
+     * 
+     * @return encoding of DN
+     */
+    public byte[] getEncoded() {
+        getInternalEncoding();
+        byte[] enc = new byte[encoded.length];
+        System.arraycopy(encoded, 0, enc, 0, encoded.length);
+        return enc;
+    }
+
+    // @return encoding, no copying is performed
+    public byte[] getInternalEncoding() {
+        if (encoded == null) {
+            encoded = ASN1.encode(this);
+        }
+        return encoded;
+    }
+
+    /**
+     * According to RFC 3280 (http://www.ietf.org/rfc/rfc3280.txt) 
+     * X.501 Name structure is defined as follows:
+     * 
+     * Name ::= CHOICE {
+     *     RDNSequence }
+     *  
+     * RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
+     *  
+     * RelativeDistinguishedName ::=
+     *     SET OF AttributeTypeAndValue
+     * 
+     */
+
+    public static final ASN1SetOf ASN1_RDN = new ASN1SetOf(
+            AttributeTypeAndValue.ASN1);
+
+    public static final ASN1SequenceOf ASN1 = new ASN1SequenceOf(ASN1_RDN) {
+
+        public Object getDecodedObject(BerInputStream in) {
+            return new Name((List) in.content);
+        }
+
+        public Collection getValues(Object object) {
+            return ((Name) object).rdn; //FIXME what about get method?
+        }
+    };
+}
\ No newline at end of file

Added: incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/svn-commit.tmp
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/svn-commit.tmp?rev=370554&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/svn-commit.tmp (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security2/src/common/javasrc/org/apache/harmony/security/x501/svn-commit.tmp Thu Jan 19 09:50:26 2006
@@ -0,0 +1,11 @@
+update
+--This line, and those below, will be ignored--
+
+A    .
+M    AttributeValue.java
+M    Name.java
+M    AttributeType.java
+A    AttributeTypeAndValue.java
+M    Attributes.java
+M    DirectoryString.java
+A    AttributeTypeAndValueComparator.java



Mime
View raw message