1 package org.bouncycastle.asn1.x509;
2
3 import org.bouncycastle.asn1.*;
4 import org.bouncycastle.asn1.pkcs.*;
5
6
21 public class V1TBSCertificateGenerator
22 {
23 DERTaggedObject version = new DERTaggedObject(0, new DERInteger(0));
24
25 DERInteger serialNumber;
26 AlgorithmIdentifier signature;
27 X509Name issuer;
28 TimeTime startDate, endDate;
29 X509Name subject;
30 SubjectPublicKeyInfo subjectPublicKeyInfo;
31
32 public V1TBSCertificateGenerator()
33 {
34 }
35
36 public void setSerialNumber(
37 DERInteger serialNumber)
38 {
39 this.serialNumber = serialNumber;
40 }
41
42 public void setSignature(
43 AlgorithmIdentifier signature)
44 {
45 this.signature = signature;
46 }
47
48 public void setIssuer(
49 X509Name issuer)
50 {
51 this.issuer = issuer;
52 }
53
54 public void setStartDate(
55 Time startDate)
56 {
57 this.startDate = startDate;
58 }
59
60 public void setStartDate(
61 DERUTCTime startDate)
62 {
63 this.startDate = new Time(startDate);
64 }
65
66 public void setEndDate(
67 Time endDate)
68 {
69 this.endDate = endDate;
70 }
71
72 public void setEndDate(
73 DERUTCTime endDate)
74 {
75 this.endDate = new Time(endDate);
76 }
77
78 public void setSubject(
79 X509Name subject)
80 {
81 this.subject = subject;
82 }
83
84 public void setSubjectPublicKeyInfo(
85 SubjectPublicKeyInfo pubKeyInfo)
86 {
87 this.subjectPublicKeyInfo = pubKeyInfo;
88 }
89
90 public TBSCertificateStructure generateTBSCertificate()
91 {
92 if ((serialNumber == null) || (signature == null)
93 || (issuer == null) || (startDate == null) || (endDate == null)
94 || (subject == null) || (subjectPublicKeyInfo == null))
95 {
96 throw new IllegalStateException("not all mandatory fields set in V1 TBScertificate generator");
97 }
98
99 DERConstructedSequence seq = new DERConstructedSequence();
100
101 seq.addObject(version);
102 seq.addObject(serialNumber);
103 seq.addObject(signature);
104 seq.addObject(issuer);
105
106
107
108
109 DERConstructedSequence validity = new DERConstructedSequence();
110
111 validity.addObject(startDate);
112 validity.addObject(endDate);
113
114 seq.addObject(validity);
115
116 seq.addObject(subject);
117
118 seq.addObject(subjectPublicKeyInfo);
119
120 return new TBSCertificateStructure(seq);
121 }
122 }
123