blob: a199282791a50ceef535042eb1de7bb142175c4f (
plain)
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
package org.bouncycastle.asn1.x509;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1Object;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.ASN1SequenceParser;
import org.bouncycastle.asn1.ASN1TaggedObject;
import org.bouncycastle.asn1.DERNull;
import org.bouncycastle.asn1.DERObjectIdentifier;
import org.bouncycastle.asn1.DERSequence;
public class AlgorithmIdentifier
extends ASN1Object
{
private ASN1ObjectIdentifier objectId;
private ASN1Encodable parameters;
private boolean parametersDefined = false;
public static AlgorithmIdentifier getInstance(
ASN1TaggedObject obj,
boolean explicit)
{
return getInstance(ASN1Sequence.getInstance(obj, explicit));
}
public static AlgorithmIdentifier getInstance(
Object obj)
{
if (obj== null || obj instanceof AlgorithmIdentifier)
{
return (AlgorithmIdentifier)obj;
}
// TODO: delete
if (obj instanceof ASN1ObjectIdentifier)
{
return new AlgorithmIdentifier((ASN1ObjectIdentifier)obj);
}
// TODO: delete
if (obj instanceof String)
{
return new AlgorithmIdentifier((String)obj);
}
return new AlgorithmIdentifier(ASN1Sequence.getInstance(obj));
}
public AlgorithmIdentifier(
ASN1ObjectIdentifier objectId)
{
this.objectId = objectId;
}
/**
* @deprecated use ASN1ObjectIdentifier
* @param objectId
*/
public AlgorithmIdentifier(
String objectId)
{
this.objectId = new ASN1ObjectIdentifier(objectId);
}
/**
* @deprecated use ASN1ObjectIdentifier
* @param objectId
*/
public AlgorithmIdentifier(
DERObjectIdentifier objectId)
{
this.objectId = new ASN1ObjectIdentifier(objectId.getId());
}
/**
* @deprecated use ASN1ObjectIdentifier
* @param objectId
* @param parameters
*/
public AlgorithmIdentifier(
DERObjectIdentifier objectId,
ASN1Encodable parameters)
{
parametersDefined = true;
this.objectId = new ASN1ObjectIdentifier(objectId.getId());
this.parameters = parameters;
}
public AlgorithmIdentifier(
ASN1ObjectIdentifier objectId,
ASN1Encodable parameters)
{
parametersDefined = true;
this.objectId = objectId;
this.parameters = parameters;
}
/**
* @deprecated use AlgorithmIdentifier.getInstance()
* @param seq
*/
public AlgorithmIdentifier(
ASN1Sequence seq)
{
if (seq.size() < 1 || seq.size() > 2)
{
throw new IllegalArgumentException("Bad sequence size: "
+ seq.size());
}
objectId = ASN1ObjectIdentifier.getInstance(seq.getObjectAt(0));
if (seq.size() == 2)
{
parametersDefined = true;
parameters = seq.getObjectAt(1);
}
else
{
parameters = null;
}
}
public ASN1ObjectIdentifier getAlgorithm()
{
return new ASN1ObjectIdentifier(objectId.getId());
}
/**
* @deprecated use getAlgorithm
* @return
*/
public ASN1ObjectIdentifier getObjectId()
{
return objectId;
}
public ASN1Encodable getParameters()
{
return parameters;
}
/**
* Produce an object suitable for an ASN1OutputStream.
* <pre>
* AlgorithmIdentifier ::= SEQUENCE {
* algorithm OBJECT IDENTIFIER,
* parameters ANY DEFINED BY algorithm OPTIONAL }
* </pre>
*/
public ASN1Primitive toASN1Primitive()
{
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(objectId);
if (parametersDefined)
{
if (parameters != null)
{
v.add(parameters);
}
else
{
v.add(DERNull.INSTANCE);
}
}
return new DERSequence(v);
}
}
|