01: package org.bouncycastle.ocsp;
02:
03: import java.io.*;
04:
05: import org.bouncycastle.asn1.*;
06: import org.bouncycastle.asn1.ocsp.*;
07:
08: /**
09: * base generator for an OCSP response - at the moment this only supports the
10: * generation of responses containing BasicOCSP responses.
11: */
12: public class OCSPRespGenerator {
13: public static final int SUCCESSFUL = 0; // Response has valid confirmations
14: public static final int MALFORMED_REQUEST = 1; // Illegal confirmation request
15: public static final int INTERNAL_ERROR = 2; // Internal error in issuer
16: public static final int TRY_LATER = 3; // Try again later
17: // (4) is not used
18: public static final int SIG_REQUIRED = 5; // Must sign the request
19: public static final int UNAUTHORIZED = 6; // Request unauthorized
20:
21: public OCSPResp generate(int status, Object response)
22: throws OCSPException {
23: if (response == null) {
24: return new OCSPResp(new OCSPResponse(
25: new OCSPResponseStatus(status), null));
26: }
27: if (response instanceof BasicOCSPResp) {
28: BasicOCSPResp r = (BasicOCSPResp) response;
29: ASN1OctetString octs;
30:
31: try {
32: octs = new DEROctetString(r.getEncoded());
33: } catch (IOException e) {
34: throw new OCSPException("can't encode object.", e);
35: }
36:
37: ResponseBytes rb = new ResponseBytes(
38: OCSPObjectIdentifiers.id_pkix_ocsp_basic, octs);
39:
40: return new OCSPResp(new OCSPResponse(
41: new OCSPResponseStatus(status), rb));
42: }
43:
44: throw new OCSPException("unknown response object");
45: }
46: }
|