CertTemplate.cs
4.47 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
138
139
140
141
142
143
144
145
146
147
148
149
using System;
using Org.BouncyCastle.Asn1.X509;
namespace Org.BouncyCastle.Asn1.Crmf
{
public class CertTemplate
: Asn1Encodable
{
private readonly Asn1Sequence seq;
private readonly DerInteger version;
private readonly DerInteger serialNumber;
private readonly AlgorithmIdentifier signingAlg;
private readonly X509Name issuer;
private readonly OptionalValidity validity;
private readonly X509Name subject;
private readonly SubjectPublicKeyInfo publicKey;
private readonly DerBitString issuerUID;
private readonly DerBitString subjectUID;
private readonly X509Extensions extensions;
private CertTemplate(Asn1Sequence seq)
{
this.seq = seq;
foreach (Asn1TaggedObject tObj in seq)
{
switch (tObj.TagNo)
{
case 0:
version = DerInteger.GetInstance(tObj, false);
break;
case 1:
serialNumber = DerInteger.GetInstance(tObj, false);
break;
case 2:
signingAlg = AlgorithmIdentifier.GetInstance(tObj, false);
break;
case 3:
issuer = X509Name.GetInstance(tObj, true); // CHOICE
break;
case 4:
validity = OptionalValidity.GetInstance(Asn1Sequence.GetInstance(tObj, false));
break;
case 5:
subject = X509Name.GetInstance(tObj, true); // CHOICE
break;
case 6:
publicKey = SubjectPublicKeyInfo.GetInstance(tObj, false);
break;
case 7:
issuerUID = DerBitString.GetInstance(tObj, false);
break;
case 8:
subjectUID = DerBitString.GetInstance(tObj, false);
break;
case 9:
extensions = X509Extensions.GetInstance(tObj, false);
break;
default:
throw new ArgumentException("unknown tag: " + tObj.TagNo, "seq");
}
}
}
public static CertTemplate GetInstance(object obj)
{
if (obj is CertTemplate)
return (CertTemplate)obj;
if (obj != null)
return new CertTemplate(Asn1Sequence.GetInstance(obj));
return null;
}
public virtual int Version
{
get { return version.Value.IntValue; }
}
public virtual DerInteger SerialNumber
{
get { return serialNumber; }
}
public virtual AlgorithmIdentifier SigningAlg
{
get { return signingAlg; }
}
public virtual X509Name Issuer
{
get { return issuer; }
}
public virtual OptionalValidity Validity
{
get { return validity; }
}
public virtual X509Name Subject
{
get { return subject; }
}
public virtual SubjectPublicKeyInfo PublicKey
{
get { return publicKey; }
}
public virtual DerBitString IssuerUID
{
get { return issuerUID; }
}
public virtual DerBitString SubjectUID
{
get { return subjectUID; }
}
public virtual X509Extensions Extensions
{
get { return extensions; }
}
/**
* <pre>
* CertTemplate ::= SEQUENCE {
* version [0] Version OPTIONAL,
* serialNumber [1] INTEGER OPTIONAL,
* signingAlg [2] AlgorithmIdentifier OPTIONAL,
* issuer [3] Name OPTIONAL,
* validity [4] OptionalValidity OPTIONAL,
* subject [5] Name OPTIONAL,
* publicKey [6] SubjectPublicKeyInfo OPTIONAL,
* issuerUID [7] UniqueIdentifier OPTIONAL,
* subjectUID [8] UniqueIdentifier OPTIONAL,
* extensions [9] Extensions OPTIONAL }
* </pre>
* @return a basic ASN.1 object representation.
*/
public override Asn1Object ToAsn1Object()
{
return seq;
}
}
}