NameConstraints.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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.Utilities;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509
  7. {
  8. public class NameConstraints
  9. : Asn1Encodable
  10. {
  11. private Asn1Sequence permitted, excluded;
  12. public static NameConstraints GetInstance(
  13. object obj)
  14. {
  15. if (obj == null || obj is NameConstraints)
  16. {
  17. return (NameConstraints) obj;
  18. }
  19. if (obj is Asn1Sequence)
  20. {
  21. return new NameConstraints((Asn1Sequence) obj);
  22. }
  23. throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  24. }
  25. public NameConstraints(
  26. Asn1Sequence seq)
  27. {
  28. foreach (Asn1TaggedObject o in seq)
  29. {
  30. switch (o.TagNo)
  31. {
  32. case 0:
  33. permitted = Asn1Sequence.GetInstance(o, false);
  34. break;
  35. case 1:
  36. excluded = Asn1Sequence.GetInstance(o, false);
  37. break;
  38. }
  39. }
  40. }
  41. #if !(SILVERLIGHT || PORTABLE || NETFX_CORE)
  42. public NameConstraints(
  43. ArrayList permitted,
  44. ArrayList excluded)
  45. : this((IList)permitted, (IList)excluded)
  46. {
  47. }
  48. #endif
  49. /**
  50. * Constructor from a given details.
  51. *
  52. * <p>permitted and excluded are Vectors of GeneralSubtree objects.</p>
  53. *
  54. * @param permitted Permitted subtrees
  55. * @param excluded Excluded subtrees
  56. */
  57. public NameConstraints(
  58. IList permitted,
  59. IList excluded)
  60. {
  61. if (permitted != null)
  62. {
  63. this.permitted = CreateSequence(permitted);
  64. }
  65. if (excluded != null)
  66. {
  67. this.excluded = CreateSequence(excluded);
  68. }
  69. }
  70. private DerSequence CreateSequence(
  71. IList subtrees)
  72. {
  73. GeneralSubtree[] gsts = new GeneralSubtree[subtrees.Count];
  74. for (int i = 0; i < subtrees.Count; ++i)
  75. {
  76. gsts[i] = (GeneralSubtree)subtrees[i];
  77. }
  78. return new DerSequence(gsts);
  79. }
  80. public Asn1Sequence PermittedSubtrees
  81. {
  82. get { return permitted; }
  83. }
  84. public Asn1Sequence ExcludedSubtrees
  85. {
  86. get { return excluded; }
  87. }
  88. /*
  89. * NameConstraints ::= SEQUENCE { permittedSubtrees [0] GeneralSubtrees
  90. * OPTIONAL, excludedSubtrees [1] GeneralSubtrees OPTIONAL }
  91. */
  92. public override Asn1Object ToAsn1Object()
  93. {
  94. Asn1EncodableVector v = new Asn1EncodableVector();
  95. v.AddOptionalTagged(false, 0, permitted);
  96. v.AddOptionalTagged(false, 1, excluded);
  97. return new DerSequence(v);
  98. }
  99. }
  100. }
  101. #pragma warning restore
  102. #endif