summary refs log tree commit diff
path: root/crypto/src/ocsp/RevokedStatus.cs
blob: a37bdade990b356723b6025feae0639bb0630433 (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
using System;

using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.Ocsp;
using Org.BouncyCastle.Asn1.X509;

namespace Org.BouncyCastle.Ocsp
{
    /// <summary>Wrapper for the RevokedInfo object</summary>
    public class RevokedStatus
		: CertificateStatus
	{
		private readonly RevokedInfo m_revokedInfo;

		public RevokedStatus(RevokedInfo revokedInfo)
		{
			m_revokedInfo = revokedInfo;
		}

		public RevokedStatus(DateTime revocationDate)
		{
			m_revokedInfo = new RevokedInfo(new Asn1GeneralizedTime(revocationDate));
		}

        public RevokedStatus(DateTime revocationDate, int reason)
		{
			m_revokedInfo = new RevokedInfo(new Asn1GeneralizedTime(revocationDate), new CrlReason(reason));
		}

		public DateTime RevocationTime
		{
			get { return m_revokedInfo.RevocationTime.ToDateTime(); }
		}

		public bool HasRevocationReason
		{
			get { return m_revokedInfo.RevocationReason != null; }
		}

        /// <summary>Return the revocation reason, if there is one.</summary>
		/// <remarks>This field is optional; test for it with <see cref="HasRevocationReason"/> first.</remarks>
		/// <returns>The revocation reason, if available.</returns>
		/// <exception cref="InvalidOperationException">If no revocation reason is available.</exception>
        public int RevocationReason
		{
			get
			{
				if (m_revokedInfo.RevocationReason == null)
					throw new InvalidOperationException("attempt to get a reason where none is available");

                return m_revokedInfo.RevocationReason.IntValueExact;
			}
		}
	}
}