SemanticsInformation.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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.X509.Qualified
  8. {
  9. /**
  10. * The SemanticsInformation object.
  11. * <pre>
  12. * SemanticsInformation ::= SEQUENCE {
  13. * semanticsIdentifier OBJECT IDENTIFIER OPTIONAL,
  14. * nameRegistrationAuthorities NameRegistrationAuthorities
  15. * OPTIONAL }
  16. * (WITH COMPONENTS {..., semanticsIdentifier PRESENT}|
  17. * WITH COMPONENTS {..., nameRegistrationAuthorities PRESENT})
  18. *
  19. * NameRegistrationAuthorities ::= SEQUENCE SIZE (1..MAX) OF
  20. * GeneralName
  21. * </pre>
  22. */
  23. public class SemanticsInformation
  24. : Asn1Encodable
  25. {
  26. private readonly DerObjectIdentifier semanticsIdentifier;
  27. private readonly GeneralName[] nameRegistrationAuthorities;
  28. public static SemanticsInformation GetInstance(
  29. object obj)
  30. {
  31. if (obj == null || obj is SemanticsInformation)
  32. {
  33. return (SemanticsInformation) obj;
  34. }
  35. if (obj is Asn1Sequence)
  36. {
  37. return new SemanticsInformation(Asn1Sequence.GetInstance(obj));
  38. }
  39. throw new ArgumentException("unknown object in GetInstance: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  40. }
  41. public SemanticsInformation(
  42. Asn1Sequence seq)
  43. {
  44. if (seq.Count < 1)
  45. {
  46. throw new ArgumentException("no objects in SemanticsInformation");
  47. }
  48. IEnumerator e = seq.GetEnumerator();
  49. e.MoveNext();
  50. object obj = e.Current;
  51. if (obj is DerObjectIdentifier)
  52. {
  53. semanticsIdentifier = DerObjectIdentifier.GetInstance(obj);
  54. if (e.MoveNext())
  55. {
  56. obj = e.Current;
  57. }
  58. else
  59. {
  60. obj = null;
  61. }
  62. }
  63. if (obj != null)
  64. {
  65. Asn1Sequence generalNameSeq = Asn1Sequence.GetInstance(obj );
  66. nameRegistrationAuthorities = new GeneralName[generalNameSeq.Count];
  67. for (int i= 0; i < generalNameSeq.Count; i++)
  68. {
  69. nameRegistrationAuthorities[i] = GeneralName.GetInstance(generalNameSeq[i]);
  70. }
  71. }
  72. }
  73. public SemanticsInformation(
  74. DerObjectIdentifier semanticsIdentifier,
  75. GeneralName[] generalNames)
  76. {
  77. this.semanticsIdentifier = semanticsIdentifier;
  78. this.nameRegistrationAuthorities = generalNames;
  79. }
  80. public SemanticsInformation(
  81. DerObjectIdentifier semanticsIdentifier)
  82. {
  83. this.semanticsIdentifier = semanticsIdentifier;
  84. }
  85. public SemanticsInformation(
  86. GeneralName[] generalNames)
  87. {
  88. this.nameRegistrationAuthorities = generalNames;
  89. }
  90. public DerObjectIdentifier SemanticsIdentifier { get { return semanticsIdentifier; } }
  91. public GeneralName[] GetNameRegistrationAuthorities()
  92. {
  93. return nameRegistrationAuthorities;
  94. }
  95. public override Asn1Object ToAsn1Object()
  96. {
  97. Asn1EncodableVector v = new Asn1EncodableVector();
  98. v.AddOptional(semanticsIdentifier);
  99. if (null != nameRegistrationAuthorities)
  100. {
  101. v.Add(new DerSequence(nameRegistrationAuthorities));
  102. }
  103. return new DerSequence(v);
  104. }
  105. }
  106. }
  107. #pragma warning restore
  108. #endif