OcspResponsesID.cs 2.2 KB

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