CrlOcspRef.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. /// CrlOcspRef ::= SEQUENCE {
  11. /// crlids [0] CRLListID OPTIONAL,
  12. /// ocspids [1] OcspListID OPTIONAL,
  13. /// otherRev [2] OtherRevRefs OPTIONAL
  14. /// }
  15. /// </code>
  16. /// </remarks>
  17. public class CrlOcspRef
  18. : Asn1Encodable
  19. {
  20. private readonly CrlListID crlids;
  21. private readonly OcspListID ocspids;
  22. private readonly OtherRevRefs otherRev;
  23. public static CrlOcspRef GetInstance(
  24. object obj)
  25. {
  26. if (obj == null || obj is CrlOcspRef)
  27. return (CrlOcspRef) obj;
  28. if (obj is Asn1Sequence)
  29. return new CrlOcspRef((Asn1Sequence) obj);
  30. throw new ArgumentException(
  31. "Unknown object in 'CrlOcspRef' factory: "
  32. + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj),
  33. "obj");
  34. }
  35. private CrlOcspRef(
  36. Asn1Sequence seq)
  37. {
  38. if (seq == null)
  39. throw new ArgumentNullException("seq");
  40. foreach (Asn1TaggedObject taggedObj in seq)
  41. {
  42. Asn1Object asn1Obj = taggedObj.GetObject();
  43. switch (taggedObj.TagNo)
  44. {
  45. case 0:
  46. this.crlids = CrlListID.GetInstance(asn1Obj);
  47. break;
  48. case 1:
  49. this.ocspids = OcspListID.GetInstance(asn1Obj);
  50. break;
  51. case 2:
  52. this.otherRev = OtherRevRefs.GetInstance(asn1Obj);
  53. break;
  54. default:
  55. throw new ArgumentException("Illegal tag in CrlOcspRef", "seq");
  56. }
  57. }
  58. }
  59. public CrlOcspRef(
  60. CrlListID crlids,
  61. OcspListID ocspids,
  62. OtherRevRefs otherRev)
  63. {
  64. this.crlids = crlids;
  65. this.ocspids = ocspids;
  66. this.otherRev = otherRev;
  67. }
  68. public CrlListID CrlIDs
  69. {
  70. get { return crlids; }
  71. }
  72. public OcspListID OcspIDs
  73. {
  74. get { return ocspids; }
  75. }
  76. public OtherRevRefs OtherRev
  77. {
  78. get { return otherRev; }
  79. }
  80. public override Asn1Object ToAsn1Object()
  81. {
  82. Asn1EncodableVector v = new Asn1EncodableVector();
  83. if (crlids != null)
  84. {
  85. v.Add(new DerTaggedObject(true, 0, crlids.ToAsn1Object()));
  86. }
  87. if (ocspids != null)
  88. {
  89. v.Add(new DerTaggedObject(true, 1, ocspids.ToAsn1Object()));
  90. }
  91. if (otherRev != null)
  92. {
  93. v.Add(new DerTaggedObject(true, 2, otherRev.ToAsn1Object()));
  94. }
  95. return new DerSequence(v);
  96. }
  97. }
  98. }
  99. #pragma warning restore
  100. #endif