Attribute.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. public class AttributeX509
  8. : Asn1Encodable
  9. {
  10. private readonly DerObjectIdentifier attrType;
  11. private readonly Asn1Set attrValues;
  12. /**
  13. * return an Attr object from the given object.
  14. *
  15. * @param o the object we want converted.
  16. * @exception ArgumentException if the object cannot be converted.
  17. */
  18. public static AttributeX509 GetInstance(
  19. object obj)
  20. {
  21. if (obj == null || obj is AttributeX509)
  22. {
  23. return (AttributeX509) obj;
  24. }
  25. if (obj is Asn1Sequence)
  26. {
  27. return new AttributeX509((Asn1Sequence) obj);
  28. }
  29. throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  30. }
  31. private AttributeX509(
  32. Asn1Sequence seq)
  33. {
  34. if (seq.Count != 2)
  35. throw new ArgumentException("Bad sequence size: " + seq.Count);
  36. attrType = DerObjectIdentifier.GetInstance(seq[0]);
  37. attrValues = Asn1Set.GetInstance(seq[1]);
  38. }
  39. public AttributeX509(
  40. DerObjectIdentifier attrType,
  41. Asn1Set attrValues)
  42. {
  43. this.attrType = attrType;
  44. this.attrValues = attrValues;
  45. }
  46. public DerObjectIdentifier AttrType
  47. {
  48. get { return attrType; }
  49. }
  50. public Asn1Encodable[] GetAttributeValues()
  51. {
  52. return attrValues.ToArray();
  53. }
  54. public Asn1Set AttrValues
  55. {
  56. get { return attrValues; }
  57. }
  58. /**
  59. * Produce an object suitable for an Asn1OutputStream.
  60. * <pre>
  61. * Attr ::= Sequence {
  62. * attrType OBJECT IDENTIFIER,
  63. * attrValues Set OF AttributeValue
  64. * }
  65. * </pre>
  66. */
  67. public override Asn1Object ToAsn1Object()
  68. {
  69. return new DerSequence(attrType, attrValues);
  70. }
  71. }
  72. }
  73. #pragma warning restore
  74. #endif