2003/02/12 06:21:04
[org.ibex.core.git] / src / org / bouncycastle / asn1 / x509 / AuthorityKeyIdentifier.java
index 9285c96..d15309d 100644 (file)
@@ -22,16 +22,38 @@ import org.bouncycastle.asn1.*;
  *
  */
 public class AuthorityKeyIdentifier
-    implements DEREncodable
+    implements DEREncodable, DERTags
 {
-    DEROctetString keyidentifier=null;
+    ASN1OctetString keyidentifier=null;
     GeneralNames certissuer=null;
     DERInteger certserno=null;
 
+    public static AuthorityKeyIdentifier getInstance(
+        ASN1TaggedObject obj,
+        boolean          explicit)
+    {
+        return getInstance(ASN1Sequence.getInstance(obj, explicit));
+    }
+
+    public static AuthorityKeyIdentifier getInstance(
+        Object  obj)
+    {
+        if (obj instanceof AuthorityKeyIdentifier)
+        {
+            return (AuthorityKeyIdentifier)obj;
+        }
+        else if (obj instanceof ASN1Sequence)
+        {
+            return new AuthorityKeyIdentifier((ASN1Sequence)obj);
+        }
+
+        throw new IllegalArgumentException("unknown object in factory");
+    }
+       
     public AuthorityKeyIdentifier(
-        DERConstructedSequence   seq)
+        ASN1Sequence   seq)
     {
-        Enumeration e = seq.getObjects();
+        Enumeration     e = seq.getObjects();
 
         while (e.hasMoreElements())
         {
@@ -40,33 +62,13 @@ public class AuthorityKeyIdentifier
             switch (o.getTagNo())
             {
             case 0:
-                this.keyidentifier= (DEROctetString)o.getObject();
+                this.keyidentifier = ASN1OctetString.getInstance(o, false);
                 break;
-
             case 1:
-                if (o.getObject() instanceof DERConstructedSequence)
-                {
-                    this.certissuer = new GeneralNames((DERConstructedSequence)o.getObject());
-                }
-                else   
-                {
-                    // as it's implicitly tagged we can loose the"sequence"
-                    // if there is only one object.
-                    //
-                    DERConstructedSequence s = new DERConstructedSequence();
-
-                    s.addObject(o.getObject());
-
-                    this.certissuer = new GeneralNames(s);
-                }
+                this.certissuer = GeneralNames.getInstance(o, false);
                 break;
             case 2:
-                //
-                // implicit tagging again...
-                //
-                DEROctetString          oct = (DEROctetString)o.getObject();
-
-                this.certserno = new DERInteger(new BigInteger(oct.getOctets()));
+                this.certserno = DERInteger.getInstance(o, false);
                 break;
             default:
                 throw new IllegalArgumentException("illegal tag");
@@ -93,11 +95,10 @@ public class AuthorityKeyIdentifier
         Digest  digest = new SHA1Digest();
         byte[]  resBuf = new byte[digest.getDigestSize()];
 
-        DERBitString derpk = new DERBitString(spki.getPublicKey());
-        byte[] bytes = derpk.getBytes();
+        byte[] bytes = spki.getPublicKeyData().getBytes();
         digest.update(bytes, 0, bytes.length);
         digest.doFinal(resBuf, 0);
-        this.keyidentifier=new DEROctetString(resBuf);
+        this.keyidentifier = new DEROctetString(resBuf);
     }
 
     /**
@@ -112,8 +113,7 @@ public class AuthorityKeyIdentifier
         Digest  digest = new SHA1Digest();
         byte[]  resBuf = new byte[digest.getDigestSize()];
 
-        DERBitString derpk = new DERBitString(spki.getPublicKey());
-        byte[] bytes = derpk.getBytes();
+        byte[] bytes = spki.getPublicKeyData().getBytes();
         digest.update(bytes, 0, bytes.length);
         digest.doFinal(resBuf, 0);