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