blob: 78fda76d1247143040a636d933619b4f0c553d92 (
plain) (
blame)
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
|
using System;
using System.Collections.Generic;
using Org.BouncyCastle.Asn1.X509;
namespace Org.BouncyCastle.Asn1.Esf
{
/// <remarks>
/// <code>
/// OtherSigningCertificate ::= SEQUENCE {
/// certs SEQUENCE OF OtherCertID,
/// policies SEQUENCE OF PolicyInformation OPTIONAL
/// }
/// </code>
/// </remarks>
public class OtherSigningCertificate
: Asn1Encodable
{
public static OtherSigningCertificate GetInstance(object obj)
{
if (obj == null)
return null;
if (obj is OtherSigningCertificate otherSigningCertificate)
return otherSigningCertificate;
return new OtherSigningCertificate(Asn1Sequence.GetInstance(obj));
}
public static OtherSigningCertificate GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
{
return new OtherSigningCertificate(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
}
private readonly Asn1Sequence m_certs;
private readonly Asn1Sequence m_policies;
private OtherSigningCertificate(Asn1Sequence seq)
{
int count = seq.Count;
if (count < 1 || count > 2)
throw new ArgumentException("Bad sequence size: " + count, nameof(seq));
m_certs = Asn1Sequence.GetInstance(seq[0]);
if (count > 1)
{
m_policies = Asn1Sequence.GetInstance(seq[1]);
}
}
public OtherSigningCertificate(params OtherCertID[] certs)
: this(certs, null)
{
}
public OtherSigningCertificate(OtherCertID[] certs, params PolicyInformation[] policies)
{
if (certs == null)
throw new ArgumentNullException(nameof(certs));
m_certs = DerSequence.FromElements(certs);
if (policies != null)
{
m_policies = DerSequence.FromElements(policies);
}
}
public OtherSigningCertificate(IEnumerable<OtherCertID> certs)
: this(certs, null)
{
}
public OtherSigningCertificate(IEnumerable<OtherCertID> certs, IEnumerable<PolicyInformation> policies)
{
if (certs == null)
throw new ArgumentNullException(nameof(certs));
m_certs = DerSequence.FromVector(Asn1EncodableVector.FromEnumerable(certs));
if (policies != null)
{
m_policies = DerSequence.FromVector(Asn1EncodableVector.FromEnumerable(policies));
}
}
public OtherCertID[] GetCerts() => m_certs.MapElements(OtherCertID.GetInstance);
public PolicyInformation[] GetPolicies() => m_policies?.MapElements(PolicyInformation.GetInstance);
public override Asn1Object ToAsn1Object()
{
Asn1EncodableVector v = new Asn1EncodableVector(2);
v.Add(m_certs);
v.AddOptional(m_policies);
return new DerSequence(v);
}
}
}
|