geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r291352 [2/10] - in /geronimo/trunk: applications/console-core/ applications/console-ear/src/plan/ applications/console-standard/src/java/org/apache/geronimo/console/util/ applications/console-standard/src/webapp/WEB-INF/ assemblies/j2ee-se...
Date Sun, 25 Sep 2005 00:32:39 GMT
Added: geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/BERInputStream.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/BERInputStream.java?rev=291352&view=auto
==============================================================================
--- geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/BERInputStream.java (added)
+++ geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/BERInputStream.java Sat Sep 24 17:31:10 2005
@@ -0,0 +1,225 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.util.asn1;
+
+import java.io.ByteArrayOutputStream;
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Vector;
+
+/**
+ * @deprecated use ASN1InputStream
+ */
+public class BERInputStream
+    extends DERInputStream
+{
+    private DERObject END_OF_STREAM = new DERObject() {
+                                        void encode(
+                                            DEROutputStream out)
+                                        throws IOException
+                                        {
+                                            throw new IOException("Eeek!");
+                                        }
+                                        public int hashCode()
+                                        {
+                                            return 0;
+                                        }
+                                        public boolean equals(
+                                            Object o)
+                                        {
+                                            return o == this;
+                                        }
+                                    };
+    public BERInputStream(
+        InputStream is)
+    {
+        super(is);
+    }
+
+    /**
+     * read a string of bytes representing an indefinite length object.
+     */
+    private byte[] readIndefiniteLengthFully()
+        throws IOException
+    {
+        ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
+        int                     b, b1;
+
+        b1 = read();
+
+        while ((b = read()) >= 0)
+        {
+            if (b1 == 0 && b == 0)
+            {
+                break;
+            }
+
+            bOut.write(b1);
+            b1 = b;
+        }
+
+        return bOut.toByteArray();
+    }
+
+    private BERConstructedOctetString buildConstructedOctetString()
+        throws IOException
+    {
+        Vector               octs = new Vector();
+
+        for (;;)
+        {
+            DERObject        o = readObject();
+
+            if (o == END_OF_STREAM)
+            {
+                break;
+            }
+
+            octs.addElement(o);
+        }
+
+        return new BERConstructedOctetString(octs);
+    }
+
+    public DERObject readObject()
+        throws IOException
+    {
+        int tag = read();
+        if (tag == -1)
+        {
+            throw new EOFException();
+        }
+
+        int     length = readLength();
+
+        if (length < 0)    // indefinite length method
+        {
+            switch (tag)
+            {
+            case NULL:
+                return null;
+            case SEQUENCE | CONSTRUCTED:
+                BERConstructedSequence  seq = new BERConstructedSequence();
+
+                for (;;)
+                {
+                    DERObject   obj = readObject();
+
+                    if (obj == END_OF_STREAM)
+                    {
+                        break;
+                    }
+
+                    seq.addObject(obj);
+                }
+                return seq;
+            case OCTET_STRING | CONSTRUCTED:
+                return buildConstructedOctetString();
+            case SET | CONSTRUCTED:
+                ASN1EncodableVector  v = new ASN1EncodableVector();
+
+                for (;;)
+                {
+                    DERObject   obj = readObject();
+
+                    if (obj == END_OF_STREAM)
+                    {
+                        break;
+                    }
+
+                    v.add(obj);
+                }
+                return new BERSet(v);
+            default:
+                //
+                // with tagged object tag number is bottom 5 bits
+                //
+                if ((tag & TAGGED) != 0)
+                {
+                    if ((tag & 0x1f) == 0x1f)
+                    {
+                        throw new IOException("unsupported high tag encountered");
+                    }
+
+                    //
+                    // simple type - implicit... return an octet string
+                    //
+                    if ((tag & CONSTRUCTED) == 0)
+                    {
+                        byte[]  bytes = readIndefiniteLengthFully();
+
+                        return new BERTaggedObject(false, tag & 0x1f, new DEROctetString(bytes));
+                    }
+
+                    //
+                    // either constructed or explicitly tagged
+                    //
+                    DERObject        dObj = readObject();
+
+                    if (dObj == END_OF_STREAM)     // empty tag!
+                    {
+                        return new DERTaggedObject(tag & 0x1f);
+                    }
+
+                    DERObject       next = readObject();
+
+                    //
+                    // explicitly tagged (probably!) - if it isn't we'd have to
+                    // tell from the context
+                    //
+                    if (next == END_OF_STREAM)
+                    {
+                        return new BERTaggedObject(tag & 0x1f, dObj);
+                    }
+
+                    //
+                    // another implicit object, we'll create a sequence...
+                    //
+                    seq = new BERConstructedSequence();
+
+                    seq.addObject(dObj);
+
+                    do
+                    {
+                        seq.addObject(next);
+                        next = readObject();
+                    }
+                    while (next != END_OF_STREAM);
+
+                    return new BERTaggedObject(false, tag & 0x1f, seq);
+                }
+
+                throw new IOException("unknown BER object encountered");
+            }
+        }
+        else
+        {
+            if (tag == 0 && length == 0)    // end of contents marker.
+            {
+                return END_OF_STREAM;
+            }
+
+            byte[]  bytes = new byte[length];
+
+            readFully(bytes);
+
+            return buildObject(tag, bytes);
+        }
+    }
+}

Added: geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/BERNull.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/BERNull.java?rev=291352&view=auto
==============================================================================
--- geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/BERNull.java (added)
+++ geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/BERNull.java Sat Sep 24 17:31:10 2005
@@ -0,0 +1,45 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.util.asn1;
+
+import java.io.IOException;
+
+/**
+ * A BER NULL object.
+ */
+public class BERNull
+    extends DERNull
+{
+    public BERNull()
+    {
+    }
+
+    void encode(
+        DEROutputStream  out)
+        throws IOException
+    {
+        if (out instanceof ASN1OutputStream || out instanceof BEROutputStream)
+        {
+            out.write(NULL);
+        }
+        else
+        {
+            super.encode(out);
+        }
+    }
+}

Added: geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/BEROutputStream.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/BEROutputStream.java?rev=291352&view=auto
==============================================================================
--- geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/BEROutputStream.java (added)
+++ geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/BEROutputStream.java Sat Sep 24 17:31:10 2005
@@ -0,0 +1,53 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.util.asn1;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+public class BEROutputStream
+    extends DEROutputStream
+{
+    public BEROutputStream(
+        OutputStream    os)
+    {
+        super(os);
+    }
+
+    public void writeObject(
+        Object    obj)
+        throws IOException
+    {
+        if (obj == null)
+        {
+            writeNull();
+        }
+        else if (obj instanceof DERObject)
+        {
+            ((DERObject)obj).encode(this);
+        }
+        else if (obj instanceof DEREncodable)
+        {
+            ((DEREncodable)obj).getDERObject().encode(this);
+        }
+        else
+        {
+            throw new IOException("object not BEREncodable");
+        }
+    }
+}

