DHParameter.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. using Org.BouncyCastle.Asn1;
  3. using System;
  4. using System.Collections;
  5. using Org.BouncyCastle.Math;
  6. namespace Org.BouncyCastle.Asn1.Pkcs
  7. {
  8. public class DHParameter
  9. : Asn1Encodable
  10. {
  11. internal DerInteger p, g, l;
  12. public DHParameter(
  13. BigInteger p,
  14. BigInteger g,
  15. int l)
  16. {
  17. this.p = new DerInteger(p);
  18. this.g = new DerInteger(g);
  19. if (l != 0)
  20. {
  21. this.l = new DerInteger(l);
  22. }
  23. }
  24. public DHParameter(
  25. Asn1Sequence seq)
  26. {
  27. IEnumerator e = seq.GetEnumerator();
  28. e.MoveNext();
  29. p = (DerInteger)e.Current;
  30. e.MoveNext();
  31. g = (DerInteger)e.Current;
  32. if (e.MoveNext())
  33. {
  34. l = (DerInteger) e.Current;
  35. }
  36. }
  37. public BigInteger P
  38. {
  39. get { return p.PositiveValue; }
  40. }
  41. public BigInteger G
  42. {
  43. get { return g.PositiveValue; }
  44. }
  45. public BigInteger L
  46. {
  47. get { return l == null ? null : l.PositiveValue; }
  48. }
  49. public override Asn1Object ToAsn1Object()
  50. {
  51. Asn1EncodableVector v = new Asn1EncodableVector(p, g);
  52. if (this.l != null)
  53. {
  54. v.Add(l);
  55. }
  56. return new DerSequence(v);
  57. }
  58. }
  59. }
  60. #endif