NamingAuthority.cs 5.5 KB

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