// 
// Decompiled by Procyon v0.6.0
// 

package org.bouncycastle.asn1.cmp;

import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.DERTaggedObject;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Util;
import org.bouncycastle.asn1.ASN1TaggedObject;
import org.bouncycastle.asn1.x509.GeneralNames;
import org.bouncycastle.asn1.x509.DistributionPointName;
import org.bouncycastle.asn1.ASN1Choice;
import org.bouncycastle.asn1.ASN1Object;

public class CRLSource extends ASN1Object implements ASN1Choice
{
    private final DistributionPointName dpn;
    private final GeneralNames issuer;
    
    private CRLSource(final ASN1TaggedObject asn1TaggedObject) {
        if (asn1TaggedObject.hasContextTag(0)) {
            this.dpn = DistributionPointName.getInstance(asn1TaggedObject, true);
            this.issuer = null;
        }
        else {
            if (!asn1TaggedObject.hasContextTag(1)) {
                throw new IllegalArgumentException("unknown tag " + ASN1Util.getTagText(asn1TaggedObject));
            }
            this.dpn = null;
            this.issuer = GeneralNames.getInstance(asn1TaggedObject, true);
        }
    }
    
    public CRLSource(final DistributionPointName dpn, final GeneralNames issuer) {
        if (dpn == null == (issuer == null)) {
            throw new IllegalArgumentException("either dpn or issuer must be set");
        }
        this.dpn = dpn;
        this.issuer = issuer;
    }
    
    public static CRLSource getInstance(final Object o) {
        if (o instanceof CRLSource) {
            return (CRLSource)o;
        }
        if (o != null) {
            return new CRLSource(ASN1TaggedObject.getInstance(o));
        }
        return null;
    }
    
    public DistributionPointName getDpn() {
        return this.dpn;
    }
    
    public GeneralNames getIssuer() {
        return this.issuer;
    }
    
    @Override
    public ASN1Primitive toASN1Primitive() {
        if (this.dpn != null) {
            return new DERTaggedObject(true, 0, this.dpn);
        }
        return new DERTaggedObject(true, 1, this.issuer);
    }
}
