CertificateValues.cs 2.4 KB

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