Added: geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/BERSequence.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/BERSequence.java?rev=291352&view=auto
==============================================================================
--- geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/BERSequence.java (added)
+++ geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/BERSequence.java Sat Sep 24 17:31:10 2005
@@ -0,0 +1,76 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.util.asn1;
+
+import java.io.IOException;
+import java.util.Enumeration;
+
+public class BERSequence
+    extends DERSequence
+{
+    /**
+     * create an empty sequence
+     */
+    public BERSequence()
+    {
+    }
+
+    /**
+     * create a sequence containing one object
+     */
+    public BERSequence(
+        DEREncodable    obj)
+    {
+        super(obj);
+    }
+
+    /**
+     * create a sequence containing a vector of objects.
+     */
+    public BERSequence(
+        DEREncodableVector   v)
+    {
+        super(v);
+    }
+
+    /*
+     */
+    void encode(
+        DEROutputStream out)
+        throws IOException
+    {
+        if (out instanceof ASN1OutputStream || out instanceof BEROutputStream)
+        {
+            out.write(SEQUENCE | CONSTRUCTED);
+            out.write(0x80);
+
+            Enumeration e = getObjects();
+            while (e.hasMoreElements())
+            {
+                out.writeObject(e.nextElement());
+            }
+
+            out.write(0x00);
+            out.write(0x00);
+        }
+        else
+        {
+            super.encode(out);
+        }
+    }
+}

Added: geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/BERSet.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/BERSet.java?rev=291352&view=auto
==============================================================================
--- geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/BERSet.java (added)
+++ geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/BERSet.java Sat Sep 24 17:31:10 2005
@@ -0,0 +1,86 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.util.asn1;
+
+import java.io.IOException;
+import java.util.Enumeration;
+
+public class BERSet
+    extends DERSet
+{
+    /**
+     * create an empty sequence
+     */
+    public BERSet()
+    {
+    }
+
+    /**
+     * create a set containing one object
+     */
+    public BERSet(
+        DEREncodable    obj)
+    {
+        super(obj);
+    }
+
+    /**
+     * @param v - a vector of objects making up the set.
+     */
+    public BERSet(
+        DEREncodableVector   v)
+    {
+        super(v, true);
+    }
+
+    /**
+     * @param v - a vector of objects making up the set.
+     */
+    BERSet(
+        DEREncodableVector   v,
+        boolean              needsSorting)
+    {
+        super(v, needsSorting);
+    }
+
+    /*
+     */
+    void encode(
+        DEROutputStream out)
+        throws IOException
+    {
+        if (out instanceof ASN1OutputStream || out instanceof BEROutputStream)
+        {
+            out.write(SET | CONSTRUCTED);
+            out.write(0x80);
+
+            Enumeration e = getObjects();
+            while (e.hasMoreElements())
+            {
+                out.writeObject(e.nextElement());
+            }
+
+            out.write(0x00);
+            out.write(0x00);
+        }
+        else
+        {
+            super.encode(out);
+        }
+    }
+}

Added: geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/BERTaggedObject.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/BERTaggedObject.java?rev=291352&view=auto
==============================================================================
--- geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/BERTaggedObject.java (added)
+++ geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/BERTaggedObject.java Sat Sep 24 17:31:10 2005
@@ -0,0 +1,136 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.util.asn1;
+
+import java.io.IOException;
+import java.util.Enumeration;
+
+/**
+ * BER TaggedObject - in ASN.1 nottation this is any object proceeded by
+ * a [n] where n is some number - these are assume to follow the construction
+ * rules (as with sequences).
+ */
+public class BERTaggedObject
+    extends DERTaggedObject
+{
+    /**
+     * @param tagNo the tag number for this object.
+     * @param obj the tagged object.
+     */
+    public BERTaggedObject(
+        int             tagNo,
+        DEREncodable    obj)
+    {
+        super(tagNo, obj);
+    }
+
+    /**
+     * @param explicit true if an explicitly tagged object.
+     * @param tagNo the tag number for this object.
+     * @param obj the tagged object.
+     */
+    public BERTaggedObject(
+        boolean         explicit,
+        int             tagNo,
+        DEREncodable    obj)
+    {
+        super(explicit, tagNo, obj);
+    }
+
+    /**
+     * create an implicitly tagged object that contains a zero
+     * length sequence.
+     */
+    public BERTaggedObject(
+        int             tagNo)
+    {
+        super(false, tagNo, new BERSequence());
+    }
+
+    void encode(
+        DEROutputStream  out)
+        throws IOException
+    {
+        if (out instanceof ASN1OutputStream || out instanceof BEROutputStream)
+        {
+            out.write(CONSTRUCTED | TAGGED | tagNo);
+            out.write(0x80);
+
+            if (!empty)
+            {
+                if (!explicit)
+                {
+                    if (obj instanceof ASN1OctetString)
+                    {
+                        Enumeration  e;
+
+                        if (obj instanceof BERConstructedOctetString)
+                        {
+                            e = ((BERConstructedOctetString)obj).getObjects();
+                        }
+                        else
+                        {
+                            ASN1OctetString             octs = (ASN1OctetString)obj;
+                            BERConstructedOctetString   berO = new BERConstructedOctetString(octs.getOctets());
+
+                            e = berO.getObjects();
+                        }
+
+                        while (e.hasMoreElements())
+                        {
+                            out.writeObject(e.nextElement());
+                        }
+                    }
+                    else if (obj instanceof ASN1Sequence)
+                    {
+                        Enumeration  e = ((ASN1Sequence)obj).getObjects();
+
+                        while (e.hasMoreElements())
+                        {
+                            out.writeObject(e.nextElement());
+                        }
+                    }
+                    else if (obj instanceof ASN1Set)
+                    {
+                        Enumeration  e = ((ASN1Set)obj).getObjects();
+
+                        while (e.hasMoreElements())
+                        {
+                            out.writeObject(e.nextElement());
+                        }
+                    }
+                    else
+                    {
+                        throw new RuntimeException("not implemented: " + obj.getClass().getName());
+                    }
+                }
+                else
+                {
+                    out.writeObject(obj);
+                }
+            }
+
+            out.write(0x00);
+            out.write(0x00);
+        }
+        else
+        {
+            super.encode(out);
+        }
+    }
+}

