SubjectDirectoryAttributes.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
  7. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509
  8. {
  9. /**
  10. * This extension may contain further X.500 attributes of the subject. See also
  11. * RFC 3039.
  12. *
  13. * <pre>
  14. * SubjectDirectoryAttributes ::= Attributes
  15. * Attributes ::= SEQUENCE SIZE (1..MAX) OF Attribute
  16. * Attribute ::= SEQUENCE
  17. * {
  18. * type AttributeType
  19. * values SET OF AttributeValue
  20. * }
  21. *
  22. * AttributeType ::= OBJECT IDENTIFIER
  23. * AttributeValue ::= ANY DEFINED BY AttributeType
  24. * </pre>
  25. *
  26. * @see org.bouncycastle.asn1.x509.X509Name for AttributeType ObjectIdentifiers.
  27. */
  28. public class SubjectDirectoryAttributes
  29. : Asn1Encodable
  30. {
  31. private readonly IList attributes;
  32. public static SubjectDirectoryAttributes GetInstance(
  33. object obj)
  34. {
  35. if (obj == null || obj is SubjectDirectoryAttributes)
  36. {
  37. return (SubjectDirectoryAttributes) obj;
  38. }
  39. if (obj is Asn1Sequence)
  40. {
  41. return new SubjectDirectoryAttributes((Asn1Sequence) obj);
  42. }
  43. throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  44. }
  45. /**
  46. * Constructor from Asn1Sequence.
  47. *
  48. * The sequence is of type SubjectDirectoryAttributes:
  49. *
  50. * <pre>
  51. * SubjectDirectoryAttributes ::= Attributes
  52. * Attributes ::= SEQUENCE SIZE (1..MAX) OF Attribute
  53. * Attribute ::= SEQUENCE
  54. * {
  55. * type AttributeType
  56. * values SET OF AttributeValue
  57. * }
  58. *
  59. * AttributeType ::= OBJECT IDENTIFIER
  60. * AttributeValue ::= ANY DEFINED BY AttributeType
  61. * </pre>
  62. *
  63. * @param seq
  64. * The ASN.1 sequence.
  65. */
  66. private SubjectDirectoryAttributes(
  67. Asn1Sequence seq)
  68. {
  69. this.attributes = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
  70. foreach (object o in seq)
  71. {
  72. Asn1Sequence s = Asn1Sequence.GetInstance(o);
  73. attributes.Add(AttributeX509.GetInstance(s));
  74. }
  75. }
  76. #if !(SILVERLIGHT || PORTABLE || NETFX_CORE)
  77. [Obsolete]
  78. public SubjectDirectoryAttributes(
  79. ArrayList attributes)
  80. : this((IList)attributes)
  81. {
  82. }
  83. #endif
  84. /**
  85. * Constructor from an ArrayList of attributes.
  86. *
  87. * The ArrayList consists of attributes of type {@link Attribute Attribute}
  88. *
  89. * @param attributes The attributes.
  90. *
  91. */
  92. public SubjectDirectoryAttributes(
  93. IList attributes)
  94. {
  95. this.attributes = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(attributes);
  96. }
  97. /**
  98. * Produce an object suitable for an Asn1OutputStream.
  99. *
  100. * Returns:
  101. *
  102. * <pre>
  103. * SubjectDirectoryAttributes ::= Attributes
  104. * Attributes ::= SEQUENCE SIZE (1..MAX) OF Attribute
  105. * Attribute ::= SEQUENCE
  106. * {
  107. * type AttributeType
  108. * values SET OF AttributeValue
  109. * }
  110. *
  111. * AttributeType ::= OBJECT IDENTIFIER
  112. * AttributeValue ::= ANY DEFINED BY AttributeType
  113. * </pre>
  114. *
  115. * @return a DERObject
  116. */
  117. public override Asn1Object ToAsn1Object()
  118. {
  119. AttributeX509[] v = new AttributeX509[attributes.Count];
  120. for (int i = 0; i < attributes.Count; ++i)
  121. {
  122. v[i] = (AttributeX509)attributes[i];
  123. }
  124. return new DerSequence(v);
  125. }
  126. /**
  127. * @return Returns the attributes.
  128. */
  129. public IEnumerable Attributes
  130. {
  131. get { return new EnumerableProxy(attributes); }
  132. }
  133. }
  134. }
  135. #pragma warning restore
  136. #endif