AdmissionSyntax.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.IsisMtt.X509
  7. {
  8. /**
  9. * Attribute to indicate admissions to certain professions.
  10. * <p/>
  11. * <pre>
  12. * AdmissionSyntax ::= SEQUENCE
  13. * {
  14. * admissionAuthority GeneralName OPTIONAL,
  15. * contentsOfAdmissions SEQUENCE OF Admissions
  16. * }
  17. * <p/>
  18. * Admissions ::= SEQUENCE
  19. * {
  20. * admissionAuthority [0] EXPLICIT GeneralName OPTIONAL
  21. * namingAuthority [1] EXPLICIT NamingAuthority OPTIONAL
  22. * professionInfos SEQUENCE OF ProfessionInfo
  23. * }
  24. * <p/>
  25. * NamingAuthority ::= SEQUENCE
  26. * {
  27. * namingAuthorityId OBJECT IDENTIFIER OPTIONAL,
  28. * namingAuthorityUrl IA5String OPTIONAL,
  29. * namingAuthorityText DirectoryString(SIZE(1..128)) OPTIONAL
  30. * }
  31. * <p/>
  32. * ProfessionInfo ::= SEQUENCE
  33. * {
  34. * namingAuthority [0] EXPLICIT NamingAuthority OPTIONAL,
  35. * professionItems SEQUENCE OF DirectoryString (SIZE(1..128)),
  36. * professionOIDs SEQUENCE OF OBJECT IDENTIFIER OPTIONAL,
  37. * registrationNumber PrintableString(SIZE(1..128)) OPTIONAL,
  38. * addProfessionInfo OCTET STRING OPTIONAL
  39. * }
  40. * </pre>
  41. * <p/>
  42. * <p/>
  43. * ISIS-MTT PROFILE: The relatively complex structure of AdmissionSyntax
  44. * supports the following concepts and requirements:
  45. * <ul>
  46. * <li> External institutions (e.g. professional associations, chambers, unions,
  47. * administrative bodies, companies, etc.), which are responsible for granting
  48. * and verifying professional admissions, are indicated by means of the data
  49. * field admissionAuthority. An admission authority is indicated by a
  50. * GeneralName object. Here an X.501 directory name (distinguished name) can be
  51. * indicated in the field directoryName, a URL address can be indicated in the
  52. * field uniformResourceIdentifier, and an object identifier can be indicated in
  53. * the field registeredId.</li>
  54. * <li> The names of authorities which are responsible for the administration of
  55. * title registers are indicated in the data field namingAuthority. The name of
  56. * the authority can be identified by an object identifier in the field
  57. * namingAuthorityId, by means of a text string in the field
  58. * namingAuthorityText, by means of a URL address in the field
  59. * namingAuthorityUrl, or by a combination of them. For example, the text string
  60. * can contain the name of the authority, the country and the name of the title
  61. * register. The URL-option refers to a web page which contains lists with
  62. * officially registered professions (text and possibly OID) as well as
  63. * further information on these professions. Object identifiers for the
  64. * component namingAuthorityId are grouped under the OID-branch
  65. * id-isis-at-namingAuthorities and must be applied for.</li>
  66. * <li>See http://www.teletrust.de/anwend.asp?Id=30200&amp;Sprache=E_&amp;HomePG=0
  67. * for an application form and http://www.teletrust.de/links.asp?id=30220,11
  68. * for an overview of registered naming authorities.</li>
  69. * <li> By means of the data type ProfessionInfo certain professions,
  70. * specializations, disciplines, fields of activity, etc. are identified. A
  71. * profession is represented by one or more text strings, resp. profession OIDs
  72. * in the fields professionItems and professionOIDs and by a registration number
  73. * in the field registrationNumber. An indication in text form must always be
  74. * present, whereas the other indications are optional. The component
  75. * addProfessionInfo may contain additional applicationspecific information in
  76. * DER-encoded form.</li>
  77. * </ul>
  78. * <p/>
  79. * By means of different namingAuthority-OIDs or profession OIDs hierarchies of
  80. * professions, specializations, disciplines, fields of activity, etc. can be
  81. * expressed. The issuing admission authority should always be indicated (field
  82. * admissionAuthority), whenever a registration number is presented. Still,
  83. * information on admissions can be given without indicating an admission or a
  84. * naming authority by the exclusive use of the component professionItems. In
  85. * this case the certification authority is responsible for the verification of
  86. * the admission information.
  87. * <p/>
  88. * <p/>
  89. * <p/>
  90. * This attribute is single-valued. Still, several admissions can be captured in
  91. * the sequence structure of the component contentsOfAdmissions of
  92. * AdmissionSyntax or in the component professionInfos of Admissions. The
  93. * component admissionAuthority of AdmissionSyntax serves as default value for
  94. * the component admissionAuthority of Admissions. Within the latter component
  95. * the default value can be overwritten, in case that another authority is
  96. * responsible. The component namingAuthority of Admissions serves as a default
  97. * value for the component namingAuthority of ProfessionInfo. Within the latter
  98. * component the default value can be overwritten, in case that another naming
  99. * authority needs to be recorded.
  100. * <p/>
  101. * The length of the string objects is limited to 128 characters. It is
  102. * recommended to indicate a namingAuthorityURL in all issued attribute
  103. * certificates. If a namingAuthorityURL is indicated, the field professionItems
  104. * of ProfessionInfo should contain only registered titles. If the field
  105. * professionOIDs exists, it has to contain the OIDs of the professions listed
  106. * in professionItems in the same order. In general, the field professionInfos
  107. * should contain only one entry, unless the admissions that are to be listed
  108. * are logically connected (e.g. they have been issued under the same admission
  109. * number).
  110. *
  111. * @see BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.IsisMtt.X509.Admissions
  112. * @see BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.IsisMtt.X509.ProfessionInfo
  113. * @see BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.IsisMtt.X509.NamingAuthority
  114. */
  115. public class AdmissionSyntax
  116. : Asn1Encodable
  117. {
  118. private readonly GeneralName admissionAuthority;
  119. private readonly Asn1Sequence contentsOfAdmissions;
  120. public static AdmissionSyntax GetInstance(
  121. object obj)
  122. {
  123. if (obj == null || obj is AdmissionSyntax)
  124. {
  125. return (AdmissionSyntax)obj;
  126. }
  127. if (obj is Asn1Sequence)
  128. {
  129. return new AdmissionSyntax((Asn1Sequence)obj);
  130. }
  131. throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  132. }
  133. /**
  134. * Constructor from Asn1Sequence.
  135. * <p/>
  136. * The sequence is of type ProcurationSyntax:
  137. * <p/>
  138. * <pre>
  139. * AdmissionSyntax ::= SEQUENCE
  140. * {
  141. * admissionAuthority GeneralName OPTIONAL,
  142. * contentsOfAdmissions SEQUENCE OF Admissions
  143. * }
  144. * <p/>
  145. * Admissions ::= SEQUENCE
  146. * {
  147. * admissionAuthority [0] EXPLICIT GeneralName OPTIONAL
  148. * namingAuthority [1] EXPLICIT NamingAuthority OPTIONAL
  149. * professionInfos SEQUENCE OF ProfessionInfo
  150. * }
  151. * <p/>
  152. * NamingAuthority ::= SEQUENCE
  153. * {
  154. * namingAuthorityId OBJECT IDENTIFIER OPTIONAL,
  155. * namingAuthorityUrl IA5String OPTIONAL,
  156. * namingAuthorityText DirectoryString(SIZE(1..128)) OPTIONAL
  157. * }
  158. * <p/>
  159. * ProfessionInfo ::= SEQUENCE
  160. * {
  161. * namingAuthority [0] EXPLICIT NamingAuthority OPTIONAL,
  162. * professionItems SEQUENCE OF DirectoryString (SIZE(1..128)),
  163. * professionOIDs SEQUENCE OF OBJECT IDENTIFIER OPTIONAL,
  164. * registrationNumber PrintableString(SIZE(1..128)) OPTIONAL,
  165. * addProfessionInfo OCTET STRING OPTIONAL
  166. * }
  167. * </pre>
  168. *
  169. * @param seq The ASN.1 sequence.
  170. */
  171. private AdmissionSyntax(
  172. Asn1Sequence seq)
  173. {
  174. switch (seq.Count)
  175. {
  176. case 1:
  177. this.contentsOfAdmissions = DerSequence.GetInstance(seq[0]);
  178. break;
  179. case 2:
  180. admissionAuthority = GeneralName.GetInstance(seq[0]);
  181. contentsOfAdmissions = DerSequence.GetInstance(seq[1]);
  182. break;
  183. default:
  184. throw new ArgumentException("Bad sequence size: " + seq.Count);
  185. }
  186. }
  187. /**
  188. * Constructor from given details.
  189. *
  190. * @param admissionAuthority The admission authority.
  191. * @param contentsOfAdmissions The admissions.
  192. */
  193. public AdmissionSyntax(
  194. GeneralName admissionAuthority,
  195. Asn1Sequence contentsOfAdmissions)
  196. {
  197. this.admissionAuthority = admissionAuthority;
  198. this.contentsOfAdmissions = contentsOfAdmissions;
  199. }
  200. /**
  201. * Produce an object suitable for an Asn1OutputStream.
  202. * <p/>
  203. * Returns:
  204. * <p/>
  205. * <pre>
  206. * AdmissionSyntax ::= SEQUENCE
  207. * {
  208. * admissionAuthority GeneralName OPTIONAL,
  209. * contentsOfAdmissions SEQUENCE OF Admissions
  210. * }
  211. * <p/>
  212. * Admissions ::= SEQUENCE
  213. * {
  214. * admissionAuthority [0] EXPLICIT GeneralName OPTIONAL
  215. * namingAuthority [1] EXPLICIT NamingAuthority OPTIONAL
  216. * professionInfos SEQUENCE OF ProfessionInfo
  217. * }
  218. * <p/>
  219. * NamingAuthority ::= SEQUENCE
  220. * {
  221. * namingAuthorityId OBJECT IDENTIFIER OPTIONAL,
  222. * namingAuthorityUrl IA5String OPTIONAL,
  223. * namingAuthorityText DirectoryString(SIZE(1..128)) OPTIONAL
  224. * }
  225. * <p/>
  226. * ProfessionInfo ::= SEQUENCE
  227. * {
  228. * namingAuthority [0] EXPLICIT NamingAuthority OPTIONAL,
  229. * professionItems SEQUENCE OF DirectoryString (SIZE(1..128)),
  230. * professionOIDs SEQUENCE OF OBJECT IDENTIFIER OPTIONAL,
  231. * registrationNumber PrintableString(SIZE(1..128)) OPTIONAL,
  232. * addProfessionInfo OCTET STRING OPTIONAL
  233. * }
  234. * </pre>
  235. *
  236. * @return an Asn1Object
  237. */
  238. public override Asn1Object ToAsn1Object()
  239. {
  240. Asn1EncodableVector v = new Asn1EncodableVector();
  241. v.AddOptional(admissionAuthority);
  242. v.Add(contentsOfAdmissions);
  243. return new DerSequence(v);
  244. }
  245. /**
  246. * @return Returns the admissionAuthority if present, null otherwise.
  247. */
  248. public virtual GeneralName AdmissionAuthority
  249. {
  250. get { return admissionAuthority; }
  251. }
  252. /**
  253. * @return Returns the contentsOfAdmissions.
  254. */
  255. public virtual Admissions[] GetContentsOfAdmissions()
  256. {
  257. Admissions[] result = new Admissions[contentsOfAdmissions.Count];
  258. for (int i = 0; i < contentsOfAdmissions.Count; ++i)
  259. {
  260. result[i] = Admissions.GetInstance(contentsOfAdmissions[i]);
  261. }
  262. return result;
  263. }
  264. }
  265. }
  266. #pragma warning restore
  267. #endif