CrlListID.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.Utilities;
  6. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
  7. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Esf
  8. {
  9. /// <remarks>
  10. /// RFC 3126: 4.2.2 Complete Revocation Refs Attribute Definition
  11. /// <code>
  12. /// CRLListID ::= SEQUENCE
  13. /// {
  14. /// crls SEQUENCE OF CrlValidatedID
  15. /// }
  16. /// </code>
  17. /// </remarks>
  18. public class CrlListID
  19. : Asn1Encodable
  20. {
  21. private readonly Asn1Sequence crls;
  22. public static CrlListID GetInstance(
  23. object obj)
  24. {
  25. if (obj == null || obj is CrlListID)
  26. return (CrlListID) obj;
  27. if (obj is Asn1Sequence)
  28. return new CrlListID((Asn1Sequence) obj);
  29. throw new ArgumentException(
  30. "Unknown object in 'CrlListID' factory: "
  31. + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj),
  32. "obj");
  33. }
  34. private CrlListID(
  35. Asn1Sequence seq)
  36. {
  37. if (seq == null)
  38. throw new ArgumentNullException("seq");
  39. if (seq.Count != 1)
  40. throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
  41. this.crls = (Asn1Sequence) seq[0].ToAsn1Object();
  42. foreach (Asn1Encodable ae in this.crls)
  43. {
  44. CrlValidatedID.GetInstance(ae.ToAsn1Object());
  45. }
  46. }
  47. public CrlListID(
  48. params CrlValidatedID[] crls)
  49. {
  50. if (crls == null)
  51. throw new ArgumentNullException("crls");
  52. this.crls = new DerSequence(crls);
  53. }
  54. public CrlListID(
  55. IEnumerable crls)
  56. {
  57. if (crls == null)
  58. throw new ArgumentNullException("crls");
  59. if (!CollectionUtilities.CheckElementsAreOfType(crls, typeof(CrlValidatedID)))
  60. throw new ArgumentException("Must contain only 'CrlValidatedID' objects", "crls");
  61. this.crls = new DerSequence(
  62. Asn1EncodableVector.FromEnumerable(crls));
  63. }
  64. public CrlValidatedID[] GetCrls()
  65. {
  66. CrlValidatedID[] result = new CrlValidatedID[crls.Count];
  67. for (int i = 0; i < crls.Count; ++i)
  68. {
  69. result[i] = CrlValidatedID.GetInstance(crls[i].ToAsn1Object());
  70. }
  71. return result;
  72. }
  73. public override Asn1Object ToAsn1Object()
  74. {
  75. return new DerSequence(crls);
  76. }
  77. }
  78. }
  79. #pragma warning restore
  80. #endif