DSAParameter.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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.X509
  8. {
  9. public class DsaParameter
  10. : Asn1Encodable
  11. {
  12. internal readonly DerInteger p, q, g;
  13. public static DsaParameter GetInstance(
  14. Asn1TaggedObject obj,
  15. bool explicitly)
  16. {
  17. return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
  18. }
  19. public static DsaParameter GetInstance(
  20. object obj)
  21. {
  22. if(obj == null || obj is DsaParameter)
  23. {
  24. return (DsaParameter) obj;
  25. }
  26. if(obj is Asn1Sequence)
  27. {
  28. return new DsaParameter((Asn1Sequence) obj);
  29. }
  30. throw new ArgumentException("Invalid DsaParameter: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj));
  31. }
  32. public DsaParameter(
  33. BigInteger p,
  34. BigInteger q,
  35. BigInteger g)
  36. {
  37. this.p = new DerInteger(p);
  38. this.q = new DerInteger(q);
  39. this.g = new DerInteger(g);
  40. }
  41. private DsaParameter(
  42. Asn1Sequence seq)
  43. {
  44. if (seq.Count != 3)
  45. throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
  46. this.p = DerInteger.GetInstance(seq[0]);
  47. this.q = DerInteger.GetInstance(seq[1]);
  48. this.g = DerInteger.GetInstance(seq[2]);
  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 G
  59. {
  60. get { return g.PositiveValue; }
  61. }
  62. public override Asn1Object ToAsn1Object()
  63. {
  64. return new DerSequence(p, q, g);
  65. }
  66. }
  67. }
  68. #pragma warning restore
  69. #endif