001package org.apache.commons.ssl.org.bouncycastle.asn1.x509;
002
003import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Choice;
004import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Encodable;
005import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Object;
006import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Primitive;
007import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Sequence;
008import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1TaggedObject;
009import org.apache.commons.ssl.org.bouncycastle.asn1.DERTaggedObject;
010
011public class AttCertIssuer
012    extends ASN1Object
013    implements ASN1Choice
014{
015    ASN1Encodable   obj;
016    ASN1Primitive choiceObj;
017    
018    public static AttCertIssuer getInstance(
019        Object  obj)
020    {
021        if (obj == null || obj instanceof AttCertIssuer)
022        {
023            return (AttCertIssuer)obj;
024        }
025        else if (obj instanceof V2Form)
026        {
027            return new AttCertIssuer(V2Form.getInstance(obj));
028        }
029        else if (obj instanceof GeneralNames)
030        {
031            return new AttCertIssuer((GeneralNames)obj);
032        }
033        else if (obj instanceof ASN1TaggedObject)
034        {
035            return new AttCertIssuer(V2Form.getInstance((ASN1TaggedObject)obj, false));
036        }
037        else if (obj instanceof ASN1Sequence)
038        {
039            return new AttCertIssuer(GeneralNames.getInstance(obj));
040        }
041
042        throw new IllegalArgumentException("unknown object in factory: " + obj.getClass().getName());
043    }
044    
045    public static AttCertIssuer getInstance(
046        ASN1TaggedObject obj,
047        boolean          explicit)
048    {
049        return getInstance(obj.getObject()); // must be explicitly tagged
050    }
051
052    /**
053     * Don't use this one if you are trying to be RFC 3281 compliant.
054     * Use it for v1 attribute certificates only.
055     * 
056     * @param names our GeneralNames structure
057     */
058    public AttCertIssuer(
059        GeneralNames  names)
060    {
061        obj = names;
062        choiceObj = obj.toASN1Primitive();
063    }
064    
065    public AttCertIssuer(
066        V2Form  v2Form)
067    {
068        obj = v2Form;
069        choiceObj = new DERTaggedObject(false, 0, obj);
070    }
071
072    public ASN1Encodable getIssuer()
073    {
074        return obj;
075    }
076    
077    /**
078     * Produce an object suitable for an ASN1OutputStream.
079     * <pre>
080     *  AttCertIssuer ::= CHOICE {
081     *       v1Form   GeneralNames,  -- MUST NOT be used in this
082     *                               -- profile
083     *       v2Form   [0] V2Form     -- v2 only
084     *  }
085     * </pre>
086     */
087    public ASN1Primitive toASN1Primitive()
088    {
089        return choiceObj;
090    }
091}