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

package org.bouncycastle.asn1.cmp;

import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.DERTaggedObject;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Encodable;
import java.util.Iterator;
import org.bouncycastle.asn1.ASN1TaggedObject;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.ASN1Object;

public class RootCaKeyUpdateContent extends ASN1Object
{
    private final CMPCertificate newWithNew;
    private final CMPCertificate newWithOld;
    private final CMPCertificate oldWithNew;
    
    public RootCaKeyUpdateContent(final CMPCertificate newWithNew, final CMPCertificate newWithOld, final CMPCertificate oldWithNew) {
        if (newWithNew == null) {
            throw new NullPointerException("'newWithNew' cannot be null");
        }
        this.newWithNew = newWithNew;
        this.newWithOld = newWithOld;
        this.oldWithNew = oldWithNew;
    }
    
    private RootCaKeyUpdateContent(final ASN1Sequence asn1Sequence) {
        if (asn1Sequence.size() < 1 || asn1Sequence.size() > 3) {
            throw new IllegalArgumentException("expected sequence of 1 to 3 elements only");
        }
        CMPCertificate instance = null;
        CMPCertificate instance2 = null;
        final Iterator<ASN1Encodable> iterator = asn1Sequence.iterator();
        final CMPCertificate instance3 = CMPCertificate.getInstance(iterator.next());
        while (iterator.hasNext()) {
            final ASN1TaggedObject instance4 = ASN1TaggedObject.getInstance(iterator.next());
            if (instance4.hasContextTag(0)) {
                instance = CMPCertificate.getInstance(instance4, true);
            }
            else {
                if (!instance4.hasContextTag(1)) {
                    continue;
                }
                instance2 = CMPCertificate.getInstance(instance4, true);
            }
        }
        this.newWithNew = instance3;
        this.newWithOld = instance;
        this.oldWithNew = instance2;
    }
    
    public static RootCaKeyUpdateContent getInstance(final Object o) {
        if (o instanceof RootCaKeyUpdateContent) {
            return (RootCaKeyUpdateContent)o;
        }
        if (o != null) {
            return new RootCaKeyUpdateContent(ASN1Sequence.getInstance(o));
        }
        return null;
    }
    
    public CMPCertificate getNewWithNew() {
        return this.newWithNew;
    }
    
    public CMPCertificate getNewWithOld() {
        return this.newWithOld;
    }
    
    public CMPCertificate getOldWithNew() {
        return this.oldWithNew;
    }
    
    @Override
    public ASN1Primitive toASN1Primitive() {
        final ASN1EncodableVector asn1EncodableVector = new ASN1EncodableVector(3);
        asn1EncodableVector.add(this.newWithNew);
        if (this.newWithOld != null) {
            asn1EncodableVector.add(new DERTaggedObject(true, 0, this.newWithOld));
        }
        if (this.oldWithNew != null) {
            asn1EncodableVector.add(new DERTaggedObject(true, 1, this.oldWithNew));
        }
        return new DERSequence(asn1EncodableVector);
    }
}
