GOST3410ParamSetParameters.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Collections;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
  6. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  7. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.CryptoPro
  8. {
  9. public class Gost3410ParamSetParameters
  10. : Asn1Encodable
  11. {
  12. private readonly int keySize;
  13. private readonly DerInteger p, q, a;
  14. public static Gost3410ParamSetParameters GetInstance(
  15. Asn1TaggedObject obj,
  16. bool explicitly)
  17. {
  18. return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
  19. }
  20. public static Gost3410ParamSetParameters GetInstance(
  21. object obj)
  22. {
  23. if (obj == null || obj is Gost3410ParamSetParameters)
  24. {
  25. return (Gost3410ParamSetParameters) obj;
  26. }
  27. if (obj is Asn1Sequence)
  28. {
  29. return new Gost3410ParamSetParameters((Asn1Sequence) obj);
  30. }
  31. throw new ArgumentException("Invalid GOST3410Parameter: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj));
  32. }
  33. public Gost3410ParamSetParameters(
  34. int keySize,
  35. BigInteger p,
  36. BigInteger q,
  37. BigInteger a)
  38. {
  39. this.keySize = keySize;
  40. this.p = new DerInteger(p);
  41. this.q = new DerInteger(q);
  42. this.a = new DerInteger(a);
  43. }
  44. private Gost3410ParamSetParameters(
  45. Asn1Sequence seq)
  46. {
  47. if (seq.Count != 4)
  48. throw new ArgumentException("Wrong number of elements in sequence", "seq");
  49. this.keySize = DerInteger.GetInstance(seq[0]).IntValueExact;
  50. this.p = DerInteger.GetInstance(seq[1]);
  51. this.q = DerInteger.GetInstance(seq[2]);
  52. this.a = DerInteger.GetInstance(seq[3]);
  53. }
  54. public int KeySize
  55. {
  56. get { return keySize; }
  57. }
  58. public BigInteger P
  59. {
  60. get { return p.PositiveValue; }
  61. }
  62. public BigInteger Q
  63. {
  64. get { return q.PositiveValue; }
  65. }
  66. public BigInteger A
  67. {
  68. get { return a.PositiveValue; }
  69. }
  70. public override Asn1Object ToAsn1Object()
  71. {
  72. return new DerSequence(new DerInteger(keySize), p, q, a);
  73. }
  74. }
  75. }
  76. #pragma warning restore
  77. #endif