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
|
using System;
namespace Org.BouncyCastle.Asn1.Cmp
{
public class KeyRecRepContent
: Asn1Encodable
{
private readonly PkiStatusInfo status;
private readonly CmpCertificate newSigCert;
private readonly Asn1Sequence caCerts;
private readonly Asn1Sequence keyPairHist;
private KeyRecRepContent(Asn1Sequence seq)
{
status = PkiStatusInfo.GetInstance(seq[0]);
for (int pos = 1; pos < seq.Count; ++pos)
{
Asn1TaggedObject tObj = Asn1TaggedObject.GetInstance(seq[pos]);
switch (tObj.TagNo)
{
case 0:
newSigCert = CmpCertificate.GetInstance(tObj.GetObject());
break;
case 1:
caCerts = Asn1Sequence.GetInstance(tObj.GetObject());
break;
case 2:
keyPairHist = Asn1Sequence.GetInstance(tObj.GetObject());
break;
default:
throw new ArgumentException("unknown tag number: " + tObj.TagNo, "seq");
}
}
}
public static KeyRecRepContent GetInstance(object obj)
{
if (obj is KeyRecRepContent)
return (KeyRecRepContent)obj;
if (obj is Asn1Sequence)
return new KeyRecRepContent((Asn1Sequence)obj);
throw new ArgumentException("Invalid object: " + obj.GetType().Name, "obj");
}
public virtual PkiStatusInfo Status
{
get { return status; }
}
public virtual CmpCertificate NewSigCert
{
get { return newSigCert; }
}
public virtual CmpCertificate[] GetCACerts()
{
if (caCerts == null)
return null;
CmpCertificate[] results = new CmpCertificate[caCerts.Count];
for (int i = 0; i != results.Length; ++i)
{
results[i] = CmpCertificate.GetInstance(caCerts[i]);
}
return results;
}
public virtual CertifiedKeyPair[] GetKeyPairHist()
{
if (keyPairHist == null)
return null;
CertifiedKeyPair[] results = new CertifiedKeyPair[keyPairHist.Count];
for (int i = 0; i != results.Length; ++i)
{
results[i] = CertifiedKeyPair.GetInstance(keyPairHist[i]);
}
return results;
}
/**
* <pre>
* KeyRecRepContent ::= SEQUENCE {
* status PKIStatusInfo,
* newSigCert [0] CMPCertificate OPTIONAL,
* caCerts [1] SEQUENCE SIZE (1..MAX) OF
* CMPCertificate OPTIONAL,
* keyPairHist [2] SEQUENCE SIZE (1..MAX) OF
* CertifiedKeyPair OPTIONAL
* }
* </pre>
* @return a basic ASN.1 object representation.
*/
public override Asn1Object ToAsn1Object()
{
Asn1EncodableVector v = new Asn1EncodableVector(status);
AddOptional(v, 0, newSigCert);
AddOptional(v, 1, caCerts);
AddOptional(v, 2, keyPairHist);
return new DerSequence(v);
}
private void AddOptional(Asn1EncodableVector v, int tagNo, Asn1Encodable obj)
{
if (obj != null)
{
v.Add(new DerTaggedObject(true, tagNo, obj));
}
}
}
}
|