NameConstraints.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Collections.Generic;
  5. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace Best.HTTP.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: " + 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. /**
  42. * Constructor from a given details.
  43. *
  44. * <p>permitted and excluded are Vectors of GeneralSubtree objects.</p>
  45. *
  46. * @param permitted Permitted subtrees
  47. * @param excluded Excluded subtrees
  48. */
  49. public NameConstraints(
  50. IList<GeneralSubtree> permitted,
  51. IList<GeneralSubtree> excluded)
  52. {
  53. if (permitted != null)
  54. {
  55. this.permitted = CreateSequence(permitted);
  56. }
  57. if (excluded != null)
  58. {
  59. this.excluded = CreateSequence(excluded);
  60. }
  61. }
  62. private DerSequence CreateSequence(IList<GeneralSubtree> subtrees)
  63. {
  64. GeneralSubtree[] gsts = new GeneralSubtree[subtrees.Count];
  65. for (int i = 0; i < subtrees.Count; ++i)
  66. {
  67. gsts[i] = subtrees[i];
  68. }
  69. return new DerSequence(gsts);
  70. }
  71. public Asn1Sequence PermittedSubtrees
  72. {
  73. get { return permitted; }
  74. }
  75. public Asn1Sequence ExcludedSubtrees
  76. {
  77. get { return excluded; }
  78. }
  79. /*
  80. * NameConstraints ::= SEQUENCE { permittedSubtrees [0] GeneralSubtrees
  81. * OPTIONAL, excludedSubtrees [1] GeneralSubtrees OPTIONAL }
  82. */
  83. public override Asn1Object ToAsn1Object()
  84. {
  85. Asn1EncodableVector v = new Asn1EncodableVector();
  86. v.AddOptionalTagged(false, 0, permitted);
  87. v.AddOptionalTagged(false, 1, excluded);
  88. return new DerSequence(v);
  89. }
  90. }
  91. }
  92. #pragma warning restore
  93. #endif