RevocationValues.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Collections.Generic;
  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.Asn1.Esf
  8. {
  9. /// <remarks>
  10. /// RFC 5126: 6.3.4. revocation-values Attribute Definition
  11. /// <code>
  12. /// RevocationValues ::= SEQUENCE {
  13. /// crlVals [0] SEQUENCE OF CertificateList OPTIONAL,
  14. /// ocspVals [1] SEQUENCE OF BasicOCSPResponse OPTIONAL,
  15. /// otherRevVals [2] OtherRevVals OPTIONAL
  16. /// }
  17. /// </code>
  18. /// </remarks>
  19. public class RevocationValues
  20. : Asn1Encodable
  21. {
  22. private readonly Asn1Sequence crlVals;
  23. private readonly Asn1Sequence ocspVals;
  24. private readonly OtherRevVals otherRevVals;
  25. public static RevocationValues GetInstance(
  26. object obj)
  27. {
  28. if (obj == null || obj is RevocationValues)
  29. return (RevocationValues) obj;
  30. return new RevocationValues(Asn1Sequence.GetInstance(obj));
  31. }
  32. private RevocationValues(
  33. Asn1Sequence seq)
  34. {
  35. if (seq == null)
  36. throw new ArgumentNullException("seq");
  37. if (seq.Count > 3)
  38. throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
  39. foreach (Asn1TaggedObject taggedObj in seq)
  40. {
  41. Asn1Object asn1Obj = taggedObj.GetObject();
  42. switch (taggedObj.TagNo)
  43. {
  44. case 0:
  45. Asn1Sequence crlValsSeq = (Asn1Sequence) asn1Obj;
  46. foreach (Asn1Encodable ae in crlValsSeq)
  47. {
  48. CertificateList.GetInstance(ae.ToAsn1Object());
  49. }
  50. this.crlVals = crlValsSeq;
  51. break;
  52. case 1:
  53. Asn1Sequence ocspValsSeq = (Asn1Sequence) asn1Obj;
  54. foreach (Asn1Encodable ae in ocspValsSeq)
  55. {
  56. BasicOcspResponse.GetInstance(ae.ToAsn1Object());
  57. }
  58. this.ocspVals = ocspValsSeq;
  59. break;
  60. case 2:
  61. this.otherRevVals = OtherRevVals.GetInstance(asn1Obj);
  62. break;
  63. default:
  64. throw new ArgumentException("Illegal tag in RevocationValues", "seq");
  65. }
  66. }
  67. }
  68. public RevocationValues(
  69. CertificateList[] crlVals,
  70. BasicOcspResponse[] ocspVals,
  71. OtherRevVals otherRevVals)
  72. {
  73. if (crlVals != null)
  74. {
  75. this.crlVals = new DerSequence(crlVals);
  76. }
  77. if (ocspVals != null)
  78. {
  79. this.ocspVals = new DerSequence(ocspVals);
  80. }
  81. this.otherRevVals = otherRevVals;
  82. }
  83. public RevocationValues(
  84. IEnumerable<CertificateList> crlVals,
  85. IEnumerable<BasicOcspResponse> ocspVals,
  86. OtherRevVals otherRevVals)
  87. {
  88. if (crlVals != null)
  89. {
  90. this.crlVals = new DerSequence(
  91. Asn1EncodableVector.FromEnumerable(crlVals));
  92. }
  93. if (ocspVals != null)
  94. {
  95. this.ocspVals = new DerSequence(
  96. Asn1EncodableVector.FromEnumerable(ocspVals));
  97. }
  98. this.otherRevVals = otherRevVals;
  99. }
  100. public CertificateList[] GetCrlVals()
  101. {
  102. CertificateList[] result = new CertificateList[crlVals.Count];
  103. for (int i = 0; i < crlVals.Count; ++i)
  104. {
  105. result[i] = CertificateList.GetInstance(crlVals[i].ToAsn1Object());
  106. }
  107. return result;
  108. }
  109. public BasicOcspResponse[] GetOcspVals()
  110. {
  111. BasicOcspResponse[] result = new BasicOcspResponse[ocspVals.Count];
  112. for (int i = 0; i < ocspVals.Count; ++i)
  113. {
  114. result[i] = BasicOcspResponse.GetInstance(ocspVals[i].ToAsn1Object());
  115. }
  116. return result;
  117. }
  118. public OtherRevVals OtherRevVals
  119. {
  120. get { return otherRevVals; }
  121. }
  122. public override Asn1Object ToAsn1Object()
  123. {
  124. Asn1EncodableVector v = new Asn1EncodableVector();
  125. v.AddOptionalTagged(true, 0, crlVals);
  126. v.AddOptionalTagged(true, 1, ocspVals);
  127. if (otherRevVals != null)
  128. {
  129. v.Add(new DerTaggedObject(true, 2, otherRevVals.ToAsn1Object()));
  130. }
  131. return new DerSequence(v);
  132. }
  133. }
  134. }
  135. #pragma warning restore
  136. #endif