V2AttributeCertificateInfoGenerator.cs
3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using System;
namespace Org.BouncyCastle.Asn1.X509
{
/**
* Generator for Version 2 AttributeCertificateInfo
* <pre>
* AttributeCertificateInfo ::= Sequence {
* version AttCertVersion -- version is v2,
* holder Holder,
* issuer AttCertIssuer,
* signature AlgorithmIdentifier,
* serialNumber CertificateSerialNumber,
* attrCertValidityPeriod AttCertValidityPeriod,
* attributes Sequence OF Attr,
* issuerUniqueID UniqueIdentifier OPTIONAL,
* extensions Extensions OPTIONAL
* }
* </pre>
*
*/
public class V2AttributeCertificateInfoGenerator
{
internal DerInteger version;
internal Holder holder;
internal AttCertIssuer issuer;
internal AlgorithmIdentifier signature;
internal DerInteger serialNumber;
// internal AttCertValidityPeriod attrCertValidityPeriod;
internal Asn1EncodableVector attributes;
internal DerBitString issuerUniqueID;
internal X509Extensions extensions;
internal DerGeneralizedTime startDate, endDate;
public V2AttributeCertificateInfoGenerator()
{
this.version = new DerInteger(1);
attributes = new Asn1EncodableVector();
}
public void SetHolder(
Holder holder)
{
this.holder = holder;
}
public void AddAttribute(
string oid,
Asn1Encodable value)
{
attributes.Add(new AttributeX509(new DerObjectIdentifier(oid), new DerSet(value)));
}
/**
* @param attribute
*/
public void AddAttribute(AttributeX509 attribute)
{
attributes.Add(attribute);
}
public void SetSerialNumber(
DerInteger serialNumber)
{
this.serialNumber = serialNumber;
}
public void SetSignature(
AlgorithmIdentifier signature)
{
this.signature = signature;
}
public void SetIssuer(
AttCertIssuer issuer)
{
this.issuer = issuer;
}
public void SetStartDate(
DerGeneralizedTime startDate)
{
this.startDate = startDate;
}
public void SetEndDate(
DerGeneralizedTime endDate)
{
this.endDate = endDate;
}
public void SetIssuerUniqueID(
DerBitString issuerUniqueID)
{
this.issuerUniqueID = issuerUniqueID;
}
public void SetExtensions(
X509Extensions extensions)
{
this.extensions = extensions;
}
public AttributeCertificateInfo GenerateAttributeCertificateInfo()
{
if ((serialNumber == null) || (signature == null)
|| (issuer == null) || (startDate == null) || (endDate == null)
|| (holder == null) || (attributes == null))
{
throw new InvalidOperationException("not all mandatory fields set in V2 AttributeCertificateInfo generator");
}
Asn1EncodableVector v = new Asn1EncodableVector(
version, holder, issuer, signature, serialNumber);
//
// before and after dates => AttCertValidityPeriod
//
v.Add(new AttCertValidityPeriod(startDate, endDate));
// Attributes
v.Add(new DerSequence(attributes));
if (issuerUniqueID != null)
{
v.Add(issuerUniqueID);
}
if (extensions != null)
{
v.Add(extensions);
}
return AttributeCertificateInfo.GetInstance(new DerSequence(v));
}
}
}