org.spongycastle.asn1.ocsp.OCSPResponse Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scprov-jdk15 Show documentation
Show all versions of scprov-jdk15 Show documentation
Spongy Castle is a package-rename (org.bouncycastle.* to org.spongycastle.*) of Bouncy Castle intended for Android.
Android ships with a stripped-down version of Bouncy Castle - this causes classloader collisions if you try to add
an alternative (updated/complete) Bouncy Castle jar.
This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5.
package org.spongycastle.asn1.ocsp;
import org.spongycastle.asn1.ASN1EncodableVector;
import org.spongycastle.asn1.ASN1Sequence;
import org.spongycastle.asn1.ASN1TaggedObject;
import org.spongycastle.asn1.ASN1Encodable;
import org.spongycastle.asn1.DEREnumerated;
import org.spongycastle.asn1.DERObject;
import org.spongycastle.asn1.DERSequence;
import org.spongycastle.asn1.DERTaggedObject;
public class OCSPResponse
extends ASN1Encodable
{
OCSPResponseStatus responseStatus;
ResponseBytes responseBytes;
public OCSPResponse(
OCSPResponseStatus responseStatus,
ResponseBytes responseBytes)
{
this.responseStatus = responseStatus;
this.responseBytes = responseBytes;
}
public OCSPResponse(
ASN1Sequence seq)
{
responseStatus = new OCSPResponseStatus(
DEREnumerated.getInstance(seq.getObjectAt(0)));
if (seq.size() == 2)
{
responseBytes = ResponseBytes.getInstance(
(ASN1TaggedObject)seq.getObjectAt(1), true);
}
}
public static OCSPResponse getInstance(
ASN1TaggedObject obj,
boolean explicit)
{
return getInstance(ASN1Sequence.getInstance(obj, explicit));
}
public static OCSPResponse getInstance(
Object obj)
{
if (obj == null || obj instanceof OCSPResponse)
{
return (OCSPResponse)obj;
}
else if (obj instanceof ASN1Sequence)
{
return new OCSPResponse((ASN1Sequence)obj);
}
throw new IllegalArgumentException("unknown object in factory: " + obj.getClass().getName());
}
public OCSPResponseStatus getResponseStatus()
{
return responseStatus;
}
public ResponseBytes getResponseBytes()
{
return responseBytes;
}
/**
* Produce an object suitable for an ASN1OutputStream.
*
* OCSPResponse ::= SEQUENCE {
* responseStatus OCSPResponseStatus,
* responseBytes [0] EXPLICIT ResponseBytes OPTIONAL }
*
*/
public DERObject toASN1Object()
{
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(responseStatus);
if (responseBytes != null)
{
v.add(new DERTaggedObject(true, 0, responseBytes));
}
return new DERSequence(v);
}
}