Home | History | Annotate | Download | only in x509
      1 package org.bouncycastle.asn1.x509;
      2 
      3 import org.bouncycastle.asn1.ASN1Choice;
      4 import org.bouncycastle.asn1.ASN1Encodable;
      5 import org.bouncycastle.asn1.ASN1Sequence;
      6 import org.bouncycastle.asn1.ASN1TaggedObject;
      7 import org.bouncycastle.asn1.DERObject;
      8 import org.bouncycastle.asn1.DERTaggedObject;
      9 
     10 public class AttCertIssuer
     11     extends ASN1Encodable
     12     implements ASN1Choice
     13 {
     14     ASN1Encodable   obj;
     15     DERObject       choiceObj;
     16 
     17     public static AttCertIssuer getInstance(
     18         Object  obj)
     19     {
     20         if (obj instanceof AttCertIssuer)
     21         {
     22             return (AttCertIssuer)obj;
     23         }
     24         else if (obj instanceof V2Form)
     25         {
     26             return new AttCertIssuer(V2Form.getInstance(obj));
     27         }
     28         else if (obj instanceof GeneralNames)
     29         {
     30             return new AttCertIssuer((GeneralNames)obj);
     31         }
     32         else if (obj instanceof ASN1TaggedObject)
     33         {
     34             return new AttCertIssuer(V2Form.getInstance((ASN1TaggedObject)obj, false));
     35         }
     36         else if (obj instanceof ASN1Sequence)
     37         {
     38             return new AttCertIssuer(GeneralNames.getInstance(obj));
     39         }
     40 
     41         throw new IllegalArgumentException("unknown object in factory: " + obj.getClass().getName());
     42     }
     43 
     44     public static AttCertIssuer getInstance(
     45         ASN1TaggedObject obj,
     46         boolean          explicit)
     47     {
     48         return getInstance(obj.getObject()); // must be explicitly tagged
     49     }
     50 
     51     /**
     52      * Don't use this one if you are trying to be RFC 3281 compliant.
     53      * Use it for v1 attribute certificates only.
     54      *
     55      * @param names our GeneralNames structure
     56      */
     57     public AttCertIssuer(
     58         GeneralNames  names)
     59     {
     60         obj = names;
     61         choiceObj = obj.getDERObject();
     62     }
     63 
     64     public AttCertIssuer(
     65         V2Form  v2Form)
     66     {
     67         obj = v2Form;
     68         choiceObj = new DERTaggedObject(false, 0, obj);
     69     }
     70 
     71     public ASN1Encodable getIssuer()
     72     {
     73         return obj;
     74     }
     75 
     76     /**
     77      * Produce an object suitable for an ASN1OutputStream.
     78      * <pre>
     79      *  AttCertIssuer ::= CHOICE {
     80      *       v1Form   GeneralNames,  -- MUST NOT be used in this
     81      *                               -- profile
     82      *       v2Form   [0] V2Form     -- v2 only
     83      *  }
     84      * </pre>
     85      */
     86     public DERObject toASN1Object()
     87     {
     88         return choiceObj;
     89     }
     90 }
     91