CompleteRevocationRefs.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. /// CompleteRevocationRefs ::= SEQUENCE OF CrlOcspRef
  13. /// </code>
  14. /// </remarks>
  15. public class CompleteRevocationRefs
  16. : Asn1Encodable
  17. {
  18. private readonly Asn1Sequence crlOcspRefs;
  19. public static CompleteRevocationRefs GetInstance(
  20. object obj)
  21. {
  22. if (obj == null || obj is CompleteRevocationRefs)
  23. return (CompleteRevocationRefs) obj;
  24. if (obj is Asn1Sequence)
  25. return new CompleteRevocationRefs((Asn1Sequence) obj);
  26. throw new ArgumentException(
  27. "Unknown object in 'CompleteRevocationRefs' factory: "
  28. + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj),
  29. "obj");
  30. }
  31. private CompleteRevocationRefs(
  32. Asn1Sequence seq)
  33. {
  34. if (seq == null)
  35. throw new ArgumentNullException("seq");
  36. foreach (Asn1Encodable ae in seq)
  37. {
  38. CrlOcspRef.GetInstance(ae.ToAsn1Object());
  39. }
  40. this.crlOcspRefs = seq;
  41. }
  42. public CompleteRevocationRefs(
  43. params CrlOcspRef[] crlOcspRefs)
  44. {
  45. if (crlOcspRefs == null)
  46. throw new ArgumentNullException("crlOcspRefs");
  47. this.crlOcspRefs = new DerSequence(crlOcspRefs);
  48. }
  49. public CompleteRevocationRefs(
  50. IEnumerable crlOcspRefs)
  51. {
  52. if (crlOcspRefs == null)
  53. throw new ArgumentNullException("crlOcspRefs");
  54. if (!CollectionUtilities.CheckElementsAreOfType(crlOcspRefs, typeof(CrlOcspRef)))
  55. throw new ArgumentException("Must contain only 'CrlOcspRef' objects", "crlOcspRefs");
  56. this.crlOcspRefs = new DerSequence(
  57. Asn1EncodableVector.FromEnumerable(crlOcspRefs));
  58. }
  59. public CrlOcspRef[] GetCrlOcspRefs()
  60. {
  61. CrlOcspRef[] result = new CrlOcspRef[crlOcspRefs.Count];
  62. for (int i = 0; i < crlOcspRefs.Count; ++i)
  63. {
  64. result[i] = CrlOcspRef.GetInstance(crlOcspRefs[i].ToAsn1Object());
  65. }
  66. return result;
  67. }
  68. public override Asn1Object ToAsn1Object()
  69. {
  70. return crlOcspRefs;
  71. }
  72. }
  73. }
  74. #pragma warning restore
  75. #endif