Admissions.cs 4.9 KB

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