TargetInformation.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509
  6. {
  7. /**
  8. * Target information extension for attributes certificates according to RFC
  9. * 3281.
  10. *
  11. * <pre>
  12. * SEQUENCE OF Targets
  13. * </pre>
  14. *
  15. */
  16. public class TargetInformation
  17. : Asn1Encodable
  18. {
  19. private readonly Asn1Sequence targets;
  20. /**
  21. * Creates an instance of a TargetInformation from the given object.
  22. * <p>
  23. * <code>obj</code> can be a TargetInformation or a {@link Asn1Sequence}</p>
  24. *
  25. * @param obj The object.
  26. * @return A TargetInformation instance.
  27. * @throws ArgumentException if the given object cannot be interpreted as TargetInformation.
  28. */
  29. public static TargetInformation GetInstance(
  30. object obj)
  31. {
  32. if (obj is TargetInformation)
  33. {
  34. return (TargetInformation) obj;
  35. }
  36. if (obj is Asn1Sequence)
  37. {
  38. return new TargetInformation((Asn1Sequence) obj);
  39. }
  40. throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  41. }
  42. /**
  43. * Constructor from a Asn1Sequence.
  44. *
  45. * @param seq The Asn1Sequence.
  46. * @throws ArgumentException if the sequence does not contain
  47. * correctly encoded Targets elements.
  48. */
  49. private TargetInformation(
  50. Asn1Sequence targets)
  51. {
  52. this.targets = targets;
  53. }
  54. /**
  55. * Returns the targets in this target information extension.
  56. * <p>
  57. * The ArrayList is cloned before it is returned.</p>
  58. *
  59. * @return Returns the targets.
  60. */
  61. public virtual Targets[] GetTargetsObjects()
  62. {
  63. Targets[] result = new Targets[targets.Count];
  64. for (int i = 0; i < targets.Count; ++i)
  65. {
  66. result[i] = Targets.GetInstance(targets[i]);
  67. }
  68. return result;
  69. }
  70. /**
  71. * Constructs a target information from a single targets element.
  72. * According to RFC 3281 only one targets element must be produced.
  73. *
  74. * @param targets A Targets instance.
  75. */
  76. public TargetInformation(
  77. Targets targets)
  78. {
  79. this.targets = new DerSequence(targets);
  80. }
  81. /**
  82. * According to RFC 3281 only one targets element must be produced. If
  83. * multiple targets are given they must be merged in
  84. * into one targets element.
  85. *
  86. * @param targets An array with {@link Targets}.
  87. */
  88. public TargetInformation(
  89. Target[] targets)
  90. : this(new Targets(targets))
  91. {
  92. }
  93. /**
  94. * Produce an object suitable for an Asn1OutputStream.
  95. *
  96. * Returns:
  97. *
  98. * <pre>
  99. * SEQUENCE OF Targets
  100. * </pre>
  101. *
  102. * <p>
  103. * According to RFC 3281 only one targets element must be produced. If
  104. * multiple targets are given in the constructor they are merged into one
  105. * targets element. If this was produced from a
  106. * {@link BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Asn1Sequence} the encoding is kept.</p>
  107. *
  108. * @return an Asn1Object
  109. */
  110. public override Asn1Object ToAsn1Object()
  111. {
  112. return targets;
  113. }
  114. }
  115. }
  116. #pragma warning restore
  117. #endif