Targets.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. * Targets structure used in target information extension for attribute
  9. * certificates from RFC 3281.
  10. *
  11. * <pre>
  12. * Targets ::= SEQUENCE OF Target
  13. *
  14. * Target ::= CHOICE {
  15. * targetName [0] GeneralName,
  16. * targetGroup [1] GeneralName,
  17. * targetCert [2] TargetCert
  18. * }
  19. *
  20. * TargetCert ::= SEQUENCE {
  21. * targetCertificate IssuerSerial,
  22. * targetName GeneralName OPTIONAL,
  23. * certDigestInfo ObjectDigestInfo OPTIONAL
  24. * }
  25. * </pre>
  26. *
  27. * @see org.bouncycastle.asn1.x509.Target
  28. * @see org.bouncycastle.asn1.x509.TargetInformation
  29. */
  30. public class Targets
  31. : Asn1Encodable
  32. {
  33. private readonly Asn1Sequence targets;
  34. /**
  35. * Creates an instance of a Targets from the given object.
  36. * <p>
  37. * <code>obj</code> can be a Targets or a {@link Asn1Sequence}</p>
  38. *
  39. * @param obj The object.
  40. * @return A Targets instance.
  41. * @throws ArgumentException if the given object cannot be interpreted as Target.
  42. */
  43. public static Targets GetInstance(
  44. object obj)
  45. {
  46. if (obj is Targets)
  47. {
  48. return (Targets) obj;
  49. }
  50. if (obj is Asn1Sequence)
  51. {
  52. return new Targets((Asn1Sequence) obj);
  53. }
  54. throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  55. }
  56. /**
  57. * Constructor from Asn1Sequence.
  58. *
  59. * @param targets The ASN.1 SEQUENCE.
  60. * @throws ArgumentException if the contents of the sequence are
  61. * invalid.
  62. */
  63. private Targets(
  64. Asn1Sequence targets)
  65. {
  66. this.targets = targets;
  67. }
  68. /**
  69. * Constructor from given targets.
  70. * <p>
  71. * The ArrayList is copied.</p>
  72. *
  73. * @param targets An <code>ArrayList</code> of {@link Target}s.
  74. * @see Target
  75. * @throws ArgumentException if the ArrayList contains not only Targets.
  76. */
  77. public Targets(
  78. Target[] targets)
  79. {
  80. this.targets = new DerSequence(targets);
  81. }
  82. /**
  83. * Returns the targets in an <code>ArrayList</code>.
  84. * <p>
  85. * The ArrayList is cloned before it is returned.</p>
  86. *
  87. * @return Returns the targets.
  88. */
  89. public virtual Target[] GetTargets()
  90. {
  91. Target[] result = new Target[targets.Count];
  92. for (int i = 0; i < targets.Count; ++i)
  93. {
  94. result[i] = Target.GetInstance(targets[i]);
  95. }
  96. return result;
  97. }
  98. /**
  99. * Produce an object suitable for an Asn1OutputStream.
  100. *
  101. * Returns:
  102. *
  103. * <pre>
  104. * Targets ::= SEQUENCE OF Target
  105. * </pre>
  106. *
  107. * @return an Asn1Object
  108. */
  109. public override Asn1Object ToAsn1Object()
  110. {
  111. return targets;
  112. }
  113. }
  114. }
  115. #pragma warning restore
  116. #endif