2003/02/12 06:21:04
[org.ibex.core.git] / src / org / bouncycastle / asn1 / x509 / AlgorithmIdentifier.java
index cad4c82..945f948 100644 (file)
@@ -9,8 +9,41 @@ public class AlgorithmIdentifier
     implements DEREncodable
 {
     private DERObjectIdentifier objectId;
-    private DERObject           parameters;
+    private DEREncodable        parameters;
     private boolean             parametersDefined = false;
+       
+    public static AlgorithmIdentifier getInstance(
+        ASN1TaggedObject obj,
+        boolean          explicit)
+    {
+        return getInstance(ASN1Sequence.getInstance(obj, explicit));
+    }
+    
+    public static AlgorithmIdentifier getInstance(
+        Object  obj)
+    {
+        if (obj instanceof AlgorithmIdentifier)
+        {
+            return (AlgorithmIdentifier)obj;
+        }
+        
+        if (obj instanceof DERObjectIdentifier)
+        {
+            return new AlgorithmIdentifier((DERObjectIdentifier)obj);
+        }
+
+        if (obj instanceof String)
+        {
+            return new AlgorithmIdentifier((String)obj);
+        }
+
+        if (obj instanceof ASN1Sequence)
+        {
+            return new AlgorithmIdentifier((ASN1Sequence)obj);
+        }
+
+        throw new IllegalArgumentException("unknown object in factory");
+    }
 
     public AlgorithmIdentifier(
         DERObjectIdentifier     objectId)
@@ -19,24 +52,29 @@ public class AlgorithmIdentifier
     }
 
     public AlgorithmIdentifier(
+        String     objectId)
+    {
+        this.objectId = new DERObjectIdentifier(objectId);
+    }
+
+    public AlgorithmIdentifier(
         DERObjectIdentifier     objectId,
-        DERObject               parameters)
+        DEREncodable            parameters)
     {
         parametersDefined = true;
-
         this.objectId = objectId;
         this.parameters = parameters;
     }
 
     public AlgorithmIdentifier(
-        DERConstructedSequence  obj)
+        ASN1Sequence   seq)
     {
-        objectId = (DERObjectIdentifier)obj.getObjectAt(0);
+        objectId = (DERObjectIdentifier)seq.getObjectAt(0);
 
-        if (obj.getSize() == 2)
+        if (seq.size() == 2)
         {
             parametersDefined = true;
-            parameters = (DERObject)obj.getObjectAt(1);
+            parameters = seq.getObjectAt(1);
         }
         else
         {
@@ -49,7 +87,7 @@ public class AlgorithmIdentifier
         return objectId;
     }
 
-    public DERObject getParameters()
+    public DEREncodable getParameters()
     {
         return parameters;
     }