ServerSrpParams.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.IO;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
  6. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  7. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Tls
  8. {
  9. public class ServerSrpParams
  10. {
  11. protected BigInteger m_N, m_g, m_B;
  12. protected byte[] m_s;
  13. public ServerSrpParams(BigInteger N, BigInteger g, byte[] s, BigInteger B)
  14. {
  15. this.m_N = N;
  16. this.m_g = g;
  17. this.m_s = Arrays.Clone(s);
  18. this.m_B = B;
  19. }
  20. public virtual BigInteger B
  21. {
  22. get { return m_B; }
  23. }
  24. public virtual BigInteger G
  25. {
  26. get { return m_g; }
  27. }
  28. public virtual BigInteger N
  29. {
  30. get { return m_N; }
  31. }
  32. public virtual byte[] S
  33. {
  34. get { return m_s; }
  35. }
  36. /**
  37. * Encode this {@link ServerSRPParams} to an {@link OutputStream}.
  38. *
  39. * @param output
  40. * the {@link OutputStream} to encode to.
  41. * @throws IOException
  42. */
  43. public virtual void Encode(Stream output)
  44. {
  45. TlsSrpUtilities.WriteSrpParameter(m_N, output);
  46. TlsSrpUtilities.WriteSrpParameter(m_g, output);
  47. TlsUtilities.WriteOpaque8(m_s, output);
  48. TlsSrpUtilities.WriteSrpParameter(m_B, output);
  49. }
  50. /**
  51. * Parse a {@link ServerSRPParams} from an {@link InputStream}.
  52. *
  53. * @param input
  54. * the {@link InputStream} to parse from.
  55. * @return a {@link ServerSRPParams} object.
  56. * @throws IOException
  57. */
  58. public static ServerSrpParams Parse(Stream input)
  59. {
  60. BigInteger N = TlsSrpUtilities.ReadSrpParameter(input);
  61. BigInteger g = TlsSrpUtilities.ReadSrpParameter(input);
  62. byte[] s = TlsUtilities.ReadOpaque8(input);
  63. BigInteger B = TlsSrpUtilities.ReadSrpParameter(input);
  64. return new ServerSrpParams(N, g, s, B);
  65. }
  66. }
  67. }
  68. #pragma warning restore
  69. #endif