DSAParameter.cs 1.8 KB

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