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 CertResponse
: Asn1Encodable
{
private readonly DerInteger certReqId;
private readonly PkiStatusInfo status;
private readonly CertifiedKeyPair certifiedKeyPair;
private readonly Asn1OctetString rspInfo;
private CertResponse(Asn1Sequence seq)
{
certReqId = DerInteger.GetInstance(seq[0]);
status = PkiStatusInfo.GetInstance(seq[1]);
if (seq.Count >= 3)
{
if (seq.Count == 3)
{
Asn1Encodable o = seq[2];
if (o is Asn1OctetString)
{
rspInfo = Asn1OctetString.GetInstance(o);
}
else
{
certifiedKeyPair = CertifiedKeyPair.GetInstance(o);
}
}
else
{
certifiedKeyPair = CertifiedKeyPair.GetInstance(seq[2]);
rspInfo = Asn1OctetString.GetInstance(seq[3]);
}
}
}
public static CertResponse GetInstance(object obj)
{
if (obj is CertResponse)
return (CertResponse)obj;
if (obj is Asn1Sequence)
return new CertResponse((Asn1Sequence)obj);
throw new ArgumentException("Invalid object: " + obj.GetType().Name, "obj");
}
public CertResponse(
DerInteger certReqId,
PkiStatusInfo status)
: this(certReqId, status, null, null)
{
}
public CertResponse(
DerInteger certReqId,
PkiStatusInfo status,
CertifiedKeyPair certifiedKeyPair,
Asn1OctetString rspInfo)
{
if (certReqId == null)
throw new ArgumentNullException("certReqId");
if (status == null)
throw new ArgumentNullException("status");
this.certReqId = certReqId;
this.status = status;
this.certifiedKeyPair = certifiedKeyPair;
this.rspInfo = rspInfo;
}
public virtual DerInteger CertReqID
{
get { return certReqId; }
}
public virtual PkiStatusInfo Status
{
get { return status; }
}
public virtual CertifiedKeyPair CertifiedKeyPair
{
get { return certifiedKeyPair; }
}
/**
* <pre>
* CertResponse ::= SEQUENCE {
* certReqId INTEGER,
* -- to match this response with corresponding request (a value
* -- of -1 is to be used if certReqId is not specified in the
* -- corresponding request)
* status PKIStatusInfo,
* certifiedKeyPair CertifiedKeyPair OPTIONAL,
* rspInfo OCTET STRING OPTIONAL
* -- analogous to the id-regInfo-utf8Pairs string defined
* -- for regInfo in CertReqMsg [CRMF]
* }
* </pre>
* @return a basic ASN.1 object representation.
*/
public override Asn1Object ToAsn1Object()
{
Asn1EncodableVector v = new Asn1EncodableVector(certReqId, status);
v.AddOptional(certifiedKeyPair);
v.AddOptional(rspInfo);
return new DerSequence(v);
}
}
}
|