NamingAuthority.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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.X500;
  6. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  7. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.IsisMtt.X509
  8. {
  9. /**
  10. * Names of authorities which are responsible for the administration of title
  11. * registers.
  12. *
  13. * <pre>
  14. * NamingAuthority ::= SEQUENCE
  15. * {
  16. * namingAuthorityID OBJECT IDENTIFIER OPTIONAL,
  17. * namingAuthorityUrl IA5String OPTIONAL,
  18. * namingAuthorityText DirectoryString(SIZE(1..128)) OPTIONAL
  19. * }
  20. * </pre>
  21. * @see BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.IsisMtt.X509.AdmissionSyntax
  22. *
  23. */
  24. public class NamingAuthority
  25. : Asn1Encodable
  26. {
  27. /**
  28. * Profession OIDs should always be defined under the OID branch of the
  29. * responsible naming authority. At the time of this writing, the work group
  30. * �Recht, Wirtschaft, Steuern� (�Law, Economy, Taxes�) is registered as the
  31. * first naming authority under the OID id-isismtt-at-namingAuthorities.
  32. */
  33. public static readonly DerObjectIdentifier IdIsisMttATNamingAuthoritiesRechtWirtschaftSteuern
  34. = new DerObjectIdentifier(IsisMttObjectIdentifiers.IdIsisMttATNamingAuthorities + ".1");
  35. private readonly DerObjectIdentifier namingAuthorityID;
  36. private readonly string namingAuthorityUrl;
  37. private readonly DirectoryString namingAuthorityText;
  38. public static NamingAuthority GetInstance(
  39. object obj)
  40. {
  41. if (obj == null || obj is NamingAuthority)
  42. {
  43. return (NamingAuthority) obj;
  44. }
  45. if (obj is Asn1Sequence)
  46. {
  47. return new NamingAuthority((Asn1Sequence) obj);
  48. }
  49. throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  50. }
  51. public static NamingAuthority GetInstance(
  52. Asn1TaggedObject obj,
  53. bool isExplicit)
  54. {
  55. return GetInstance(Asn1Sequence.GetInstance(obj, isExplicit));
  56. }
  57. /**
  58. * Constructor from Asn1Sequence.
  59. * <p/>
  60. * <p/>
  61. * <pre>
  62. * NamingAuthority ::= SEQUENCE
  63. * {
  64. * namingAuthorityID OBJECT IDENTIFIER OPTIONAL,
  65. * namingAuthorityUrl IA5String OPTIONAL,
  66. * namingAuthorityText DirectoryString(SIZE(1..128)) OPTIONAL
  67. * }
  68. * </pre>
  69. *
  70. * @param seq The ASN.1 sequence.
  71. */
  72. private NamingAuthority(
  73. Asn1Sequence seq)
  74. {
  75. if (seq.Count > 3)
  76. throw new ArgumentException("Bad sequence size: " + seq.Count);
  77. IEnumerator e = seq.GetEnumerator();
  78. if (e.MoveNext())
  79. {
  80. Asn1Encodable o = (Asn1Encodable) e.Current;
  81. if (o is DerObjectIdentifier)
  82. {
  83. namingAuthorityID = (DerObjectIdentifier) o;
  84. }
  85. else if (o is DerIA5String)
  86. {
  87. namingAuthorityUrl = DerIA5String.GetInstance(o).GetString();
  88. }
  89. else if (o is IAsn1String)
  90. {
  91. namingAuthorityText = DirectoryString.GetInstance(o);
  92. }
  93. else
  94. {
  95. throw new ArgumentException("Bad object encountered: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(o));
  96. }
  97. }
  98. if (e.MoveNext())
  99. {
  100. Asn1Encodable o = (Asn1Encodable) e.Current;
  101. if (o is DerIA5String)
  102. {
  103. namingAuthorityUrl = DerIA5String.GetInstance(o).GetString();
  104. }
  105. else if (o is IAsn1String)
  106. {
  107. namingAuthorityText = DirectoryString.GetInstance(o);
  108. }
  109. else
  110. {
  111. throw new ArgumentException("Bad object encountered: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(o));
  112. }
  113. }
  114. if (e.MoveNext())
  115. {
  116. Asn1Encodable o = (Asn1Encodable) e.Current;
  117. if (o is IAsn1String)
  118. {
  119. namingAuthorityText = DirectoryString.GetInstance(o);
  120. }
  121. else
  122. {
  123. throw new ArgumentException("Bad object encountered: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(o));
  124. }
  125. }
  126. }
  127. /**
  128. * @return Returns the namingAuthorityID.
  129. */
  130. public virtual DerObjectIdentifier NamingAuthorityID
  131. {
  132. get { return namingAuthorityID; }
  133. }
  134. /**
  135. * @return Returns the namingAuthorityText.
  136. */
  137. public virtual DirectoryString NamingAuthorityText
  138. {
  139. get { return namingAuthorityText; }
  140. }
  141. /**
  142. * @return Returns the namingAuthorityUrl.
  143. */
  144. public virtual string NamingAuthorityUrl
  145. {
  146. get { return namingAuthorityUrl; }
  147. }
  148. /**
  149. * Constructor from given details.
  150. * <p/>
  151. * All parameters can be combined.
  152. *
  153. * @param namingAuthorityID ObjectIdentifier for naming authority.
  154. * @param namingAuthorityUrl URL for naming authority.
  155. * @param namingAuthorityText Textual representation of naming authority.
  156. */
  157. public NamingAuthority(
  158. DerObjectIdentifier namingAuthorityID,
  159. string namingAuthorityUrl,
  160. DirectoryString namingAuthorityText)
  161. {
  162. this.namingAuthorityID = namingAuthorityID;
  163. this.namingAuthorityUrl = namingAuthorityUrl;
  164. this.namingAuthorityText = namingAuthorityText;
  165. }
  166. /**
  167. * Produce an object suitable for an Asn1OutputStream.
  168. * <p/>
  169. * Returns:
  170. * <p/>
  171. * <pre>
  172. * NamingAuthority ::= SEQUENCE
  173. * {
  174. * namingAuthorityID OBJECT IDENTIFIER OPTIONAL,
  175. * namingAuthorityUrl IA5String OPTIONAL,
  176. * namingAuthorityText DirectoryString(SIZE(1..128)) OPTIONAL
  177. * }
  178. * </pre>
  179. *
  180. * @return an Asn1Object
  181. */
  182. public override Asn1Object ToAsn1Object()
  183. {
  184. Asn1EncodableVector v = new Asn1EncodableVector();
  185. v.AddOptional(namingAuthorityID);
  186. if (namingAuthorityUrl != null)
  187. {
  188. v.Add(new DerIA5String(namingAuthorityUrl, true));
  189. }
  190. v.AddOptional(namingAuthorityText);
  191. return new DerSequence(v);
  192. }
  193. }
  194. }
  195. #pragma warning restore
  196. #endif