01: package org.bouncycastle.asn1.cmp;
02:
03: import org.bouncycastle.asn1.ASN1Encodable;
04: import org.bouncycastle.asn1.ASN1EncodableVector;
05: import org.bouncycastle.asn1.ASN1Sequence;
06: import org.bouncycastle.asn1.DERObject;
07: import org.bouncycastle.asn1.DERSequence;
08:
09: public class CertRepMessage extends ASN1Encodable {
10: private ASN1Sequence caPubs;
11: private ASN1Sequence response;
12:
13: private CertRepMessage(ASN1Sequence seq) {
14: int index = 0;
15:
16: if (seq.size() > 1) {
17: caPubs = ASN1Sequence.getInstance(seq.getObjectAt(index++));
18: }
19:
20: response = ASN1Sequence.getInstance(seq.getObjectAt(index));
21: }
22:
23: public static CertRepMessage getInstance(Object o) {
24: if (o instanceof CertRepMessage) {
25: return (CertRepMessage) o;
26: }
27:
28: if (o instanceof ASN1Sequence) {
29: return new CertRepMessage((ASN1Sequence) o);
30: }
31:
32: throw new IllegalArgumentException("Invalid object: "
33: + o.getClass().getName());
34: }
35:
36: public CMPCertificate[] getCaPubs() {
37: if (caPubs == null) {
38: return null;
39: }
40:
41: CMPCertificate[] results = new CMPCertificate[caPubs.size()];
42:
43: for (int i = 0; i != results.length; i++) {
44: results[i] = CMPCertificate.getInstance(caPubs
45: .getObjectAt(i));
46: }
47:
48: return results;
49: }
50:
51: public CertResponse[] getResponse() {
52: CertResponse[] results = new CertResponse[caPubs.size()];
53:
54: for (int i = 0; i != results.length; i++) {
55: results[i] = CertResponse
56: .getInstance(caPubs.getObjectAt(i));
57: }
58:
59: return results;
60: }
61:
62: /**
63: * <pre>
64: * CertRepMessage ::= SEQUENCE {
65: * caPubs [1] SEQUENCE SIZE (1..MAX) OF CMPCertificate
66: * OPTIONAL,
67: * response SEQUENCE OF CertResponse
68: * }
69: * </pre>
70: * @return a basic ASN.1 object representation.
71: */
72: public DERObject toASN1Object() {
73: ASN1EncodableVector v = new ASN1EncodableVector();
74:
75: if (caPubs != null) {
76: v.add(caPubs);
77: }
78:
79: v.add(response);
80:
81: return new DERSequence(v);
82: }
83: }
|