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