X509Attribute.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.X509
  7. {
  8. /**
  9. * Class for carrying the values in an X.509 Attribute.
  10. */
  11. public class X509Attribute
  12. : Asn1Encodable
  13. {
  14. private readonly AttributeX509 attr;
  15. /**
  16. * @param at an object representing an attribute.
  17. */
  18. internal X509Attribute(
  19. Asn1Encodable at)
  20. {
  21. this.attr = AttributeX509.GetInstance(at);
  22. }
  23. /**
  24. * Create an X.509 Attribute with the type given by the passed in oid and
  25. * the value represented by an ASN.1 Set containing value.
  26. *
  27. * @param oid type of the attribute
  28. * @param value value object to go into the atribute's value set.
  29. */
  30. public X509Attribute(
  31. string oid,
  32. Asn1Encodable value)
  33. {
  34. this.attr = new AttributeX509(new DerObjectIdentifier(oid), new DerSet(value));
  35. }
  36. /**
  37. * Create an X.59 Attribute with the type given by the passed in oid and the
  38. * value represented by an ASN.1 Set containing the objects in value.
  39. *
  40. * @param oid type of the attribute
  41. * @param value vector of values to go in the attribute's value set.
  42. */
  43. public X509Attribute(
  44. string oid,
  45. Asn1EncodableVector value)
  46. {
  47. this.attr = new AttributeX509(new DerObjectIdentifier(oid), new DerSet(value));
  48. }
  49. public string Oid
  50. {
  51. get { return attr.AttrType.Id; }
  52. }
  53. public Asn1Encodable[] GetValues()
  54. {
  55. Asn1Set s = attr.AttrValues;
  56. Asn1Encodable[] values = new Asn1Encodable[s.Count];
  57. for (int i = 0; i != s.Count; i++)
  58. {
  59. values[i] = (Asn1Encodable)s[i];
  60. }
  61. return values;
  62. }
  63. public override Asn1Object ToAsn1Object()
  64. {
  65. return attr.ToAsn1Object();
  66. }
  67. }
  68. }
  69. #pragma warning restore
  70. #endif