AlgorithmIdentifier.cs
2.79 KB
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
using System;
namespace Org.BouncyCastle.Asn1.X509
{
public class AlgorithmIdentifier
: Asn1Encodable
{
private readonly DerObjectIdentifier algorithm;
private readonly Asn1Encodable parameters;
public static AlgorithmIdentifier GetInstance(
Asn1TaggedObject obj,
bool explicitly)
{
return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
}
public static AlgorithmIdentifier GetInstance(
object obj)
{
if (obj == null)
return null;
if (obj is AlgorithmIdentifier)
return (AlgorithmIdentifier)obj;
return new AlgorithmIdentifier(Asn1Sequence.GetInstance(obj));
}
public AlgorithmIdentifier(
DerObjectIdentifier algorithm)
{
this.algorithm = algorithm;
}
[Obsolete("Use version taking a DerObjectIdentifier")]
public AlgorithmIdentifier(
string algorithm)
{
this.algorithm = new DerObjectIdentifier(algorithm);
}
public AlgorithmIdentifier(
DerObjectIdentifier algorithm,
Asn1Encodable parameters)
{
this.algorithm = algorithm;
this.parameters = parameters;
}
internal AlgorithmIdentifier(
Asn1Sequence seq)
{
if (seq.Count < 1 || seq.Count > 2)
throw new ArgumentException("Bad sequence size: " + seq.Count);
this.algorithm = DerObjectIdentifier.GetInstance(seq[0]);
this.parameters = seq.Count < 2 ? null : seq[1];
}
/// <summary>
/// Return the OID in the Algorithm entry of this identifier.
/// </summary>
public virtual DerObjectIdentifier Algorithm
{
get { return algorithm; }
}
[Obsolete("Use 'Algorithm' property instead")]
public virtual DerObjectIdentifier ObjectID
{
get { return algorithm; }
}
/// <summary>
/// Return the parameters structure in the Parameters entry of this identifier.
/// </summary>
public virtual Asn1Encodable Parameters
{
get { return parameters; }
}
/**
* Produce an object suitable for an Asn1OutputStream.
* <pre>
* AlgorithmIdentifier ::= Sequence {
* algorithm OBJECT IDENTIFIER,
* parameters ANY DEFINED BY algorithm OPTIONAL }
* </pre>
*/
public override Asn1Object ToAsn1Object()
{
Asn1EncodableVector v = new Asn1EncodableVector(algorithm);
v.AddOptional(parameters);
return new DerSequence(v);
}
}
}