001: package org.bouncycastle.asn1.cmp;
002:
003: import org.bouncycastle.asn1.ASN1Choice;
004: import org.bouncycastle.asn1.ASN1Encodable;
005: import org.bouncycastle.asn1.ASN1TaggedObject;
006: import org.bouncycastle.asn1.DERObject;
007: import org.bouncycastle.asn1.DERTaggedObject;
008: import org.bouncycastle.asn1.crmf.CertReqMessages;
009: import org.bouncycastle.asn1.pkcs.CertificationRequest;
010:
011: public class PKIBody extends ASN1Encodable implements ASN1Choice {
012: private int tagNo;
013: private ASN1Encodable body;
014:
015: public static PKIBody getInstance(Object o) {
016: if (o instanceof PKIBody) {
017: return (PKIBody) o;
018: }
019:
020: if (o instanceof ASN1TaggedObject) {
021: return new PKIBody((ASN1TaggedObject) o);
022: }
023:
024: throw new IllegalArgumentException("Invalid object: "
025: + o.getClass().getName());
026: }
027:
028: private PKIBody(ASN1TaggedObject tagged) {
029: tagNo = tagged.getTagNo();
030:
031: switch (tagged.getTagNo()) {
032: case 0:
033: body = CertReqMessages.getInstance(tagged.getObject());
034: break;
035: case 1:
036: body = CertRepMessage.getInstance(tagged.getObject());
037: break;
038: case 2:
039: body = CertReqMessages.getInstance(tagged.getObject());
040: break;
041: case 3:
042: body = CertRepMessage.getInstance(tagged.getObject());
043: break;
044: case 4:
045: body = CertificationRequest.getInstance(tagged.getObject());
046: break;
047: case 5:
048: body = POPODecKeyChallContent.getInstance(tagged
049: .getObject());
050: break;
051: case 6:
052: body = POPODecKeyRespContent
053: .getInstance(tagged.getObject());
054: break;
055: case 7:
056: body = CertReqMessages.getInstance(tagged.getObject());
057: break;
058: case 8:
059: body = CertRepMessage.getInstance(tagged.getObject());
060: break;
061: case 9:
062: body = CertReqMessages.getInstance(tagged.getObject());
063: break;
064: case 10:
065: body = KeyRecRepContent.getInstance(tagged.getObject());
066: break;
067: case 11:
068: body = RevReqContent.getInstance(tagged.getObject());
069: break;
070: case 12:
071: body = RevRepContent.getInstance(tagged.getObject());
072: break;
073: case 13:
074: body = CertReqMessages.getInstance(tagged.getObject());
075: break;
076: case 14:
077: body = CertRepMessage.getInstance(tagged.getObject());
078: break;
079: case 15:
080: body = CAKeyUpdAnnContent.getInstance(tagged.getObject());
081: break;
082: case 16:
083: body = CMPCertificate.getInstance(tagged.getObject()); // CertAnnContent
084: break;
085: case 17:
086: body = RevAnnContent.getInstance(tagged.getObject());
087: break;
088: case 18:
089: body = CRLAnnContent.getInstance(tagged.getObject());
090: break;
091: case 19:
092: body = PKIConfirmContent.getInstance(tagged.getObject());
093: break;
094: case 20:
095: body = PKIMessages.getInstance(tagged.getObject()); // NestedMessageContent
096: break;
097: case 21:
098: body = GenMsgContent.getInstance(tagged.getObject());
099: break;
100: case 22:
101: body = GenRepContent.getInstance(tagged.getObject());
102: break;
103: case 23:
104: body = ErrorMsgContent.getInstance(tagged.getObject());
105: break;
106: case 24:
107: body = CertConfirmContent.getInstance(tagged.getObject());
108: break;
109: case 25:
110: body = PollReqContent.getInstance(tagged.getObject());
111: break;
112: case 26:
113: body = PollRepContent.getInstance(tagged.getObject());
114: break;
115: default:
116: throw new IllegalArgumentException("unknown tag number: "
117: + tagged.getTagNo());
118: }
119: }
120:
121: /**
122: * <pre>
123: * PKIBody ::= CHOICE { -- message-specific body elements
124: * ir [0] CertReqMessages, --Initialization Request
125: * ip [1] CertRepMessage, --Initialization Response
126: * cr [2] CertReqMessages, --Certification Request
127: * cp [3] CertRepMessage, --Certification Response
128: * p10cr [4] CertificationRequest, --imported from [PKCS10]
129: * popdecc [5] POPODecKeyChallContent, --pop Challenge
130: * popdecr [6] POPODecKeyRespContent, --pop Response
131: * kur [7] CertReqMessages, --Key Update Request
132: * kup [8] CertRepMessage, --Key Update Response
133: * krr [9] CertReqMessages, --Key Recovery Request
134: * krp [10] KeyRecRepContent, --Key Recovery Response
135: * rr [11] RevReqContent, --Revocation Request
136: * rp [12] RevRepContent, --Revocation Response
137: * ccr [13] CertReqMessages, --Cross-Cert. Request
138: * ccp [14] CertRepMessage, --Cross-Cert. Response
139: * ckuann [15] CAKeyUpdAnnContent, --CA Key Update Ann.
140: * cann [16] CertAnnContent, --Certificate Ann.
141: * rann [17] RevAnnContent, --Revocation Ann.
142: * crlann [18] CRLAnnContent, --CRL Announcement
143: * pkiconf [19] PKIConfirmContent, --Confirmation
144: * nested [20] NestedMessageContent, --Nested Message
145: * genm [21] GenMsgContent, --General Message
146: * genp [22] GenRepContent, --General Response
147: * error [23] ErrorMsgContent, --Error Message
148: * certConf [24] CertConfirmContent, --Certificate confirm
149: * pollReq [25] PollReqContent, --Polling request
150: * pollRep [26] PollRepContent --Polling response
151: * }
152: * </pre>
153: * @return a basic ASN.1 object representation.
154: */
155: public DERObject toASN1Object() {
156: return new DERTaggedObject(true, tagNo, body);
157: }
158: }
|