GOST3410ParamSetParameters.cs 2.2 KB

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