01: package org.bouncycastle.asn1.tsp;
02:
03: import java.util.Enumeration;
04:
05: import org.bouncycastle.asn1.ASN1Encodable;
06: import org.bouncycastle.asn1.ASN1EncodableVector;
07: import org.bouncycastle.asn1.ASN1Sequence;
08: import org.bouncycastle.asn1.DERObject;
09: import org.bouncycastle.asn1.DERSequence;
10: import org.bouncycastle.asn1.cms.ContentInfo;
11: import org.bouncycastle.asn1.cmp.PKIStatusInfo;
12:
13: public class TimeStampResp extends ASN1Encodable {
14: PKIStatusInfo pkiStatusInfo;
15:
16: ContentInfo timeStampToken;
17:
18: public static TimeStampResp getInstance(Object o) {
19: if (o == null || o instanceof TimeStampResp) {
20: return (TimeStampResp) o;
21: } else if (o instanceof ASN1Sequence) {
22: return new TimeStampResp((ASN1Sequence) o);
23: }
24:
25: throw new IllegalArgumentException(
26: "unknown object in 'TimeStampResp' factory : "
27: + o.getClass().getName() + ".");
28: }
29:
30: public TimeStampResp(ASN1Sequence seq) {
31:
32: Enumeration e = seq.getObjects();
33:
34: // status
35: pkiStatusInfo = PKIStatusInfo.getInstance(e.nextElement());
36:
37: if (e.hasMoreElements()) {
38: timeStampToken = ContentInfo.getInstance(e.nextElement());
39: }
40: }
41:
42: public TimeStampResp(PKIStatusInfo pkiStatusInfo,
43: ContentInfo timeStampToken) {
44: this .pkiStatusInfo = pkiStatusInfo;
45: this .timeStampToken = timeStampToken;
46: }
47:
48: public PKIStatusInfo getStatus() {
49: return pkiStatusInfo;
50: }
51:
52: public ContentInfo getTimeStampToken() {
53: return timeStampToken;
54: }
55:
56: /**
57: * <pre>
58: * TimeStampResp ::= SEQUENCE {
59: * status PKIStatusInfo,
60: * timeStampToken TimeStampToken OPTIONAL }
61: * </pre>
62: */
63: public DERObject toASN1Object() {
64: ASN1EncodableVector v = new ASN1EncodableVector();
65:
66: v.add(pkiStatusInfo);
67: if (timeStampToken != null) {
68: v.add(timeStampToken);
69: }
70:
71: return new DERSequence(v);
72: }
73: }
|