CscaMasterList.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Icao
  6. {
  7. /**
  8. * The CscaMasterList object. This object can be wrapped in a
  9. * CMSSignedData to be published in LDAP.
  10. *
  11. * <pre>
  12. * CscaMasterList ::= SEQUENCE {
  13. * version CscaMasterListVersion,
  14. * certList SET OF Certificate }
  15. *
  16. * CscaMasterListVersion :: INTEGER {v0(0)}
  17. * </pre>
  18. */
  19. public class CscaMasterList
  20. : Asn1Encodable
  21. {
  22. private DerInteger version = new DerInteger(0);
  23. private X509CertificateStructure[] certList;
  24. public static CscaMasterList GetInstance(
  25. object obj)
  26. {
  27. if (obj is CscaMasterList)
  28. return (CscaMasterList)obj;
  29. if (obj != null)
  30. return new CscaMasterList(Asn1Sequence.GetInstance(obj));
  31. return null;
  32. }
  33. private CscaMasterList(
  34. Asn1Sequence seq)
  35. {
  36. if (seq == null || seq.Count == 0)
  37. throw new ArgumentException("null or empty sequence passed.");
  38. if (seq.Count != 2)
  39. throw new ArgumentException("Incorrect sequence size: " + seq.Count);
  40. this.version = DerInteger.GetInstance(seq[0]);
  41. Asn1Set certSet = Asn1Set.GetInstance(seq[1]);
  42. this.certList = new X509CertificateStructure[certSet.Count];
  43. for (int i = 0; i < certList.Length; i++)
  44. {
  45. certList[i] = X509CertificateStructure.GetInstance(certSet[i]);
  46. }
  47. }
  48. public CscaMasterList(
  49. X509CertificateStructure[] certStructs)
  50. {
  51. certList = CopyCertList(certStructs);
  52. }
  53. public virtual int Version
  54. {
  55. get { return version.IntValueExact; }
  56. }
  57. public X509CertificateStructure[] GetCertStructs()
  58. {
  59. return CopyCertList(certList);
  60. }
  61. private static X509CertificateStructure[] CopyCertList(X509CertificateStructure[] orig)
  62. {
  63. return (X509CertificateStructure[])orig.Clone();
  64. }
  65. public override Asn1Object ToAsn1Object()
  66. {
  67. return new DerSequence(version, new DerSet(certList));
  68. }
  69. }
  70. }
  71. #pragma warning restore
  72. #endif