DHValidationParms.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. using System;
  3. using Org.BouncyCastle.Utilities;
  4. namespace Org.BouncyCastle.Asn1.X9
  5. {
  6. public class DHValidationParms
  7. : Asn1Encodable
  8. {
  9. private readonly DerBitString seed;
  10. private readonly DerInteger pgenCounter;
  11. public static DHValidationParms GetInstance(Asn1TaggedObject obj, bool isExplicit)
  12. {
  13. return GetInstance(Asn1Sequence.GetInstance(obj, isExplicit));
  14. }
  15. public static DHValidationParms GetInstance(object obj)
  16. {
  17. if (obj == null || obj is DHDomainParameters)
  18. return (DHValidationParms)obj;
  19. if (obj is Asn1Sequence)
  20. return new DHValidationParms((Asn1Sequence)obj);
  21. throw new ArgumentException("Invalid DHValidationParms: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  22. }
  23. public DHValidationParms(DerBitString seed, DerInteger pgenCounter)
  24. {
  25. if (seed == null)
  26. throw new ArgumentNullException("seed");
  27. if (pgenCounter == null)
  28. throw new ArgumentNullException("pgenCounter");
  29. this.seed = seed;
  30. this.pgenCounter = pgenCounter;
  31. }
  32. private DHValidationParms(Asn1Sequence seq)
  33. {
  34. if (seq.Count != 2)
  35. throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
  36. this.seed = DerBitString.GetInstance(seq[0]);
  37. this.pgenCounter = DerInteger.GetInstance(seq[1]);
  38. }
  39. public DerBitString Seed
  40. {
  41. get { return this.seed; }
  42. }
  43. public DerInteger PgenCounter
  44. {
  45. get { return this.pgenCounter; }
  46. }
  47. public override Asn1Object ToAsn1Object()
  48. {
  49. return new DerSequence(seed, pgenCounter);
  50. }
  51. }
  52. }
  53. #endif