Admissions.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  5. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.IsisMtt.X509
  7. {
  8. /**
  9. * An Admissions structure.
  10. * <p/>
  11. * <pre>
  12. * Admissions ::= SEQUENCE
  13. * {
  14. * admissionAuthority [0] EXPLICIT GeneralName OPTIONAL
  15. * namingAuthority [1] EXPLICIT NamingAuthority OPTIONAL
  16. * professionInfos SEQUENCE OF ProfessionInfo
  17. * }
  18. * <p/>
  19. * </pre>
  20. *
  21. * @see Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.IsisMtt.X509.AdmissionSyntax
  22. * @see Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.IsisMtt.X509.ProfessionInfo
  23. * @see Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.IsisMtt.X509.NamingAuthority
  24. */
  25. public class Admissions
  26. : Asn1Encodable
  27. {
  28. private readonly GeneralName admissionAuthority;
  29. private readonly NamingAuthority namingAuthority;
  30. private readonly Asn1Sequence professionInfos;
  31. public static Admissions GetInstance(object obj)
  32. {
  33. if (obj == null || obj is Admissions)
  34. return (Admissions)obj;
  35. if (obj is Asn1Sequence seq)
  36. return new Admissions(seq);
  37. throw new ArgumentException("unknown object in factory: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  38. }
  39. /**
  40. * Constructor from Asn1Sequence.
  41. * <p/>
  42. * The sequence is of type ProcurationSyntax:
  43. * <p/>
  44. * <pre>
  45. * Admissions ::= SEQUENCE
  46. * {
  47. * admissionAuthority [0] EXPLICIT GeneralName OPTIONAL
  48. * namingAuthority [1] EXPLICIT NamingAuthority OPTIONAL
  49. * professionInfos SEQUENCE OF ProfessionInfo
  50. * }
  51. * </pre>
  52. *
  53. * @param seq The ASN.1 sequence.
  54. */
  55. private Admissions(Asn1Sequence seq)
  56. {
  57. if (seq.Count > 3)
  58. throw new ArgumentException("Bad sequence size: " + seq.Count);
  59. var e = seq.GetEnumerator();
  60. e.MoveNext();
  61. Asn1Encodable o = e.Current;
  62. if (o is Asn1TaggedObject tagged1)
  63. {
  64. switch (tagged1.TagNo)
  65. {
  66. case 0:
  67. admissionAuthority = GeneralName.GetInstance((Asn1TaggedObject)o, true);
  68. break;
  69. case 1:
  70. namingAuthority = NamingAuthority.GetInstance((Asn1TaggedObject)o, true);
  71. break;
  72. default:
  73. throw new ArgumentException("Bad tag number: " + ((Asn1TaggedObject)o).TagNo);
  74. }
  75. e.MoveNext();
  76. o = e.Current;
  77. }
  78. if (o is Asn1TaggedObject tagged2)
  79. {
  80. switch (tagged2.TagNo)
  81. {
  82. case 1:
  83. namingAuthority = NamingAuthority.GetInstance((Asn1TaggedObject)o, true);
  84. break;
  85. default:
  86. throw new ArgumentException("Bad tag number: " + ((Asn1TaggedObject)o).TagNo);
  87. }
  88. e.MoveNext();
  89. o = e.Current;
  90. }
  91. professionInfos = Asn1Sequence.GetInstance(o);
  92. if (e.MoveNext())
  93. {
  94. throw new ArgumentException("Bad object encountered: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(e.Current));
  95. }
  96. }
  97. /**
  98. * Constructor from a given details.
  99. * <p/>
  100. * Parameter <code>professionInfos</code> is mandatory.
  101. *
  102. * @param admissionAuthority The admission authority.
  103. * @param namingAuthority The naming authority.
  104. * @param professionInfos The profession infos.
  105. */
  106. public Admissions(
  107. GeneralName admissionAuthority,
  108. NamingAuthority namingAuthority,
  109. ProfessionInfo[] professionInfos)
  110. {
  111. this.admissionAuthority = admissionAuthority;
  112. this.namingAuthority = namingAuthority;
  113. this.professionInfos = new DerSequence(professionInfos);
  114. }
  115. public virtual GeneralName AdmissionAuthority
  116. {
  117. get { return admissionAuthority; }
  118. }
  119. public virtual NamingAuthority NamingAuthority
  120. {
  121. get { return namingAuthority; }
  122. }
  123. public ProfessionInfo[] GetProfessionInfos()
  124. {
  125. ProfessionInfo[] infos = new ProfessionInfo[professionInfos.Count];
  126. int count = 0;
  127. foreach (Asn1Encodable ae in professionInfos)
  128. {
  129. infos[count++] = ProfessionInfo.GetInstance(ae);
  130. }
  131. return infos;
  132. }
  133. /**
  134. * Produce an object suitable for an Asn1OutputStream.
  135. * <p/>
  136. * Returns:
  137. * <p/>
  138. * <pre>
  139. * Admissions ::= SEQUENCE
  140. * {
  141. * admissionAuthority [0] EXPLICIT GeneralName OPTIONAL
  142. * namingAuthority [1] EXPLICIT NamingAuthority OPTIONAL
  143. * professionInfos SEQUENCE OF ProfessionInfo
  144. * }
  145. * <p/>
  146. * </pre>
  147. *
  148. * @return an Asn1Object
  149. */
  150. public override Asn1Object ToAsn1Object()
  151. {
  152. Asn1EncodableVector v = new Asn1EncodableVector();
  153. v.AddOptionalTagged(true, 0, admissionAuthority);
  154. v.AddOptionalTagged(true, 1, namingAuthority);
  155. v.Add(professionInfos);
  156. return new DerSequence(v);
  157. }
  158. }
  159. }
  160. #pragma warning restore
  161. #endif