Attribute.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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.Pkcs
  6. {
  7. public class AttributePkcs
  8. : Asn1Encodable
  9. {
  10. private readonly DerObjectIdentifier attrType;
  11. private readonly Asn1Set attrValues;
  12. /**
  13. * return an Attribute 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 AttributePkcs GetInstance(
  19. object obj)
  20. {
  21. AttributePkcs attr = obj as AttributePkcs;
  22. if (obj == null || attr != null)
  23. {
  24. return attr;
  25. }
  26. Asn1Sequence seq = obj as Asn1Sequence;
  27. if (seq != null)
  28. {
  29. return new AttributePkcs(seq);
  30. }
  31. throw new ArgumentException("Unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  32. }
  33. private AttributePkcs(
  34. Asn1Sequence seq)
  35. {
  36. if (seq.Count != 2)
  37. throw new ArgumentException("Wrong number of elements in sequence", "seq");
  38. attrType = DerObjectIdentifier.GetInstance(seq[0]);
  39. attrValues = Asn1Set.GetInstance(seq[1]);
  40. }
  41. public AttributePkcs(
  42. DerObjectIdentifier attrType,
  43. Asn1Set attrValues)
  44. {
  45. this.attrType = attrType;
  46. this.attrValues = attrValues;
  47. }
  48. public DerObjectIdentifier AttrType
  49. {
  50. get { return attrType; }
  51. }
  52. public Asn1Set AttrValues
  53. {
  54. get { return attrValues; }
  55. }
  56. /**
  57. * Produce an object suitable for an Asn1OutputStream.
  58. * <pre>
  59. * Attr ::= Sequence {
  60. * attrType OBJECT IDENTIFIER,
  61. * attrValues Set OF AttributeValue
  62. * }
  63. * </pre>
  64. */
  65. public override Asn1Object ToAsn1Object()
  66. {
  67. return new DerSequence(attrType, attrValues);
  68. }
  69. }
  70. }
  71. #pragma warning restore
  72. #endif