RevokedStatus.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1;
  5. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Ocsp;
  6. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  7. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Ocsp
  8. {
  9. /// <summary>Wrapper for the RevokedInfo object</summary>
  10. public class RevokedStatus
  11. : CertificateStatus
  12. {
  13. private readonly RevokedInfo m_revokedInfo;
  14. public RevokedStatus(RevokedInfo revokedInfo)
  15. {
  16. m_revokedInfo = revokedInfo;
  17. }
  18. public RevokedStatus(DateTime revocationDate)
  19. {
  20. m_revokedInfo = new RevokedInfo(new Asn1GeneralizedTime(revocationDate));
  21. }
  22. public RevokedStatus(DateTime revocationDate, int reason)
  23. {
  24. m_revokedInfo = new RevokedInfo(new Asn1GeneralizedTime(revocationDate), new CrlReason(reason));
  25. }
  26. public DateTime RevocationTime
  27. {
  28. get { return m_revokedInfo.RevocationTime.ToDateTime(); }
  29. }
  30. public bool HasRevocationReason
  31. {
  32. get { return m_revokedInfo.RevocationReason != null; }
  33. }
  34. /// <summary>Return the revocation reason, if there is one.</summary>
  35. /// <remarks>This field is optional; test for it with <see cref="HasRevocationReason"/> first.</remarks>
  36. /// <returns>The revocation reason, if available.</returns>
  37. /// <exception cref="InvalidOperationException">If no revocation reason is available.</exception>
  38. public int RevocationReason
  39. {
  40. get
  41. {
  42. if (m_revokedInfo.RevocationReason == null)
  43. throw new InvalidOperationException("attempt to get a reason where none is available");
  44. return m_revokedInfo.RevocationReason.IntValueExact;
  45. }
  46. }
  47. }
  48. }
  49. #pragma warning restore
  50. #endif