001: package org.bouncycastle.asn1.cmp;
002:
003: import org.bouncycastle.asn1.ASN1Encodable;
004: import org.bouncycastle.asn1.ASN1EncodableVector;
005: import org.bouncycastle.asn1.ASN1Sequence;
006: import org.bouncycastle.asn1.ASN1TaggedObject;
007: import org.bouncycastle.asn1.DERObject;
008: import org.bouncycastle.asn1.DERSequence;
009: import org.bouncycastle.asn1.DERTaggedObject;
010:
011: import java.util.Enumeration;
012:
013: public class KeyRecRepContent extends ASN1Encodable {
014: private PKIStatusInfo status;
015: private CMPCertificate newSigCert;
016: private ASN1Sequence caCerts;
017: private ASN1Sequence keyPairHist;
018:
019: private KeyRecRepContent(ASN1Sequence seq) {
020: Enumeration en = seq.getObjects();
021:
022: status = PKIStatusInfo.getInstance(en.nextElement());
023:
024: while (en.hasMoreElements()) {
025: ASN1TaggedObject tObj = ASN1TaggedObject.getInstance(en
026: .nextElement());
027:
028: switch (tObj.getTagNo()) {
029: case 0:
030: newSigCert = CMPCertificate.getInstance(tObj
031: .getObject());
032: break;
033: case 1:
034: caCerts = ASN1Sequence.getInstance(tObj.getObject());
035: break;
036: case 2:
037: keyPairHist = ASN1Sequence
038: .getInstance(tObj.getObject());
039: break;
040: default:
041: throw new IllegalArgumentException(
042: "unknown tag number: " + tObj.getTagNo());
043: }
044: }
045: }
046:
047: public static KeyRecRepContent getInstance(Object o) {
048: if (o instanceof KeyRecRepContent) {
049: return (KeyRecRepContent) o;
050: }
051:
052: if (o instanceof ASN1Sequence) {
053: return new KeyRecRepContent((ASN1Sequence) o);
054: }
055:
056: throw new IllegalArgumentException("Invalid object: "
057: + o.getClass().getName());
058: }
059:
060: public PKIStatusInfo getStatus() {
061: return status;
062: }
063:
064: public CMPCertificate getNewSigCert() {
065: return newSigCert;
066: }
067:
068: public CMPCertificate[] getCaCerts() {
069: if (caCerts == null) {
070: return null;
071: }
072:
073: CMPCertificate[] results = new CMPCertificate[caCerts.size()];
074:
075: for (int i = 0; i != results.length; i++) {
076: results[i] = CMPCertificate.getInstance(caCerts
077: .getObjectAt(i));
078: }
079:
080: return results;
081: }
082:
083: public CertifiedKeyPair[] getKeyPairHist() {
084: if (keyPairHist == null) {
085: return null;
086: }
087:
088: CertifiedKeyPair[] results = new CertifiedKeyPair[keyPairHist
089: .size()];
090:
091: for (int i = 0; i != results.length; i++) {
092: results[i] = CertifiedKeyPair.getInstance(keyPairHist
093: .getObjectAt(i));
094: }
095:
096: return results;
097: }
098:
099: /**
100: * <pre>
101: * KeyRecRepContent ::= SEQUENCE {
102: * status PKIStatusInfo,
103: * newSigCert [0] CMPCertificate OPTIONAL,
104: * caCerts [1] SEQUENCE SIZE (1..MAX) OF
105: * CMPCertificate OPTIONAL,
106: * keyPairHist [2] SEQUENCE SIZE (1..MAX) OF
107: * CertifiedKeyPair OPTIONAL
108: * }
109: * </pre>
110: * @return a basic ASN.1 object representation.
111: */
112: public DERObject toASN1Object() {
113: ASN1EncodableVector v = new ASN1EncodableVector();
114:
115: v.add(status);
116:
117: addOptional(v, 0, newSigCert);
118: addOptional(v, 1, caCerts);
119: addOptional(v, 2, keyPairHist);
120:
121: return new DERSequence(v);
122: }
123:
124: private void addOptional(ASN1EncodableVector v, int tagNo,
125: ASN1Encodable obj) {
126: if (obj != null) {
127: v.add(new DERTaggedObject(true, tagNo, obj));
128: }
129: }
130: }
|