mirrored from https://www.bouncycastle.org/repositories/bc-csharp
-
Notifications
You must be signed in to change notification settings - Fork 602
Expand file tree
/
Copy pathRespID.cs
More file actions
52 lines (42 loc) · 1.44 KB
/
Copy pathRespID.cs
File metadata and controls
52 lines (42 loc) · 1.44 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
using System;
using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.Ocsp;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.X509;
namespace Org.BouncyCastle.Ocsp
{
/// <summary>Carrier for a ResponderID.</summary>
public class RespID
: IEquatable<RespID>
{
private readonly ResponderID m_id;
public RespID(ResponderID id)
{
m_id = id ?? throw new ArgumentNullException(nameof(id));
}
public RespID(X509Name name)
{
m_id = new ResponderID(name);
}
public RespID(AsymmetricKeyParameter publicKey)
{
try
{
SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(publicKey);
byte[] key = info.PublicKey.GetBytes();
byte[] keyHash = DigestUtilities.CalculateDigest("SHA1", key);
m_id = new ResponderID(new DerOctetString(keyHash));
}
catch (Exception e)
{
throw new OcspException("problem creating ID", e);
}
}
public ResponderID ToAsn1Object() => m_id;
public bool Equals(RespID other) => this == other || m_id.Equals(other?.m_id);
public override bool Equals(object obj) => Equals(obj as RespID);
public override int GetHashCode() => m_id.GetHashCode();
}
}