Rdn.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X500
  5. {
  6. /**
  7. * Holding class for a single Relative Distinguished Name (RDN).
  8. */
  9. public class Rdn
  10. : Asn1Encodable
  11. {
  12. private readonly Asn1Set values;
  13. private Rdn(Asn1Set values)
  14. {
  15. this.values = values;
  16. }
  17. public static Rdn GetInstance(object obj)
  18. {
  19. if (obj is Rdn)
  20. return (Rdn)obj;
  21. if (null != obj)
  22. return new Rdn(Asn1Set.GetInstance(obj));
  23. return null;
  24. }
  25. /**
  26. * Create a single valued RDN.
  27. *
  28. * @param oid RDN type.
  29. * @param value RDN value.
  30. */
  31. public Rdn(DerObjectIdentifier oid, Asn1Encodable value)
  32. {
  33. this.values = new DerSet(new DerSequence(oid, value));
  34. }
  35. public Rdn(AttributeTypeAndValue attrTAndV)
  36. {
  37. this.values = new DerSet(attrTAndV);
  38. }
  39. /**
  40. * Create a multi-valued RDN.
  41. *
  42. * @param aAndVs attribute type/value pairs making up the RDN
  43. */
  44. public Rdn(AttributeTypeAndValue[] aAndVs)
  45. {
  46. this.values = new DerSet(aAndVs);
  47. }
  48. public virtual bool IsMultiValued
  49. {
  50. get { return this.values.Count > 1; }
  51. }
  52. /**
  53. * Return the number of AttributeTypeAndValue objects in this RDN,
  54. *
  55. * @return size of RDN, greater than 1 if multi-valued.
  56. */
  57. public virtual int Count
  58. {
  59. get { return this.values.Count; }
  60. }
  61. public virtual AttributeTypeAndValue GetFirst()
  62. {
  63. if (this.values.Count == 0)
  64. return null;
  65. return AttributeTypeAndValue.GetInstance(this.values[0]);
  66. }
  67. public virtual AttributeTypeAndValue[] GetTypesAndValues()
  68. {
  69. AttributeTypeAndValue[] tmp = new AttributeTypeAndValue[values.Count];
  70. for (int i = 0; i < tmp.Length; ++i)
  71. {
  72. tmp[i] = AttributeTypeAndValue.GetInstance(values[i]);
  73. }
  74. return tmp;
  75. }
  76. /**
  77. * <pre>
  78. * RelativeDistinguishedName ::=
  79. * SET OF AttributeTypeAndValue
  80. * AttributeTypeAndValue ::= SEQUENCE {
  81. * type AttributeType,
  82. * value AttributeValue }
  83. * </pre>
  84. * @return this object as its ASN1Primitive type
  85. */
  86. public override Asn1Object ToAsn1Object()
  87. {
  88. return values;
  89. }
  90. }
  91. }
  92. #pragma warning restore
  93. #endif