14eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Rootpackage org.bouncycastle.asn1.ocsp;
24eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root
34eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Rootimport org.bouncycastle.asn1.ASN1EncodableVector;
44eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Rootimport org.bouncycastle.asn1.ASN1Object;
54eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Rootimport org.bouncycastle.asn1.ASN1Primitive;
64eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Rootimport org.bouncycastle.asn1.ASN1Sequence;
74eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Rootimport org.bouncycastle.asn1.ASN1TaggedObject;
84eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Rootimport org.bouncycastle.asn1.DERSequence;
94eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Rootimport org.bouncycastle.asn1.DERTaggedObject;
104eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root
114eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Rootpublic class OCSPResponse
124eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root    extends ASN1Object
134eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root{
144eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root    OCSPResponseStatus    responseStatus;
154eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root    ResponseBytes        responseBytes;
164eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root
174eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root    public OCSPResponse(
184eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root        OCSPResponseStatus  responseStatus,
194eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root        ResponseBytes       responseBytes)
204eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root    {
214eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root        this.responseStatus = responseStatus;
224eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root        this.responseBytes = responseBytes;
234eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root    }
244eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root
254eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root    private OCSPResponse(
264eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root        ASN1Sequence    seq)
274eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root    {
284eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root        responseStatus = OCSPResponseStatus.getInstance(seq.getObjectAt(0));
294eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root
304eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root        if (seq.size() == 2)
314eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root        {
324eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root            responseBytes = ResponseBytes.getInstance(
334eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root                                (ASN1TaggedObject)seq.getObjectAt(1), true);
344eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root        }
354eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root    }
364eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root
374eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root    public static OCSPResponse getInstance(
384eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root        ASN1TaggedObject obj,
394eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root        boolean          explicit)
404eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root    {
414eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root        return getInstance(ASN1Sequence.getInstance(obj, explicit));
424eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root    }
434eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root
444eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root    public static OCSPResponse getInstance(
454eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root        Object  obj)
464eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root    {
474eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root        if (obj instanceof OCSPResponse)
484eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root        {
494eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root            return (OCSPResponse)obj;
504eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root        }
514eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root        else if (obj != null)
524eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root        {
534eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root            return new OCSPResponse(ASN1Sequence.getInstance(obj));
544eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root        }
554eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root
564eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root        return null;
574eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root    }
584eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root
594eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root    public OCSPResponseStatus getResponseStatus()
604eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root    {
614eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root        return responseStatus;
624eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root    }
634eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root
644eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root    public ResponseBytes getResponseBytes()
654eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root    {
664eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root        return responseBytes;
674eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root    }
684eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root
694eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root    /**
704eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root     * Produce an object suitable for an ASN1OutputStream.
714eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root     * <pre>
724eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root     * OCSPResponse ::= SEQUENCE {
734eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root     *     responseStatus         OCSPResponseStatus,
744eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root     *     responseBytes          [0] EXPLICIT ResponseBytes OPTIONAL }
754eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root     * </pre>
764eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root     */
774eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root    public ASN1Primitive toASN1Primitive()
784eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root    {
794eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root        ASN1EncodableVector    v = new ASN1EncodableVector();
804eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root
814eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root        v.add(responseStatus);
824eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root
834eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root        if (responseBytes != null)
844eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root        {
854eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root            v.add(new DERTaggedObject(true, 0, responseBytes));
864eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root        }
874eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root
884eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root        return new DERSequence(v);
894eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root    }
904eb438010b8024cfa97cdad1906a8e6963a16f5bKenny Root}
91