X962Parameters.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. namespace BestHTTP.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. public X962Parameters(
  51. Asn1Object obj)
  52. {
  53. this._params = obj;
  54. }
  55. public bool IsNamedCurve
  56. {
  57. get { return (_params is DerObjectIdentifier); }
  58. }
  59. public bool IsImplicitlyCA
  60. {
  61. get { return (_params is Asn1Null); }
  62. }
  63. public Asn1Object Parameters
  64. {
  65. get { return _params; }
  66. }
  67. /**
  68. * Produce an object suitable for an Asn1OutputStream.
  69. * <pre>
  70. * Parameters ::= CHOICE {
  71. * ecParameters ECParameters,
  72. * namedCurve CURVES.&amp;id({CurveNames}),
  73. * implicitlyCA Null
  74. * }
  75. * </pre>
  76. */
  77. public override Asn1Object ToAsn1Object()
  78. {
  79. return _params;
  80. }
  81. }
  82. }
  83. #pragma warning restore
  84. #endif