SubjectDirectoryAttributes.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
  7. namespace Best.HTTP.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<AttributeX509> m_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: " + 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. m_attributes = new List<AttributeX509>();
  70. foreach (object o in seq)
  71. {
  72. Asn1Sequence s = Asn1Sequence.GetInstance(o);
  73. m_attributes.Add(AttributeX509.GetInstance(s));
  74. }
  75. }
  76. /**
  77. * Constructor from an ArrayList of attributes.
  78. *
  79. * The ArrayList consists of attributes of type {@link Attribute Attribute}
  80. *
  81. * @param attributes The attributes.
  82. *
  83. */
  84. public SubjectDirectoryAttributes(IList<AttributeX509> attributes)
  85. {
  86. m_attributes = new List<AttributeX509>(attributes);
  87. }
  88. /**
  89. * Produce an object suitable for an Asn1OutputStream.
  90. *
  91. * Returns:
  92. *
  93. * <pre>
  94. * SubjectDirectoryAttributes ::= Attributes
  95. * Attributes ::= SEQUENCE SIZE (1..MAX) OF Attribute
  96. * Attribute ::= SEQUENCE
  97. * {
  98. * type AttributeType
  99. * values SET OF AttributeValue
  100. * }
  101. *
  102. * AttributeType ::= OBJECT IDENTIFIER
  103. * AttributeValue ::= ANY DEFINED BY AttributeType
  104. * </pre>
  105. *
  106. * @return a DERObject
  107. */
  108. public override Asn1Object ToAsn1Object()
  109. {
  110. AttributeX509[] v = new AttributeX509[m_attributes.Count];
  111. for (int i = 0; i < m_attributes.Count; ++i)
  112. {
  113. v[i] = m_attributes[i];
  114. }
  115. return new DerSequence(v);
  116. }
  117. /**
  118. * @return Returns the attributes.
  119. */
  120. public IEnumerable<AttributeX509> Attributes
  121. {
  122. get { return CollectionUtilities.Proxy(m_attributes); }
  123. }
  124. }
  125. }
  126. #pragma warning restore
  127. #endif