001package org.apache.commons.ssl.org.bouncycastle.asn1.cmp;
002
003import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1EncodableVector;
004import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Object;
005import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Primitive;
006import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Sequence;
007import org.apache.commons.ssl.org.bouncycastle.asn1.DERSequence;
008
009public class CAKeyUpdAnnContent
010    extends ASN1Object
011{
012    private CMPCertificate oldWithNew;
013    private CMPCertificate newWithOld;
014    private CMPCertificate newWithNew;
015
016    private CAKeyUpdAnnContent(ASN1Sequence seq)
017    {
018        oldWithNew = CMPCertificate.getInstance(seq.getObjectAt(0));
019        newWithOld = CMPCertificate.getInstance(seq.getObjectAt(1));
020        newWithNew = CMPCertificate.getInstance(seq.getObjectAt(2));
021    }
022
023    public static CAKeyUpdAnnContent getInstance(Object o)
024    {
025        if (o instanceof CAKeyUpdAnnContent)
026        {
027            return (CAKeyUpdAnnContent)o;
028        }
029
030        if (o != null)
031        {
032            return new CAKeyUpdAnnContent(ASN1Sequence.getInstance(o));
033        }
034
035        return null;
036    }
037
038    public CAKeyUpdAnnContent(CMPCertificate oldWithNew, CMPCertificate newWithOld, CMPCertificate newWithNew)
039    {
040        this.oldWithNew = oldWithNew;
041        this.newWithOld = newWithOld;
042        this.newWithNew = newWithNew;
043    }
044
045    public CMPCertificate getOldWithNew()
046    {
047        return oldWithNew;
048    }
049
050    public CMPCertificate getNewWithOld()
051    {
052        return newWithOld;
053    }
054
055    public CMPCertificate getNewWithNew()
056    {
057        return newWithNew;
058    }
059
060    /**
061     * <pre>
062     * CAKeyUpdAnnContent ::= SEQUENCE {
063     *                             oldWithNew   CMPCertificate, -- old pub signed with new priv
064     *                             newWithOld   CMPCertificate, -- new pub signed with old priv
065     *                             newWithNew   CMPCertificate  -- new pub signed with new priv
066     *  }
067     * </pre>
068     * @return a basic ASN.1 object representation.
069     */
070    public ASN1Primitive toASN1Primitive()
071    {
072        ASN1EncodableVector v = new ASN1EncodableVector();
073
074        v.add(oldWithNew);
075        v.add(newWithOld);
076        v.add(newWithNew);
077
078        return new DERSequence(v);
079    }
080}