blob: 2ee16247833de98f035fed836a0b33318670ac7b (
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
|
using System;
using Org.BouncyCastle.Asn1.Oiw;
using Org.BouncyCastle.Asn1.X509;
namespace Org.BouncyCastle.Asn1.Esf
{
/// <remarks>
/// <code>
/// OtherHash ::= CHOICE {
/// sha1Hash OtherHashValue, -- This contains a SHA-1 hash
/// otherHash OtherHashAlgAndValue
/// }
///
/// OtherHashValue ::= OCTET STRING
/// </code>
/// </remarks>
public class OtherHash
: Asn1Encodable, IAsn1Choice
{
private readonly Asn1OctetString sha1Hash;
private readonly OtherHashAlgAndValue otherHash;
public static OtherHash GetInstance(
object obj)
{
if (obj == null || obj is OtherHash)
return (OtherHash) obj;
if (obj is Asn1OctetString)
return new OtherHash((Asn1OctetString) obj);
return new OtherHash(
OtherHashAlgAndValue.GetInstance(obj));
}
public OtherHash(
byte[] sha1Hash)
{
if (sha1Hash == null)
throw new ArgumentNullException("sha1Hash");
this.sha1Hash = new DerOctetString(sha1Hash);
}
public OtherHash(
Asn1OctetString sha1Hash)
{
if (sha1Hash == null)
throw new ArgumentNullException("sha1Hash");
this.sha1Hash = sha1Hash;
}
public OtherHash(
OtherHashAlgAndValue otherHash)
{
if (otherHash == null)
throw new ArgumentNullException("otherHash");
this.otherHash = otherHash;
}
public AlgorithmIdentifier HashAlgorithm
{
get
{
return otherHash == null
? new AlgorithmIdentifier(OiwObjectIdentifiers.IdSha1)
: otherHash.HashAlgorithm;
}
}
public byte[] GetHashValue()
{
return otherHash == null
? sha1Hash.GetOctets()
: otherHash.GetHashValue();
}
public override Asn1Object ToAsn1Object()
{
return otherHash == null
? sha1Hash
: otherHash.ToAsn1Object();
}
}
}
|