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
|
using System;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Math;
namespace Org.BouncyCastle.Asn1.Cmp
{
public class CertStatus
: Asn1Encodable
{
public static CertStatus GetInstance(object obj)
{
if (obj == null)
return null;
if (obj is CertStatus certStatus)
return certStatus;
return new CertStatus(Asn1Sequence.GetInstance(obj));
}
public static CertStatus GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
{
return new CertStatus(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
}
private readonly Asn1OctetString m_certHash;
private readonly DerInteger m_certReqID;
private readonly PkiStatusInfo m_statusInfo;
private readonly AlgorithmIdentifier m_hashAlg;
private CertStatus(Asn1Sequence seq)
{
m_certHash = Asn1OctetString.GetInstance(seq[0]);
m_certReqID = DerInteger.GetInstance(seq[1]);
if (seq.Count > 2)
{
for (int t = 2; t < seq.Count; t++)
{
Asn1Object p = seq[t].ToAsn1Object();
if (p is Asn1Sequence s)
{
m_statusInfo = PkiStatusInfo.GetInstance(s);
}
if (p is Asn1TaggedObject dto)
{
if (!dto.HasContextTag(0))
throw new ArgumentException("unknown tag " + Asn1Utilities.GetTagText(dto));
m_hashAlg = AlgorithmIdentifier.GetInstance(dto, true);
}
}
}
}
public CertStatus(byte[] certHash, BigInteger certReqID)
{
m_certHash = new DerOctetString(certHash);
m_certReqID = new DerInteger(certReqID);
m_statusInfo = null;
m_hashAlg = null;
}
public CertStatus(byte[] certHash, BigInteger certReqID, PkiStatusInfo statusInfo)
{
m_certHash = new DerOctetString(certHash);
m_certReqID = new DerInteger(certReqID);
m_statusInfo = statusInfo;
m_hashAlg = null;
}
public CertStatus(byte[] certHash, BigInteger certReqID, PkiStatusInfo statusInfo, AlgorithmIdentifier hashAlg)
{
m_certHash = new DerOctetString(certHash);
m_certReqID = new DerInteger(certReqID);
m_statusInfo = statusInfo;
m_hashAlg = hashAlg;
}
public virtual Asn1OctetString CertHash => m_certHash;
public virtual DerInteger CertReqID => m_certReqID;
public virtual PkiStatusInfo StatusInfo => m_statusInfo;
public virtual AlgorithmIdentifier HashAlg => m_hashAlg;
/**
* <pre>
*
* CertStatus ::= SEQUENCE {
* certHash OCTET STRING,
* certReqId INTEGER,
* statusInfo PKIStatusInfo OPTIONAL,
* hashAlg [0] AlgorithmIdentifier{DIGEST-ALGORITHM, {...}} OPTIONAL
* }
*
* </pre>
*
* @return a basic ASN.1 object representation.
*/
public override Asn1Object ToAsn1Object()
{
Asn1EncodableVector v = new Asn1EncodableVector(4);
v.Add(m_certHash, m_certReqID);
v.AddOptional(m_statusInfo);
v.AddOptionalTagged(true, 0, m_hashAlg);
return new DerSequence(v);
}
}
}
|