X962Parameters.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1;
  5. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X9
  6. {
  7. public class X962Parameters
  8. : Asn1Encodable, IAsn1Choice
  9. {
  10. private readonly Asn1Object _params;
  11. public static X962Parameters GetInstance(
  12. object obj)
  13. {
  14. if (obj == null || obj is X962Parameters)
  15. {
  16. return (X962Parameters)obj;
  17. }
  18. if (obj is Asn1Object)
  19. {
  20. return new X962Parameters((Asn1Object)obj);
  21. }
  22. if (obj is byte[])
  23. {
  24. try
  25. {
  26. return new X962Parameters(Asn1Object.FromByteArray((byte[])obj));
  27. }
  28. catch (Exception e)
  29. {
  30. throw new ArgumentException("unable to parse encoded data: " + e.Message, e);
  31. }
  32. }
  33. throw new ArgumentException("unknown object in getInstance()");
  34. }
  35. public X962Parameters(
  36. X9ECParameters ecParameters)
  37. {
  38. this._params = ecParameters.ToAsn1Object();
  39. }
  40. public X962Parameters(
  41. DerObjectIdentifier namedCurve)
  42. {
  43. this._params = namedCurve;
  44. }
  45. public X962Parameters(
  46. Asn1Null obj)
  47. {
  48. this._params = obj;
  49. }
  50. private X962Parameters(Asn1Object obj)
  51. {
  52. this._params = obj;
  53. }
  54. public bool IsNamedCurve
  55. {
  56. get { return (_params is DerObjectIdentifier); }
  57. }
  58. public bool IsImplicitlyCA
  59. {
  60. get { return (_params is Asn1Null); }
  61. }
  62. public Asn1Object Parameters
  63. {
  64. get { return _params; }
  65. }
  66. /**
  67. * Produce an object suitable for an Asn1OutputStream.
  68. * <pre>
  69. * Parameters ::= CHOICE {
  70. * ecParameters ECParameters,
  71. * namedCurve CURVES.&amp;id({CurveNames}),
  72. * implicitlyCA Null
  73. * }
  74. * </pre>
  75. */
  76. public override Asn1Object ToAsn1Object()
  77. {
  78. return _params;
  79. }
  80. }
  81. }
  82. #pragma warning restore
  83. #endif