1 package org.bouncycastle.asn1.x509;
3 import java.util.Vector;
4 import java.util.Enumeration;
6 import org.bouncycastle.asn1.*;
9 * Generator for Version 2 TBSCertList structures.
11 * TBSCertList ::= SEQUENCE {
12 * version Version OPTIONAL,
13 * -- if present, shall be v2
14 * signature AlgorithmIdentifier,
17 * nextUpdate Time OPTIONAL,
18 * revokedCertificates SEQUENCE OF SEQUENCE {
19 * userCertificate CertificateSerialNumber,
20 * revocationDate Time,
21 * crlEntryExtensions Extensions OPTIONAL
22 * -- if present, shall be v2
24 * crlExtensions [0] EXPLICIT Extensions OPTIONAL
25 * -- if present, shall be v2
29 * <b>Note: This class may be subject to change</b>
31 public class V2TBSCertListGenerator
33 DERInteger version = new DERInteger(1);
35 AlgorithmIdentifier signature;
37 DERUTCTime thisUpdate, nextUpdate=null;
38 X509Extensions extensions=null;
39 private Vector crlentries=null;
41 public V2TBSCertListGenerator()
46 public void setSignature(
47 AlgorithmIdentifier signature)
49 this.signature = signature;
52 public void setIssuer(
58 public void setThisUpdate(
59 DERUTCTime thisUpdate)
61 this.thisUpdate = thisUpdate;
64 public void setNextUpdate(
65 DERUTCTime nextUpdate)
67 this.nextUpdate = nextUpdate;
71 public void addCRLEntry(
72 DERConstructedSequence crlEntry)
74 if (crlentries == null)
75 crlentries = new Vector();
76 crlentries.addElement(crlEntry);
79 public void addCRLEntry(DERInteger userCertificate, DERUTCTime revocationDate, int reason)
81 DERConstructedSequence seq = new DERConstructedSequence();
82 seq.addObject(userCertificate);
83 seq.addObject(revocationDate);
86 ReasonFlags rf = new ReasonFlags(reason);
87 DERConstructedSequence eseq = new DERConstructedSequence();
88 eseq.addObject(X509Extensions.ReasonCode);
90 X509Extensions ex = new X509Extensions(eseq);
93 if (crlentries == null)
94 crlentries = new Vector();
95 crlentries.addElement(seq);
98 public void setExtensions(
99 X509Extensions extensions)
101 this.extensions = extensions;
104 public TBSCertList generateTBSCertList()
106 if ((signature == null) || (issuer == null) || (thisUpdate == null))
108 throw new IllegalStateException("Not all mandatory fields set in V2 TBSCertList generator.");
111 DERConstructedSequence seq = new DERConstructedSequence();
113 seq.addObject(version);
114 seq.addObject(signature);
115 seq.addObject(issuer);
117 seq.addObject(thisUpdate);
118 if (nextUpdate != null)
119 seq.addObject(nextUpdate);
121 // Add CRLEntries if they exist
122 if (crlentries != null) {
123 DERConstructedSequence certseq = new DERConstructedSequence();
124 Enumeration it = crlentries.elements();
125 while( it.hasMoreElements() ) {
126 certseq.addObject((DERConstructedSequence)it.nextElement());
128 seq.addObject(certseq);
131 if (extensions != null)
133 seq.addObject(new DERTaggedObject(0, extensions.getDERObject()));
136 return new TBSCertList(seq);