RevocationValues.cs 4.1 KB

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