blob: cda4aaa37da21dba4e5757ff9757437d52195f7e (
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
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
|
using System;
using System.Collections;
using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Math;
namespace Org.BouncyCastle.Asn1.Icao
{
/**
* The LDSSecurityObject object (V1.8).
* <pre>
* LDSSecurityObject ::= SEQUENCE {
* version LDSSecurityObjectVersion,
* hashAlgorithm DigestAlgorithmIdentifier,
* dataGroupHashValues SEQUENCE SIZE (2..ub-DataGroups) OF DataHashGroup,
* ldsVersionInfo LDSVersionInfo OPTIONAL
* -- if present, version MUST be v1 }
*
* DigestAlgorithmIdentifier ::= AlgorithmIdentifier,
*
* LDSSecurityObjectVersion :: INTEGER {V0(0)}
* </pre>
*/
public class LdsSecurityObject
: Asn1Encodable
{
public const int UBDataGroups = 16;
private DerInteger version = new DerInteger(0);
private AlgorithmIdentifier digestAlgorithmIdentifier;
private DataGroupHash[] datagroupHash;
private LdsVersionInfo versionInfo;
public static LdsSecurityObject GetInstance(
object obj)
{
if (obj is LdsSecurityObject)
return (LdsSecurityObject)obj;
if (obj != null)
return new LdsSecurityObject(Asn1Sequence.GetInstance(obj));
return null;
}
private LdsSecurityObject(
Asn1Sequence seq)
{
if (seq == null || seq.Count == 0)
throw new ArgumentException("null or empty sequence passed.");
IEnumerator e = seq.GetEnumerator();
// version
e.MoveNext();
version = DerInteger.GetInstance(e.Current);
// digestAlgorithmIdentifier
e.MoveNext();
digestAlgorithmIdentifier = AlgorithmIdentifier.GetInstance(e.Current);
e.MoveNext();
Asn1Sequence datagroupHashSeq = Asn1Sequence.GetInstance(e.Current);
if (version.Value.Equals(BigInteger.One))
{
e.MoveNext();
versionInfo = LdsVersionInfo.GetInstance(e.Current);
}
CheckDatagroupHashSeqSize(datagroupHashSeq.Count);
datagroupHash = new DataGroupHash[datagroupHashSeq.Count];
for (int i= 0; i< datagroupHashSeq.Count; i++)
{
datagroupHash[i] = DataGroupHash.GetInstance(datagroupHashSeq[i]);
}
}
public LdsSecurityObject(
AlgorithmIdentifier digestAlgorithmIdentifier,
DataGroupHash[] datagroupHash)
{
this.version = new DerInteger(0);
this.digestAlgorithmIdentifier = digestAlgorithmIdentifier;
this.datagroupHash = datagroupHash;
CheckDatagroupHashSeqSize(datagroupHash.Length);
}
public LdsSecurityObject(
AlgorithmIdentifier digestAlgorithmIdentifier,
DataGroupHash[] datagroupHash,
LdsVersionInfo versionInfo)
{
this.version = new DerInteger(1);
this.digestAlgorithmIdentifier = digestAlgorithmIdentifier;
this.datagroupHash = datagroupHash;
this.versionInfo = versionInfo;
CheckDatagroupHashSeqSize(datagroupHash.Length);
}
private void CheckDatagroupHashSeqSize(int size)
{
if (size < 2 || size > UBDataGroups)
throw new ArgumentException("wrong size in DataGroupHashValues : not in (2.."+ UBDataGroups +")");
}
public BigInteger Version
{
get { return version.Value; }
}
public AlgorithmIdentifier DigestAlgorithmIdentifier
{
get { return digestAlgorithmIdentifier; }
}
public DataGroupHash[] GetDatagroupHash()
{
return datagroupHash;
}
public LdsVersionInfo VersionInfo
{
get { return versionInfo; }
}
public override Asn1Object ToAsn1Object()
{
DerSequence hashSeq = new DerSequence(datagroupHash);
Asn1EncodableVector v = new Asn1EncodableVector(version, digestAlgorithmIdentifier, hashSeq);
v.AddOptional(versionInfo);
return new DerSequence(v);
}
}
}
|