X962Parameters.cs 1.8 KB

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