1 package org.bouncycastle.asn1.ocsp; 2 3 import org.bouncycastle.asn1.ASN1EncodableVector; 4 import org.bouncycastle.asn1.ASN1Object; 5 import org.bouncycastle.asn1.ASN1Primitive; 6 import org.bouncycastle.asn1.ASN1Sequence; 7 import org.bouncycastle.asn1.ASN1TaggedObject; 8 import org.bouncycastle.asn1.DERSequence; 9 import org.bouncycastle.asn1.DERTaggedObject; 10 11 public class OCSPResponse 12 extends ASN1Object 13 { 14 OCSPResponseStatus responseStatus; 15 ResponseBytes responseBytes; 16 OCSPResponse( OCSPResponseStatus responseStatus, ResponseBytes responseBytes)17 public OCSPResponse( 18 OCSPResponseStatus responseStatus, 19 ResponseBytes responseBytes) 20 { 21 this.responseStatus = responseStatus; 22 this.responseBytes = responseBytes; 23 } 24 OCSPResponse( ASN1Sequence seq)25 private OCSPResponse( 26 ASN1Sequence seq) 27 { 28 responseStatus = OCSPResponseStatus.getInstance(seq.getObjectAt(0)); 29 30 if (seq.size() == 2) 31 { 32 responseBytes = ResponseBytes.getInstance( 33 (ASN1TaggedObject)seq.getObjectAt(1), true); 34 } 35 } 36 getInstance( ASN1TaggedObject obj, boolean explicit)37 public static OCSPResponse getInstance( 38 ASN1TaggedObject obj, 39 boolean explicit) 40 { 41 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 42 } 43 getInstance( Object obj)44 public static OCSPResponse getInstance( 45 Object obj) 46 { 47 if (obj instanceof OCSPResponse) 48 { 49 return (OCSPResponse)obj; 50 } 51 else if (obj != null) 52 { 53 return new OCSPResponse(ASN1Sequence.getInstance(obj)); 54 } 55 56 return null; 57 } 58 getResponseStatus()59 public OCSPResponseStatus getResponseStatus() 60 { 61 return responseStatus; 62 } 63 getResponseBytes()64 public ResponseBytes getResponseBytes() 65 { 66 return responseBytes; 67 } 68 69 /** 70 * Produce an object suitable for an ASN1OutputStream. 71 * <pre> 72 * OCSPResponse ::= SEQUENCE { 73 * responseStatus OCSPResponseStatus, 74 * responseBytes [0] EXPLICIT ResponseBytes OPTIONAL } 75 * </pre> 76 */ toASN1Primitive()77 public ASN1Primitive toASN1Primitive() 78 { 79 ASN1EncodableVector v = new ASN1EncodableVector(); 80 81 v.add(responseStatus); 82 83 if (responseBytes != null) 84 { 85 v.add(new DERTaggedObject(true, 0, responseBytes)); 86 } 87 88 return new DERSequence(v); 89 } 90 } 91