OcspIdentifier.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Ocsp;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Esf
  7. {
  8. /// <remarks>
  9. /// RFC 3126: 4.2.2 Complete Revocation Refs Attribute Definition
  10. /// <code>
  11. /// OcspIdentifier ::= SEQUENCE {
  12. /// ocspResponderID ResponderID,
  13. /// -- As in OCSP response data
  14. /// producedAt GeneralizedTime
  15. /// -- As in OCSP response data
  16. /// }
  17. /// </code>
  18. /// </remarks>
  19. public class OcspIdentifier
  20. : Asn1Encodable
  21. {
  22. private readonly ResponderID ocspResponderID;
  23. private readonly DerGeneralizedTime producedAt;
  24. public static OcspIdentifier GetInstance(
  25. object obj)
  26. {
  27. if (obj == null || obj is OcspIdentifier)
  28. return (OcspIdentifier) obj;
  29. if (obj is Asn1Sequence)
  30. return new OcspIdentifier((Asn1Sequence) obj);
  31. throw new ArgumentException(
  32. "Unknown object in 'OcspIdentifier' factory: "
  33. + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj),
  34. "obj");
  35. }
  36. private OcspIdentifier(
  37. Asn1Sequence seq)
  38. {
  39. if (seq == null)
  40. throw new ArgumentNullException("seq");
  41. if (seq.Count != 2)
  42. throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
  43. this.ocspResponderID = ResponderID.GetInstance(seq[0].ToAsn1Object());
  44. this.producedAt = (DerGeneralizedTime) seq[1].ToAsn1Object();
  45. }
  46. public OcspIdentifier(
  47. ResponderID ocspResponderID,
  48. DateTime producedAt)
  49. {
  50. if (ocspResponderID == null)
  51. throw new ArgumentNullException();
  52. this.ocspResponderID = ocspResponderID;
  53. this.producedAt = new DerGeneralizedTime(producedAt);
  54. }
  55. public ResponderID OcspResponderID
  56. {
  57. get { return ocspResponderID; }
  58. }
  59. public DateTime ProducedAt
  60. {
  61. get { return producedAt.ToDateTime(); }
  62. }
  63. public override Asn1Object ToAsn1Object()
  64. {
  65. return new DerSequence(ocspResponderID, producedAt);
  66. }
  67. }
  68. }
  69. #pragma warning restore
  70. #endif