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 pathOCSPRespGenerator.cs
More file actions
47 lines (40 loc) · 1.68 KB
/
Copy pathOCSPRespGenerator.cs
File metadata and controls
47 lines (40 loc) · 1.68 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
using System;
using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.Ocsp;
namespace Org.BouncyCastle.Ocsp
{
/// <summmary>Base generator for an OCSP response.</summmary>
/// <remarks>
/// At the moment this only supports the generation of responses containing BasicOCSP responses.
/// </remarks>
public class OCSPRespGenerator
{
public const int Successful = 0; // Response has valid confirmations
public const int MalformedRequest = 1; // Illegal confirmation request
public const int InternalError = 2; // Internal error in issuer
public const int TryLater = 3; // Try again later
// (4) is not used
public const int SigRequired = 5; // Must sign the request
public const int Unauthorized = 6; // Request unauthorized
public OcspResp Generate(int status, object response)
{
if (response == null)
return new OcspResp(new OcspResponse(new OcspResponseStatus(status), null));
if (response is BasicOcspResp basicOcspResp)
{
Asn1OctetString octs;
try
{
octs = new DerOctetString(basicOcspResp.GetEncoded());
}
catch (Exception e)
{
throw new OcspException("can't encode object.", e);
}
var responseBytes = new ResponseBytes(OcspObjectIdentifiers.PkixOcspBasic, octs);
return new OcspResp(new OcspResponse(new OcspResponseStatus(status), responseBytes));
}
throw new OcspException("unknown response object");
}
}
}