ServerSrpParams.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.Tls
  8. {
  9. public sealed class ServerSrpParams
  10. {
  11. private BigInteger m_N, m_g, m_B;
  12. private 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 BigInteger B
  21. {
  22. get { return m_B; }
  23. }
  24. public BigInteger G
  25. {
  26. get { return m_g; }
  27. }
  28. public BigInteger N
  29. {
  30. get { return m_N; }
  31. }
  32. public byte[] S
  33. {
  34. get { return m_s; }
  35. }
  36. /// <summary>Encode this <see cref="ServerSrpParams"/> to a <see cref="Stream"/>.</summary>
  37. /// <param name="output">the <see cref="Stream"/> to encode to.</param>
  38. /// <exception cref="IOException"/>
  39. public void Encode(Stream output)
  40. {
  41. TlsSrpUtilities.WriteSrpParameter(m_N, output);
  42. TlsSrpUtilities.WriteSrpParameter(m_g, output);
  43. TlsUtilities.WriteOpaque8(m_s, output);
  44. TlsSrpUtilities.WriteSrpParameter(m_B, output);
  45. }
  46. /// <summary>Parse a <see cref="ServerSrpParams"/> from a <see cref="Stream"/>.</summary>
  47. /// <param name="input">the <see cref="Stream"/> to parse from.</param>
  48. /// <returns>a <see cref="ServerSrpParams"/> object.</returns>
  49. /// <exception cref="IOException"/>
  50. public static ServerSrpParams Parse(Stream input)
  51. {
  52. BigInteger N = TlsSrpUtilities.ReadSrpParameter(input);
  53. BigInteger g = TlsSrpUtilities.ReadSrpParameter(input);
  54. byte[] s = TlsUtilities.ReadOpaque8(input, 1);
  55. BigInteger B = TlsSrpUtilities.ReadSrpParameter(input);
  56. return new ServerSrpParams(N, g, s, B);
  57. }
  58. }
  59. }
  60. #pragma warning restore
  61. #endif