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 pathOCSPResp.cs
More file actions
92 lines (75 loc) · 2.39 KB
/
Copy pathOCSPResp.cs
File metadata and controls
92 lines (75 loc) · 2.39 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
using System;
using System.IO;
using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.Ocsp;
namespace Org.BouncyCastle.Ocsp
{
public class OcspResp
{
private static OcspResponse ParseOcspResponse(byte[] encoding)
{
try
{
return OcspResponse.GetInstance(encoding);
}
catch (Exception e)
{
throw new IOException("malformed response: " + e.Message, e);
}
}
private static OcspResponse ParseOcspResponse(Stream input)
{
try
{
return OcspResponse.GetInstance(Asn1Object.FromStream(input));
}
catch (Exception e)
{
throw new IOException("malformed response: " + e.Message, e);
}
}
private readonly OcspResponse m_ocspResponse;
public OcspResp(OcspResponse resp)
{
m_ocspResponse = resp;
}
public OcspResp(byte[] resp)
: this(ParseOcspResponse(resp))
{
}
public OcspResp(Stream inStr)
: this(ParseOcspResponse(inStr))
{
}
public int Status => m_ocspResponse.ResponseStatus.IntValueExact;
public object GetResponseObject()
{
ResponseBytes rb = m_ocspResponse.ResponseBytes;
if (rb == null)
return null;
if (OcspObjectIdentifiers.PkixOcspBasic.Equals(rb.ResponseType))
{
try
{
return new BasicOcspResp(BasicOcspResponse.GetInstance(rb.Response.GetOctets()));
}
catch (Exception e)
{
throw new OcspException("problem decoding object: " + e, e);
}
}
return rb.Response;
}
/// <summary>Return the ASN.1 encoded representation of this object.</summary>
public byte[] GetEncoded() => m_ocspResponse.GetEncoded();
public override bool Equals(object obj)
{
if (obj == this)
return true;
return obj is OcspResp that
&& m_ocspResponse.Equals(that.m_ocspResponse);
}
public override int GetHashCode() => m_ocspResponse.GetHashCode();
public OcspResponse ToAsn1Structure() => m_ocspResponse;
}
}