Added: geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERApplicationSpecific.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERApplicationSpecific.java?rev=291352&view=auto
==============================================================================
--- geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERApplicationSpecific.java (added)
+++ geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERApplicationSpecific.java Sat Sep 24 17:31:10 2005
@@ -0,0 +1,128 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.util.asn1;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+/**
+ * Base class for an application specific object
+ */
+public class DERApplicationSpecific
+    extends DERObject
+{
+    private int       tag;
+    private byte[]    octets;
+
+    public DERApplicationSpecific(
+        int        tag,
+        byte[]    octets)
+    {
+        this.tag = tag;
+        this.octets = octets;
+    }
+
+    public DERApplicationSpecific(
+        int                  tag,
+        DEREncodable         object)
+        throws IOException
+    {
+        this.tag = tag | DERTags.CONSTRUCTED;
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        DEROutputStream dos = new DEROutputStream(baos);
+
+        dos.writeObject(object);
+
+        this.octets = baos.toByteArray();
+    }
+
+    public boolean isConstructed()
+    {
+        return (tag & DERTags.CONSTRUCTED) != 0;
+    }
+
+    public byte[] getContents()
+    {
+        return octets;
+    }
+
+    public int getApplicationTag()
+    {
+        return tag & 0x1F;
+    }
+
+    public DERObject getObject()
+        throws IOException
+    {
+        return new ASN1InputStream(new ByteArrayInputStream(getContents())).readObject();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.geronimo.util.asn1.DERObject#encode(org.apache.geronimo.util.asn1.DEROutputStream)
+     */
+    void encode(DEROutputStream out) throws IOException
+    {
+        out.writeEncoded(DERTags.APPLICATION | tag, octets);
+    }
+
+    public boolean equals(
+            Object o)
+    {
+        if ((o == null) || !(o instanceof DERApplicationSpecific))
+        {
+            return false;
+        }
+
+        DERApplicationSpecific other = (DERApplicationSpecific)o;
+
+        if (tag != other.tag)
+        {
+            return false;
+        }
+
+        if (octets.length != other.octets.length)
+        {
+            return false;
+        }
+
+        for (int i = 0; i < octets.length; i++)
+        {
+            if (octets[i] != other.octets[i])
+            {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    public int hashCode()
+    {
+        byte[]  b = this.getContents();
+        int     value = 0;
+
+        for (int i = 0; i != b.length; i++)
+        {
+            value ^= (b[i] & 0xff) << (i % 4);
+        }
+
+        return value ^ this.getApplicationTag();
+    }
+}

Added: geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERBMPString.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERBMPString.java?rev=291352&view=auto
==============================================================================
--- geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERBMPString.java (added)
+++ geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERBMPString.java Sat Sep 24 17:31:10 2005
@@ -0,0 +1,138 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.util.asn1;
+
+import java.io.IOException;
+
+/**
+ * DER BMPString object.
+ */
+public class DERBMPString
+    extends DERObject
+    implements DERString
+{
+    String  string;
+
+    /**
+     * return a BMP String from the given object.
+     *
+     * @param obj the object we want converted.
+     * @exception IllegalArgumentException if the object cannot be converted.
+     */
+    public static DERBMPString getInstance(
+        Object  obj)
+    {
+        if (obj == null || obj instanceof DERBMPString)
+        {
+            return (DERBMPString)obj;
+        }
+
+        if (obj instanceof ASN1OctetString)
+        {
+            return new DERBMPString(((ASN1OctetString)obj).getOctets());
+        }
+
+        if (obj instanceof ASN1TaggedObject)
+        {
+            return getInstance(((ASN1TaggedObject)obj).getObject());
+        }
+
+        throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
+    }
+
+    /**
+     * return a BMP String from a tagged object.
+     *
+     * @param obj the tagged object holding the object we want
+     * @param explicit true if the object is meant to be explicitly
+     *              tagged false otherwise.
+     * @exception IllegalArgumentException if the tagged object cannot
+     *              be converted.
+     */
+    public static DERBMPString getInstance(
+        ASN1TaggedObject obj,
+        boolean          explicit)
+    {
+        return getInstance(obj.getObject());
+    }
+
+
+    /**
+     * basic constructor - byte encoded string.
+     */
+    public DERBMPString(
+        byte[]   string)
+    {
+        char[]  cs = new char[string.length / 2];
+
+        for (int i = 0; i != cs.length; i++)
+        {
+            cs[i] = (char)((string[2 * i] << 8) | (string[2 * i + 1] & 0xff));
+        }
+
+        this.string = new String(cs);
+    }
+
+    /**
+     * basic constructor
+     */
+    public DERBMPString(
+        String   string)
+    {
+        this.string = string;
+    }
+
+    public String getString()
+    {
+        return string;
+    }
+
+    public int hashCode()
+    {
+        return this.getString().hashCode();
+    }
+
+    public boolean equals(
+        Object  o)
+    {
+        if (!(o instanceof DERBMPString))
+        {
+            return false;
+        }
+
+        DERBMPString  s = (DERBMPString)o;
+
+        return this.getString().equals(s.getString());
+    }
+
+    void encode(
+        DEROutputStream  out)
+        throws IOException
+    {
+        char[]  c = string.toCharArray();
+        byte[]  b = new byte[c.length * 2];
+
+        for (int i = 0; i != c.length; i++)
+        {
+            b[2 * i] = (byte)(c[i] >> 8);
+            b[2 * i + 1] = (byte)c[i];
+        }
+
+        out.writeEncoded(BMP_STRING, b);
+    }
+}

Added: geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERBitString.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERBitString.java?rev=291352&view=auto
==============================================================================
--- geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERBitString.java (added)
+++ geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERBitString.java Sat Sep 24 17:31:10 2005
@@ -0,0 +1,301 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.util.asn1;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+public class DERBitString
+    extends DERObject
+    implements DERString
+{
+    private static final char[]  table = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
+
+    protected byte[]      data;
+    protected int         padBits;
+
+    /**
+     * return the correct number of pad bits for a bit string defined in
+     * a 32 bit constant
+     */
+    static protected int getPadBits(
+        int bitString)
+    {
+        int val = 0;
+        for (int i = 3; i >= 0; i--)
+        {
+            //
+            // this may look a little odd, but if it isn't done like this pre jdk1.2
+            // JVM's break!
+            //
+            if (i != 0)
+            {
+                if ((bitString >> (i * 8)) != 0)
+                {
+                    val = (bitString >> (i * 8)) & 0xFF;
+                    break;
+                }
+            }
+            else
+            {
+                if (bitString != 0)
+                {
+                    val = bitString & 0xFF;
+                    break;
+                }
+            }
+        }
+
+        if (val == 0)
+        {
+            return 7;
+        }
+
+
+        int bits = 1;
+
+        while (((val <<= 1) & 0xFF) != 0)
+        {
+            bits++;
+        }
+
+        return 8 - bits;
+    }
+
+    /**
+     * return the correct number of bytes for a bit string defined in
+     * a 32 bit constant
+     */
+    static protected byte[] getBytes(int bitString)
+    {
+        int bytes = 4;
+        for (int i = 3; i >= 1; i--)
+        {
+            if ((bitString & (0xFF << (i * 8))) != 0)
+            {
+                break;
+            }
+            bytes--;
+        }
+
+        byte[] result = new byte[bytes];
+        for (int i = 0; i < bytes; i++)
+        {
+            result[i] = (byte) ((bitString >> (i * 8)) & 0xFF);
+        }
+
+        return result;
+    }
+
+    /**
+     * return a Bit String from the passed in object
+     *
+     * @exception IllegalArgumentException if the object cannot be converted.
+     */
+    public static DERBitString getInstance(
+        Object  obj)
+    {
+        if (obj == null || obj instanceof DERBitString)
+        {
+            return (DERBitString)obj;
+        }
+
+        if (obj instanceof ASN1OctetString)
+        {
+            byte[]  bytes = ((ASN1OctetString)obj).getOctets();
+            int     padBits = bytes[0];
+            byte[]  data = new byte[bytes.length - 1];
+
+            System.arraycopy(bytes, 1, data, 0, bytes.length - 1);
+
+            return new DERBitString(data, padBits);
+        }
+
+        if (obj instanceof ASN1TaggedObject)
+        {
+            return getInstance(((ASN1TaggedObject)obj).getObject());
+        }
+
+        throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
+    }
+
+    /**
+     * return a Bit String from a tagged object.
+     *
+     * @param obj the tagged object holding the object we want
+     * @param explicit true if the object is meant to be explicitly
+     *              tagged false otherwise.
+     * @exception IllegalArgumentException if the tagged object cannot
+     *               be converted.
+     */
+    public static DERBitString getInstance(
+        ASN1TaggedObject obj,
+        boolean          explicit)
+    {
+        return getInstance(obj.getObject());
+    }
+
+    protected DERBitString(
+        byte    data,
+        int     padBits)
+    {
+        this.data = new byte[1];
+        this.data[0] = data;
+        this.padBits = padBits;
+    }
+
+    /**
+     * @param data the octets making up the bit string.
+     * @param padBits the number of extra bits at the end of the string.
+     */
+    public DERBitString(
+        byte[]  data,
+        int     padBits)
+    {
+        this.data = data;
+        this.padBits = padBits;
+    }
+
+    public DERBitString(
+        byte[]  data)
+    {
+        this(data, 0);
+    }
+
+    public DERBitString(
+        DEREncodable  obj)
+    {
+        try
+        {
+            ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
+            DEROutputStream         dOut = new DEROutputStream(bOut);
+
+            dOut.writeObject(obj);
+            dOut.close();
+
+            this.data = bOut.toByteArray();
+            this.padBits = 0;
+        }
+        catch (IOException e)
+        {
+            throw new IllegalArgumentException("Error processing object : " + e.toString());
+        }
+    }
+
+    public byte[] getBytes()
+    {
+        return data;
+    }
+
+    public int getPadBits()
+    {
+        return padBits;
+    }
+
+
+    /**
+     * @return the value of the bit string as an int (truncating if necessary)
+     */
+    public int intValue()
+    {
+        int value = 0;
+
+        for (int i = 0; i != data.length && i != 4; i++)
+        {
+            value |= (data[i] & 0xff) << (8 * i);
+        }
+
+        return value;
+    }
+
+    void encode(
+        DEROutputStream  out)
+        throws IOException
+    {
+        byte[]  bytes = new byte[getBytes().length + 1];
+
+        bytes[0] = (byte)getPadBits();
+        System.arraycopy(getBytes(), 0, bytes, 1, bytes.length - 1);
+
+        out.writeEncoded(BIT_STRING, bytes);
+    }
+
+    public int hashCode()
+    {
+        int     value = 0;
+
+        for (int i = 0; i != data.length; i++)
+        {
+            value ^= (data[i] & 0xff) << (i % 4);
+        }
+
+        return value;
+    }
+
+    public boolean equals(
+        Object  o)
+    {
+        if (o == null || !(o instanceof DERBitString))
+        {
+            return false;
+        }
+
+        DERBitString  other = (DERBitString)o;
+
+        if (data.length != other.data.length)
+        {
+            return false;
+        }
+
+        for (int i = 0; i != data.length; i++)
+        {
+            if (data[i] != other.data[i])
+            {
+                return false;
+            }
+        }
+
+        return (padBits == other.padBits);
+    }
+
+    public String getString()
+    {
+        StringBuffer          buf = new StringBuffer("#");
+        ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+        ASN1OutputStream      aOut = new ASN1OutputStream(bOut);
+
+        try
+        {
+            aOut.writeObject(this);
+        }
+        catch (IOException e)
+        {
+           throw new RuntimeException("internal error encoding BitString");
+        }
+
+        byte[]    string = bOut.toByteArray();
+
+        for (int i = 0; i != string.length; i++)
+        {
+            buf.append(table[(string[i] >>> 4) % 0xf]);
+            buf.append(table[string[i] & 0xf]);
+        }
+
+        return buf.toString();
+    }
+}

Added: geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERBoolean.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERBoolean.java?rev=291352&view=auto
==============================================================================
--- geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERBoolean.java (added)
+++ geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERBoolean.java Sat Sep 24 17:31:10 2005
@@ -0,0 +1,125 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.util.asn1;
+
+import java.io.IOException;
+
+public class DERBoolean
+    extends DERObject
+{
+    byte         value;
+
+    public static final DERBoolean FALSE = new DERBoolean(false);
+    public static final DERBoolean TRUE  = new DERBoolean(true);
+
+    /**
+     * return a boolean from the passed in object.
+     *
+     * @exception IllegalArgumentException if the object cannot be converted.
+     */
+    public static DERBoolean getInstance(
+        Object  obj)
+    {
+        if (obj == null || obj instanceof DERBoolean)
+        {
+            return (DERBoolean)obj;
+        }
+
+        if (obj instanceof ASN1OctetString)
+        {
+            return new DERBoolean(((ASN1OctetString)obj).getOctets());
+        }
+
+        if (obj instanceof ASN1TaggedObject)
+        {
+            return getInstance(((ASN1TaggedObject)obj).getObject());
+        }
+
+        throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
+    }
+
+    /**
+     * return a DERBoolean from the passed in boolean.
+     */
+    public static DERBoolean getInstance(
+        boolean  value)
+    {
+        return (value ? TRUE : FALSE);
+    }
+
+    /**
+     * return a Boolean from a tagged object.
+     *
+     * @param obj the tagged object holding the object we want
+     * @param explicit true if the object is meant to be explicitly
+     *              tagged false otherwise.
+     * @exception IllegalArgumentException if the tagged object cannot
+     *               be converted.
+     */
+    public static DERBoolean getInstance(
+        ASN1TaggedObject obj,
+        boolean          explicit)
+    {
+        return getInstance(obj.getObject());
+    }
+
+    public DERBoolean(
+        byte[]       value)
+    {
+        this.value = value[0];
+    }
+
+    public DERBoolean(
+        boolean     value)
+    {
+        this.value = (value) ? (byte)0xff : (byte)0;
+    }
+
+    public boolean isTrue()
+    {
+        return (value != 0);
+    }
+
+    void encode(
+        DEROutputStream out)
+        throws IOException
+    {
+        byte[]  bytes = new byte[1];
+
+        bytes[0] = value;
+
+        out.writeEncoded(BOOLEAN, bytes);
+    }
+
+    public boolean equals(
+        Object  o)
+    {
+        if ((o == null) || !(o instanceof DERBoolean))
+        {
+            return false;
+        }
+
+        return (value == ((DERBoolean)o).value);
+    }
+
+    public int hashCode()
+    {
+        return value;
+    }
+
+}

Added: geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERConstructedSequence.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERConstructedSequence.java?rev=291352&view=auto
==============================================================================
--- geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERConstructedSequence.java (added)
+++ geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERConstructedSequence.java Sat Sep 24 17:31:10 2005
@@ -0,0 +1,70 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.util.asn1;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Enumeration;
+
+/**
+ * @deprecated use DERSequence.
+ */
+public class DERConstructedSequence
+    extends ASN1Sequence
+{
+    public void addObject(
+        DEREncodable obj)
+    {
+        super.addObject(obj);
+    }
+
+    public int getSize()
+    {
+        return size();
+    }
+
+    /*
+     * A note on the implementation:
+     * <p>
+     * As DER requires the constructed, definite-length model to
+     * be used for structured types, this varies slightly from the
+     * ASN.1 descriptions given. Rather than just outputing SEQUENCE,
+     * we also have to specify CONSTRUCTED, and the objects length.
+     */
+    void encode(
+        DEROutputStream out)
+        throws IOException
+    {
+        ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
+        DEROutputStream         dOut = new DEROutputStream(bOut);
+        Enumeration             e = this.getObjects();
+
+        while (e.hasMoreElements())
+        {
+            Object    obj = e.nextElement();
+
+            dOut.writeObject(obj);
+        }
+
+        dOut.close();
+
+        byte[]  bytes = bOut.toByteArray();
+
+        out.writeEncoded(SEQUENCE | CONSTRUCTED, bytes);
+    }
+}

Added: geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERConstructedSet.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERConstructedSet.java?rev=291352&view=auto
==============================================================================
--- geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERConstructedSet.java (added)
+++ geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERConstructedSet.java Sat Sep 24 17:31:10 2005
@@ -0,0 +1,96 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.util.asn1;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Enumeration;
+
+/**
+ *
+ * @deprecated use DERSet
+ */
+public class DERConstructedSet
+    extends ASN1Set
+{
+    public DERConstructedSet()
+    {
+    }
+
+    /**
+     * @param obj - a single object that makes up the set.
+     */
+    public DERConstructedSet(
+        DEREncodable   obj)
+    {
+        this.addObject(obj);
+    }
+
+    /**
+     * @param v - a vector of objects making up the set.
+     */
+    public DERConstructedSet(
+        DEREncodableVector   v)
+    {
+        for (int i = 0; i != v.size(); i++)
+        {
+            this.addObject(v.get(i));
+        }
+    }
+
+    public void addObject(
+        DEREncodable    obj)
+    {
+        super.addObject(obj);
+    }
+
+    public int getSize()
+    {
+        return size();
+    }
+
+    /*
+     * A note on the implementation:
+     * <p>
+     * As DER requires the constructed, definite-length model to
+     * be used for structured types, this varies slightly from the
+     * ASN.1 descriptions given. Rather than just outputing SET,
+     * we also have to specify CONSTRUCTED, and the objects length.
+     */
+    void encode(
+        DEROutputStream out)
+        throws IOException
+    {
+        ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
+        DEROutputStream         dOut = new DEROutputStream(bOut);
+        Enumeration             e = this.getObjects();
+
+        while (e.hasMoreElements())
+        {
+            Object    obj = e.nextElement();
+
+            dOut.writeObject(obj);
+        }
+
+        dOut.close();
+
+        byte[]  bytes = bOut.toByteArray();
+
+        out.writeEncoded(SET | CONSTRUCTED, bytes);
+    }
+}

Added: geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DEREncodable.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DEREncodable.java?rev=291352&view=auto
==============================================================================
--- geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DEREncodable.java (added)
+++ geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DEREncodable.java Sat Sep 24 17:31:10 2005
@@ -0,0 +1,23 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.util.asn1;
+
+public interface DEREncodable
+{
+    public DERObject getDERObject();
+}

Added: geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DEREncodableVector.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DEREncodableVector.java?rev=291352&view=auto
==============================================================================
--- geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DEREncodableVector.java (added)
+++ geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DEREncodableVector.java Sat Sep 24 17:31:10 2005
@@ -0,0 +1,47 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.util.asn1;
+
+import java.util.Vector;
+
+/**
+ * a general class for building up a vector of DER encodable objects -
+ * this will eventually be superceded by ASN1EncodableVector so you should
+ * use that class in preference.
+ */
+public class DEREncodableVector
+{
+    private Vector  v = new Vector();
+
+    public void add(
+        DEREncodable   obj)
+    {
+        v.addElement(obj);
+    }
+
+    public DEREncodable get(
+        int i)
+    {
+        return (DEREncodable)v.elementAt(i);
+    }
+
+    public int size()
+    {
+        return v.size();
+    }
+}

Added: geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DEREnumerated.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DEREnumerated.java?rev=291352&view=auto
==============================================================================
--- geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DEREnumerated.java (added)
+++ geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DEREnumerated.java Sat Sep 24 17:31:10 2005
@@ -0,0 +1,130 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.util.asn1;
+
+import java.io.IOException;
+import java.math.BigInteger;
+
+public class DEREnumerated
+    extends DERObject
+{
+    byte[]      bytes;
+
+    /**
+     * return an integer from the passed in object
+     *
+     * @exception IllegalArgumentException if the object cannot be converted.
+     */
+    public static DEREnumerated getInstance(
+        Object  obj)
+    {
+        if (obj == null || obj instanceof DEREnumerated)
+        {
+            return (DEREnumerated)obj;
+        }
+
+        if (obj instanceof ASN1OctetString)
+        {
+            return new DEREnumerated(((ASN1OctetString)obj).getOctets());
+        }
+
+        if (obj instanceof ASN1TaggedObject)
+        {
+            return getInstance(((ASN1TaggedObject)obj).getObject());
+        }
+
+        throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
+    }
+
+    /**
+     * return an Enumerated from a tagged object.
+     *
+     * @param obj the tagged object holding the object we want
+     * @param explicit true if the object is meant to be explicitly
+     *              tagged false otherwise.
+     * @exception IllegalArgumentException if the tagged object cannot
+     *               be converted.
+     */
+    public static DEREnumerated getInstance(
+        ASN1TaggedObject obj,
+        boolean          explicit)
+    {
+        return getInstance(obj.getObject());
+    }
+
+    public DEREnumerated(
+        int         value)
+    {
+        bytes = BigInteger.valueOf(value).toByteArray();
+    }
+
+    public DEREnumerated(
+        BigInteger   value)
+    {
+        bytes = value.toByteArray();
+    }
+
+    public DEREnumerated(
+        byte[]   bytes)
+    {
+        this.bytes = bytes;
+    }
+
+    public BigInteger getValue()
+    {
+        return new BigInteger(bytes);
+    }
+
+    void encode(
+        DEROutputStream out)
+        throws IOException
+    {
+        out.writeEncoded(ENUMERATED, bytes);
+    }
+
+    public boolean equals(
+        Object  o)
+    {
+        if (o == null || !(o instanceof DEREnumerated))
+        {
+            return false;
+        }
+
+        DEREnumerated other = (DEREnumerated)o;
+
+        if (bytes.length != other.bytes.length)
+        {
+            return false;
+        }
+
+        for (int i = 0; i != bytes.length; i++)
+        {
+            if (bytes[i] != other.bytes[i])
+            {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    public int hashCode()
+    {
+        return this.getValue().hashCode();
+    }
+}

Added: geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERGeneralString.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERGeneralString.java?rev=291352&view=auto
==============================================================================
--- geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERGeneralString.java (added)
+++ geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERGeneralString.java Sat Sep 24 17:31:10 2005
@@ -0,0 +1,104 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.util.asn1;
+
+import java.io.IOException;
+
+public class DERGeneralString
+    extends DERObject implements DERString
+{
+    private String string;
+
+    public static DERGeneralString getInstance(
+        Object obj)
+    {
+        if (obj == null || obj instanceof DERGeneralString)
+        {
+            return (DERGeneralString) obj;
+        }
+        if (obj instanceof ASN1OctetString)
+        {
+            return new DERGeneralString(((ASN1OctetString) obj).getOctets());
+        }
+        if (obj instanceof ASN1TaggedObject)
+        {
+            return getInstance(((ASN1TaggedObject) obj).getObject());
+        }
+        throw new IllegalArgumentException("illegal object in getInstance: "
+                + obj.getClass().getName());
+    }
+
+    public static DERGeneralString getInstance(
+        ASN1TaggedObject obj,
+        boolean explicit)
+    {
+        return getInstance(obj.getObject());
+    }
+
+    public DERGeneralString(byte[] string)
+    {
+        char[] cs = new char[string.length];
+        for (int i = 0; i != cs.length; i++)
+        {
+            cs[i] = (char)(string[i] & 0xff);
+        }
+        this.string = new String(cs);
+    }
+
+    public DERGeneralString(String string)
+    {
+        this.string = string;
+    }
+
+    public String getString()
+    {
+        return string;
+    }
+
+    public byte[] getOctets()
+    {
+        char[] cs = string.toCharArray();
+        byte[] bs = new byte[cs.length];
+        for (int i = 0; i != cs.length; i++)
+        {
+            bs[i] = (byte) cs[i];
+        }
+        return bs;
+    }
+
+    void encode(DEROutputStream out)
+        throws IOException
+    {
+        out.writeEncoded(GENERAL_STRING, this.getOctets());
+    }
+
+    public int hashCode()
+    {
+        return this.getString().hashCode();
+    }
+
+    public boolean equals(Object o)
+    {
+        if (!(o instanceof DERGeneralString))
+        {
+            return false;
+        }
+        DERGeneralString s = (DERGeneralString) o;
+        return this.getString().equals(s.getString());
+    }
+}

Added: geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERGeneralizedTime.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERGeneralizedTime.java?rev=291352&view=auto
==============================================================================
--- geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERGeneralizedTime.java (added)
+++ geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERGeneralizedTime.java Sat Sep 24 17:31:10 2005
@@ -0,0 +1,219 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.util.asn1;
+
+import java.io.IOException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.SimpleTimeZone;
+
+/**
+ * Generalized time object.
+ */
+public class DERGeneralizedTime
+    extends DERObject
+{
+    String      time;
+
+    /**
+     * return a generalized time from the passed in object
+     *
+     * @exception IllegalArgumentException if the object cannot be converted.
+     */
+    public static DERGeneralizedTime getInstance(
+        Object  obj)
+    {
+        if (obj == null || obj instanceof DERGeneralizedTime)
+        {
+            return (DERGeneralizedTime)obj;
+        }
+
+        if (obj instanceof ASN1OctetString)
+        {
+            return new DERGeneralizedTime(((ASN1OctetString)obj).getOctets());
+        }
+
+        throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
+    }
+
+    /**
+     * return a Generalized Time object from a tagged object.
+     *
+     * @param obj the tagged object holding the object we want
+     * @param explicit true if the object is meant to be explicitly
+     *              tagged false otherwise.
+     * @exception IllegalArgumentException if the tagged object cannot
+     *               be converted.
+     */
+    public static DERGeneralizedTime getInstance(
+        ASN1TaggedObject obj,
+        boolean          explicit)
+    {
+        return getInstance(obj.getObject());
+    }
+
+    /**
+     * The correct format for this is YYYYMMDDHHMMSSZ, or without the Z
+     * for local time, or Z+-HHMM on the end, for difference between local
+     * time and UTC time.
+     * <p>
+     *
+     * @param time the time string.
+     */
+    public DERGeneralizedTime(
+        String  time)
+    {
+        this.time = time;
+    }
+
+    /**
+     * base constructer from a java.util.date object
+     */
+    public DERGeneralizedTime(
+        Date time)
+    {
+        SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmss'Z'");
+
+        dateF.setTimeZone(new SimpleTimeZone(0,"Z"));
+
+        this.time = dateF.format(time);
+    }
+
+    DERGeneralizedTime(
+        byte[]  bytes)
+    {
+        //
+        // explicitly convert to characters
+        //
+        char[]  dateC = new char[bytes.length];
+
+        for (int i = 0; i != dateC.length; i++)
+        {
+            dateC[i] = (char)(bytes[i] & 0xff);
+        }
+
+        this.time = new String(dateC);
+    }
+
+    /**
+     * return the time - always in the form of
+     *  YYYYMMDDhhmmssGMT(+hh:mm|-hh:mm).
+     * <p>
+     * Normally in a certificate we would expect "Z" rather than "GMT",
+     * however adding the "GMT" means we can just use:
+     * <pre>
+     *     dateF = new SimpleDateFormat("yyyyMMddHHmmssz");
+     * </pre>
+     * To read in the time and get a date which is compatible with our local
+     * time zone.
+     */
+    public String getTime()
+    {
+        //
+        // standardise the format.
+        //
+        if (time.charAt(time.length() - 1) == 'Z')
+        {
+            return time.substring(0, time.length() - 1) + "GMT+00:00";
+        }
+        else
+        {
+            int signPos = time.length() - 5;
+            char sign = time.charAt(signPos);
+            if (sign == '-' || sign == '+')
+            {
+                return time.substring(0, signPos)
+                    + "GMT"
+                    + time.substring(signPos, signPos + 3)
+                    + ":"
+                    + time.substring(signPos + 3);
+            }
+            else
+            {
+                signPos = time.length() - 3;
+                sign = time.charAt(signPos);
+                if (sign == '-' || sign == '+')
+                {
+                    return time.substring(0, signPos)
+                        + "GMT"
+                        + time.substring(signPos)
+                        + ":00";
+                }
+            }
+        }
+
+        return time;
+    }
+
+    public Date getDate()
+        throws ParseException
+    {
+        SimpleDateFormat dateF;
+
+        if (time.indexOf('.') == 14)
+        {
+            dateF = new SimpleDateFormat("yyyyMMddHHmmss.SSS'Z'");
+        }
+        else
+        {
+            dateF = new SimpleDateFormat("yyyyMMddHHmmss'Z'");
+        }
+
+        dateF.setTimeZone(new SimpleTimeZone(0, "Z"));
+
+        return dateF.parse(time);
+    }
+
+    private byte[] getOctets()
+    {
+        char[]  cs = time.toCharArray();
+        byte[]  bs = new byte[cs.length];
+
+        for (int i = 0; i != cs.length; i++)
+        {
+            bs[i] = (byte)cs[i];
+        }
+
+        return bs;
+    }
+
+
+    void encode(
+        DEROutputStream  out)
+        throws IOException
+    {
+        out.writeEncoded(GENERALIZED_TIME, this.getOctets());
+    }
+
+    public boolean equals(
+        Object  o)
+    {
+        if ((o == null) || !(o instanceof DERGeneralizedTime))
+        {
+            return false;
+        }
+
+        return time.equals(((DERGeneralizedTime)o).time);
+    }
+
+    public int hashCode()
+    {
+        return time.hashCode();
+    }
+}

Added: geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERIA5String.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERIA5String.java?rev=291352&view=auto
==============================================================================
--- geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERIA5String.java (added)
+++ geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERIA5String.java Sat Sep 24 17:31:10 2005
@@ -0,0 +1,140 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.util.asn1;
+
+import java.io.IOException;
+
+/**
+ * DER IA5String object - this is an ascii string.
+ */
+public class DERIA5String
+    extends DERObject
+    implements DERString
+{
+    String  string;
+
+    /**
+     * return a IA5 string from the passed in object
+     *
+     * @exception IllegalArgumentException if the object cannot be converted.
+     */
+    public static DERIA5String getInstance(
+        Object  obj)
+    {
+        if (obj == null || obj instanceof DERIA5String)
+        {
+            return (DERIA5String)obj;
+        }
+
+        if (obj instanceof ASN1OctetString)
+        {
+            return new DERIA5String(((ASN1OctetString)obj).getOctets());
+        }
+
+        if (obj instanceof ASN1TaggedObject)
+        {
+            return getInstance(((ASN1TaggedObject)obj).getObject());
+        }
+
+        throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
+    }
+
+    /**
+     * return an IA5 String from a tagged object.
+     *
+     * @param obj the tagged object holding the object we want
+     * @param explicit true if the object is meant to be explicitly
+     *              tagged false otherwise.
+     * @exception IllegalArgumentException if the tagged object cannot
+     *               be converted.
+     */
+    public static DERIA5String getInstance(
+        ASN1TaggedObject obj,
+        boolean          explicit)
+    {
+        return getInstance(obj.getObject());
+    }
+
+    /**
+     * basic constructor - with bytes.
+     */
+    public DERIA5String(
+        byte[]   string)
+    {
+        char[]  cs = new char[string.length];
+
+        for (int i = 0; i != cs.length; i++)
+        {
+            cs[i] = (char)(string[i] & 0xff);
+        }
+
+        this.string = new String(cs);
+    }
+
+    /**
+     * basic constructor - with string.
+     */
+    public DERIA5String(
+        String   string)
+    {
+        this.string = string;
+    }
+
+    public String getString()
+    {
+        return string;
+    }
+
+    public byte[] getOctets()
+    {
+        char[]  cs = string.toCharArray();
+        byte[]  bs = new byte[cs.length];
+
+        for (int i = 0; i != cs.length; i++)
+        {
+            bs[i] = (byte)cs[i];
+        }
+
+        return bs;
+    }
+
+    void encode(
+        DEROutputStream  out)
+        throws IOException
+    {
+        out.writeEncoded(IA5_STRING, this.getOctets());
+    }
+
+    public int hashCode()
+    {
+        return this.getString().hashCode();
+    }
+
+    public boolean equals(
+        Object  o)
+    {
+        if (!(o instanceof DERIA5String))
+        {
+            return false;
+        }
+
+        DERIA5String  s = (DERIA5String)o;
+
+        return this.getString().equals(s.getString());
+    }
+}

Added: geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERInputStream.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERInputStream.java?rev=291352&view=auto
==============================================================================
--- geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERInputStream.java (added)
+++ geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERInputStream.java Sat Sep 24 17:31:10 2005
@@ -0,0 +1,289 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.util.asn1;
+
+import java.io.ByteArrayInputStream;
+import java.io.EOFException;
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Don't use this class. It will eventually disappear, use ASN1InputStream.
+ * <br>
+ * This class is scheduled for removal.
+ * @deprecated use ASN1InputStream
+ */
+public class DERInputStream
+    extends FilterInputStream implements DERTags
+{
+    /**
+     * @deprecated use ASN1InputStream
+     */
+    public DERInputStream(
+        InputStream is)
+    {
+        super(is);
+    }
+
+    protected int readLength()
+        throws IOException
+    {
+        int length = read();
+        if (length < 0)
+        {
+            throw new IOException("EOF found when length expected");
+        }
+
+        if (length == 0x80)
+        {
+            return -1;      // indefinite-length encoding
+        }
+
+        if (length > 127)
+        {
+            int size = length & 0x7f;
+
+            if (size > 4)
+            {
+                throw new IOException("DER length more than 4 bytes");
+            }
+
+            length = 0;
+            for (int i = 0; i < size; i++)
+            {
+                int next = read();
+
+                if (next < 0)
+                {
+                    throw new IOException("EOF found reading length");
+                }
+
+                length = (length << 8) + next;
+            }
+
+            if (length < 0)
+            {
+                throw new IOException("corrupted steam - negative length found");
+            }
+        }
+
+        return length;
+    }
+
+    protected void readFully(
+        byte[]  bytes)
+        throws IOException
+    {
+        int     left = bytes.length;
+
+        if (left == 0)
+        {
+            return;
+        }
+
+        while (left > 0)
+        {
+            int    l = read(bytes, bytes.length - left, left);
+
+            if (l < 0)
+            {
+                throw new EOFException("unexpected end of stream");
+            }
+
+            left -= l;
+        }
+    }
+
+    /**
+     * build an object given its tag and a byte stream to construct it
+     * from.
+     */
+    protected DERObject buildObject(
+        int       tag,
+        byte[]    bytes)
+        throws IOException
+    {
+        switch (tag)
+        {
+        case NULL:
+            return null;
+        case SEQUENCE | CONSTRUCTED:
+            ByteArrayInputStream    bIn = new ByteArrayInputStream(bytes);
+            BERInputStream          dIn = new BERInputStream(bIn);
+            DERConstructedSequence  seq = new DERConstructedSequence();
+
+            try
+            {
+                for (;;)
+                {
+                    DERObject   obj = dIn.readObject();
+
+                    seq.addObject(obj);
+                }
+            }
+            catch (EOFException ex)
+            {
+                return seq;
+            }
+        case SET | CONSTRUCTED:
+            bIn = new ByteArrayInputStream(bytes);
+            dIn = new BERInputStream(bIn);
+
+            ASN1EncodableVector    v = new ASN1EncodableVector();
+
+            try
+            {
+                for (;;)
+                {
+                    DERObject   obj = dIn.readObject();
+
+                    v.add(obj);
+                }
+            }
+            catch (EOFException ex)
+            {
+                return new DERConstructedSet(v);
+            }
+        case BOOLEAN:
+            return new DERBoolean(bytes);
+        case INTEGER:
+            return new DERInteger(bytes);
+        case ENUMERATED:
+            return new DEREnumerated(bytes);
+        case OBJECT_IDENTIFIER:
+            return new DERObjectIdentifier(bytes);
+        case BIT_STRING:
+            int     padBits = bytes[0];
+            byte[]  data = new byte[bytes.length - 1];
+
+            System.arraycopy(bytes, 1, data, 0, bytes.length - 1);
+
+            return new DERBitString(data, padBits);
+        case UTF8_STRING:
+            return new DERUTF8String(bytes);
+        case PRINTABLE_STRING:
+            return new DERPrintableString(bytes);
+        case IA5_STRING:
+            return new DERIA5String(bytes);
+        case T61_STRING:
+            return new DERT61String(bytes);
+        case VISIBLE_STRING:
+            return new DERVisibleString(bytes);
+        case UNIVERSAL_STRING:
+            return new DERUniversalString(bytes);
+        case GENERAL_STRING:
+            return new DERGeneralString(bytes);
+        case BMP_STRING:
+            return new DERBMPString(bytes);
+        case OCTET_STRING:
+            return new DEROctetString(bytes);
+        case UTC_TIME:
+            return new DERUTCTime(bytes);
+        case GENERALIZED_TIME:
+            return new DERGeneralizedTime(bytes);
+        default:
+            //
+            // with tagged object tag number is bottom 5 bits
+            //
+            if ((tag & TAGGED) != 0)
+            {
+                if ((tag & 0x1f) == 0x1f)
+                {
+                    throw new IOException("unsupported high tag encountered");
+                }
+
+                if (bytes.length == 0)        // empty tag!
+                {
+                    if ((tag & CONSTRUCTED) == 0)
+                    {
+                        return new DERTaggedObject(false, tag & 0x1f, new DERNull());
+                    }
+                    else
+                    {
+                        return new DERTaggedObject(false, tag & 0x1f, new DERConstructedSequence());
+                    }
+                }
+
+                //
+                // simple type - implicit... return an octet string
+                //
+                if ((tag & CONSTRUCTED) == 0)
+                {
+                    return new DERTaggedObject(false, tag & 0x1f, new DEROctetString(bytes));
+                }
+
+                bIn = new ByteArrayInputStream(bytes);
+                dIn = new BERInputStream(bIn);
+
+                DEREncodable dObj = dIn.readObject();
+
+                //
+                // explicitly tagged (probably!) - if it isn't we'd have to
+                // tell from the context
+                //
+                if (dIn.available() == 0)
+                {
+                    return new DERTaggedObject(tag & 0x1f, dObj);
+                }
+
+                //
+                // another implicit object, we'll create a sequence...
+                //
+                seq = new DERConstructedSequence();
+
+                seq.addObject(dObj);
+
+                try
+                {
+                    for (;;)
+                    {
+                        dObj = dIn.readObject();
+
+                        seq.addObject(dObj);
+                    }
+                }
+                catch (EOFException ex)
+                {
+                    // ignore --
+                }
+
+                return new DERTaggedObject(false, tag & 0x1f, seq);
+            }
+
+            return new DERUnknownTag(tag, bytes);
+        }
+    }
+
+    public DERObject readObject()
+        throws IOException
+    {
+        int tag = read();
+        if (tag == -1)
+        {
+            throw new EOFException();
+        }
+
+        int     length = readLength();
+        byte[]  bytes = new byte[length];
+
+        readFully(bytes);
+
+        return buildObject(tag, bytes);
+    }
+}

Added: geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERInteger.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERInteger.java?rev=291352&view=auto
==============================================================================
--- geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERInteger.java (added)
+++ geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERInteger.java Sat Sep 24 17:31:10 2005
@@ -0,0 +1,146 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.util.asn1;
+
+import java.io.IOException;
+import java.math.BigInteger;
+
+public class DERInteger
+    extends DERObject
+{
+    byte[]      bytes;
+
+    /**
+     * return an integer from the passed in object
+     *
+     * @exception IllegalArgumentException if the object cannot be converted.
+     */
+    public static DERInteger getInstance(
+        Object  obj)
+    {
+        if (obj == null || obj instanceof DERInteger)
+        {
+            return (DERInteger)obj;
+        }
+
+        if (obj instanceof ASN1OctetString)
+        {
+            return new DERInteger(((ASN1OctetString)obj).getOctets());
+        }
+
+        if (obj instanceof ASN1TaggedObject)
+        {
+            return getInstance(((ASN1TaggedObject)obj).getObject());
+        }
+
+        throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
+    }
+
+    /**
+     * return an Integer from a tagged object.
+     *
+     * @param obj the tagged object holding the object we want
+     * @param explicit true if the object is meant to be explicitly
+     *              tagged false otherwise.
+     * @exception IllegalArgumentException if the tagged object cannot
+     *               be converted.
+     */
+    public static DERInteger getInstance(
+        ASN1TaggedObject obj,
+        boolean          explicit)
+    {
+        return getInstance(obj.getObject());
+    }
+
+    public DERInteger(
+        int         value)
+    {
+        bytes = BigInteger.valueOf(value).toByteArray();
+    }
+
+    public DERInteger(
+        BigInteger   value)
+    {
+        bytes = value.toByteArray();
+    }
+
+    public DERInteger(
+        byte[]   bytes)
+    {
+        this.bytes = bytes;
+    }
+
+    public BigInteger getValue()
+    {
+        return new BigInteger(bytes);
+    }
+
+    /**
+     * in some cases positive values get crammed into a space,
+     * that's not quite big enough...
+     */
+    public BigInteger getPositiveValue()
+    {
+        return new BigInteger(1, bytes);
+    }
+
+    void encode(
+        DEROutputStream out)
+        throws IOException
+    {
+        out.writeEncoded(INTEGER, bytes);
+    }
+
+    public int hashCode()
+    {
+         int     value = 0;
+
+         for (int i = 0; i != bytes.length; i++)
+         {
+             value ^= (bytes[i] & 0xff) << (i % 4);
+         }
+
+         return value;
+    }
+
+    public boolean equals(
+        Object  o)
+    {
+        if (o == null || !(o instanceof DERInteger))
+        {
+            return false;
+        }
+
+        DERInteger other = (DERInteger)o;
+
+        if (bytes.length != other.bytes.length)
+        {
+            return false;
+        }
+
+        for (int i = 0; i != bytes.length; i++)
+        {
+            if (bytes[i] != other.bytes[i])
+            {
+                return false;
+            }
+        }
+
+        return true;
+    }
+}

Added: geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERNull.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERNull.java?rev=291352&view=auto
==============================================================================
--- geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERNull.java (added)
+++ geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERNull.java Sat Sep 24 17:31:10 2005
@@ -0,0 +1,56 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.util.asn1;
+
+import java.io.IOException;
+
+/**
+ * A NULL object.
+ */
+public class DERNull
+    extends ASN1Null
+{
+    byte[]  zeroBytes = new byte[0];
+
+    public DERNull()
+    {
+    }
+
+    void encode(
+        DEROutputStream  out)
+        throws IOException
+    {
+        out.writeEncoded(NULL, zeroBytes);
+    }
+
+    public boolean equals(
+        Object o)
+    {
+        if ((o == null) || !(o instanceof DERNull))
+        {
+            return false;
+        }
+
+        return true;
+    }
+
+    public int hashCode()
+    {
+        return 0;
+    }
+}

Added: geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERNumericString.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERNumericString.java?rev=291352&view=auto
==============================================================================
--- geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERNumericString.java (added)
+++ geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERNumericString.java Sat Sep 24 17:31:10 2005
@@ -0,0 +1,140 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.util.asn1;
+
+import java.io.IOException;
+
+/**
+ * DER NumericString object - this is an ascii string of characters {0,1,2,3,4,5,6,7,8,9, }.
+ */
+public class DERNumericString
+    extends DERObject
+    implements DERString
+{
+    String  string;
+
+    /**
+     * return a Numeric string from the passed in object
+     *
+     * @exception IllegalArgumentException if the object cannot be converted.
+     */
+    public static DERNumericString getInstance(
+        Object  obj)
+    {
+        if (obj == null || obj instanceof DERNumericString)
+        {
+            return (DERNumericString)obj;
+        }
+
+        if (obj instanceof ASN1OctetString)
+        {
+            return new DERNumericString(((ASN1OctetString)obj).getOctets());
+        }
+
+        if (obj instanceof ASN1TaggedObject)
+        {
+            return getInstance(((ASN1TaggedObject)obj).getObject());
+        }
+
+        throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
+    }
+
+    /**
+     * return an Numeric String from a tagged object.
+     *
+     * @param obj the tagged object holding the object we want
+     * @param explicit true if the object is meant to be explicitly
+     *              tagged false otherwise.
+     * @exception IllegalArgumentException if the tagged object cannot
+     *               be converted.
+     */
+    public static DERNumericString getInstance(
+        ASN1TaggedObject obj,
+        boolean          explicit)
+    {
+        return getInstance(obj.getObject());
+    }
+
+    /**
+     * basic constructor - with bytes.
+     */
+    public DERNumericString(
+        byte[]   string)
+    {
+        char[]  cs = new char[string.length];
+
+        for (int i = 0; i != cs.length; i++)
+        {
+            cs[i] = (char)(string[i] & 0xff);
+        }
+
+        this.string = new String(cs);
+    }
+
+    /**
+     * basic constructor - with string.
+     */
+    public DERNumericString(
+        String   string)
+    {
+        this.string = string;
+    }
+
+    public String getString()
+    {
+        return string;
+    }
+
+    public byte[] getOctets()
+    {
+        char[]  cs = string.toCharArray();
+        byte[]  bs = new byte[cs.length];
+
+        for (int i = 0; i != cs.length; i++)
+        {
+            bs[i] = (byte)cs[i];
+        }
+
+        return bs;
+    }
+
+    void encode(
+        DEROutputStream  out)
+        throws IOException
+    {
+        out.writeEncoded(NUMERIC_STRING, this.getOctets());
+    }
+
+    public int hashCode()
+    {
+        return this.getString().hashCode();
+    }
+
+    public boolean equals(
+        Object  o)
+    {
+        if (!(o instanceof DERNumericString))
+        {
+            return false;
+        }
+
+        DERNumericString  s = (DERNumericString)o;
+
+        return this.getString().equals(s.getString());
+    }
+}

Added: geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERObject.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERObject.java?rev=291352&view=auto
==============================================================================
--- geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERObject.java (added)
+++ geronimo/trunk/modules/util/src/java/org/apache/geronimo/util/asn1/DERObject.java Sat Sep 24 17:31:10 2005
@@ -0,0 +1,37 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.util.asn1;
+
+import java.io.IOException;
+
+public abstract class DERObject
+    extends ASN1Encodable
+    implements DERTags
+{
+    public DERObject toASN1Object()
+    {
+        return this;
+    }
+
+    public abstract int hashCode();
+
+    public abstract boolean equals(Object o);
+
+    abstract void encode(DEROutputStream out)
+        throws IOException;
+}



Mime
View raw message