SemanticsInformation.cs 3.6 KB

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