DHParameter.cs 1.5 KB

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