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: import org.bouncycastle.asn1.crmf.CertId;
011: import org.bouncycastle.asn1.x509.CertificateList;
012:
013: import java.util.Enumeration;
014:
015: public class RevRepContent extends ASN1Encodable {
016: private ASN1Sequence status;
017: private ASN1Sequence revCerts;
018: private ASN1Sequence crls;
019:
020: private RevRepContent(ASN1Sequence seq) {
021: Enumeration en = seq.getObjects();
022:
023: status = ASN1Sequence.getInstance(en.nextElement());
024: while (en.hasMoreElements()) {
025: ASN1TaggedObject tObj = ASN1TaggedObject.getInstance(en
026: .nextElement());
027:
028: if (tObj.getTagNo() == 0) {
029: revCerts = ASN1Sequence.getInstance(tObj, true);
030: } else {
031: crls = ASN1Sequence.getInstance(tObj, true);
032: }
033: }
034: }
035:
036: public static RevRepContent getInstance(Object o) {
037: if (o instanceof RevRepContent) {
038: return (RevRepContent) o;
039: }
040:
041: if (o instanceof ASN1Sequence) {
042: return new RevRepContent((ASN1Sequence) o);
043: }
044:
045: throw new IllegalArgumentException("Invalid object: "
046: + o.getClass().getName());
047: }
048:
049: public PKIStatusInfo[] getStatus() {
050: PKIStatusInfo[] results = new PKIStatusInfo[status.size()];
051:
052: for (int i = 0; i != results.length; i++) {
053: results[i] = PKIStatusInfo.getInstance(status
054: .getObjectAt(i));
055: }
056:
057: return results;
058: }
059:
060: public CertId[] getRevCerts() {
061: if (revCerts == null) {
062: return null;
063: }
064:
065: CertId[] results = new CertId[revCerts.size()];
066:
067: for (int i = 0; i != results.length; i++) {
068: results[i] = CertId.getInstance(revCerts.getObjectAt(i));
069: }
070:
071: return results;
072: }
073:
074: public CertificateList[] getCrls() {
075: if (crls == null) {
076: return null;
077: }
078:
079: CertificateList[] results = new CertificateList[crls.size()];
080:
081: for (int i = 0; i != results.length; i++) {
082: results[i] = CertificateList.getInstance(crls
083: .getObjectAt(i));
084: }
085:
086: return results;
087: }
088:
089: /**
090: * <pre>
091: * RevRepContent ::= SEQUENCE {
092: * status SEQUENCE SIZE (1..MAX) OF PKIStatusInfo,
093: * -- in same order as was sent in RevReqContent
094: * revCerts [0] SEQUENCE SIZE (1..MAX) OF CertId OPTIONAL,
095: * -- IDs for which revocation was requested
096: * -- (same order as status)
097: * crls [1] SEQUENCE SIZE (1..MAX) OF CertificateList OPTIONAL
098: * -- the resulting CRLs (there may be more than one)
099: * }
100: * </pre>
101: * @return a basic ASN.1 object representation.
102: */
103: public DERObject toASN1Object() {
104: ASN1EncodableVector v = new ASN1EncodableVector();
105:
106: v.add(status);
107:
108: addOptional(v, 0, revCerts);
109: addOptional(v, 1, crls);
110:
111: return new DERSequence(v);
112: }
113:
114: private void addOptional(ASN1EncodableVector v, int tagNo,
115: ASN1Encodable obj) {
116: if (obj != null) {
117: v.add(new DERTaggedObject(true, tagNo, obj));
118: }
119: }
120: }
|