01: package org.bouncycastle.ocsp;
02:
03: import org.bouncycastle.asn1.DERGeneralizedTime;
04: import org.bouncycastle.asn1.ocsp.RevokedInfo;
05: import org.bouncycastle.asn1.x509.CRLReason;
06:
07: import java.text.ParseException;
08: import java.util.Date;
09:
10: /**
11: * wrapper for the RevokedInfo object
12: */
13: public class RevokedStatus implements CertificateStatus {
14: RevokedInfo info;
15:
16: public RevokedStatus(RevokedInfo info) {
17: this .info = info;
18: }
19:
20: public RevokedStatus(Date revocationDate, int reason) {
21: this .info = new RevokedInfo(new DERGeneralizedTime(
22: revocationDate), new CRLReason(reason));
23: }
24:
25: public Date getRevocationTime() {
26: try {
27: return info.getRevocationTime().getDate();
28: } catch (ParseException e) {
29: throw new IllegalStateException("ParseException:"
30: + e.getMessage());
31: }
32: }
33:
34: public boolean hasRevocationReason() {
35: return (info.getRevocationReason() != null);
36: }
37:
38: /**
39: * return the revocation reason. Note: this field is optional, test for it
40: * with hasRevocationReason() first.
41: * @return the revocation reason value.
42: * @exception IllegalStateException if a reason is asked for and none is avaliable
43: */
44: public int getRevocationReason() {
45: if (info.getRevocationReason() == null) {
46: throw new IllegalStateException(
47: "attempt to get a reason where none is available");
48: }
49:
50: return info.getRevocationReason().getValue().intValue();
51: }
52: }
|