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.DERInteger;
07: import org.bouncycastle.asn1.DERObject;
08: import org.bouncycastle.asn1.DERSequence;
09:
10: import java.util.Enumeration;
11:
12: public class ErrorMsgContent extends ASN1Encodable {
13: private PKIStatusInfo pKIStatusInfo;
14: private DERInteger errorCode;
15: private PKIFreeText errorDetails;
16:
17: private ErrorMsgContent(ASN1Sequence seq) {
18: Enumeration en = seq.getObjects();
19:
20: pKIStatusInfo = PKIStatusInfo.getInstance(en.nextElement());
21:
22: while (en.hasMoreElements()) {
23: Object o = en.nextElement();
24:
25: if (o instanceof DERInteger) {
26: errorCode = DERInteger.getInstance(o);
27: } else {
28: errorDetails = PKIFreeText.getInstance(o);
29: }
30: }
31: }
32:
33: public static ErrorMsgContent getInstance(Object o) {
34: if (o instanceof ErrorMsgContent) {
35: return (ErrorMsgContent) o;
36: }
37:
38: if (o instanceof ASN1Sequence) {
39: return new ErrorMsgContent((ASN1Sequence) o);
40: }
41:
42: throw new IllegalArgumentException("Invalid object: "
43: + o.getClass().getName());
44: }
45:
46: public PKIStatusInfo getPKIStatusInfo() {
47: return pKIStatusInfo;
48: }
49:
50: public DERInteger getErrorCode() {
51: return errorCode;
52: }
53:
54: public PKIFreeText getErrorDetails() {
55: return errorDetails;
56: }
57:
58: /**
59: * <pre>
60: * ErrorMsgContent ::= SEQUENCE {
61: * pKIStatusInfo PKIStatusInfo,
62: * errorCode INTEGER OPTIONAL,
63: * -- implementation-specific error codes
64: * errorDetails PKIFreeText OPTIONAL
65: * -- implementation-specific error details
66: * }
67: * </pre>
68: * @return a basic ASN.1 object representation.
69: */
70: public DERObject toASN1Object() {
71: ASN1EncodableVector v = new ASN1EncodableVector();
72:
73: v.add(pKIStatusInfo);
74: addOptional(v, errorCode);
75: addOptional(v, errorDetails);
76:
77: return new DERSequence(v);
78: }
79:
80: private void addOptional(ASN1EncodableVector v, ASN1Encodable obj) {
81: if (obj != null) {
82: v.add(obj);
83: }
84: }
85: }
|