KeyExchangeDhGroupExchangeReply.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using Renci.SshNet.Common;
  3. namespace Renci.SshNet.Messages.Transport
  4. {
  5. /// <summary>
  6. /// Represents SSH_MSG_KEX_DH_GEX_REPLY message.
  7. /// </summary>
  8. [Message("SSH_MSG_KEX_DH_GEX_REPLY", MessageNumber)]
  9. internal class KeyExchangeDhGroupExchangeReply : Message
  10. {
  11. internal const byte MessageNumber = 33;
  12. #if TUNING
  13. private byte[] _fBytes;
  14. #endif
  15. /// <summary>
  16. /// Gets server public host key and certificates
  17. /// </summary>
  18. /// <value>The host key.</value>
  19. public byte[] HostKey { get; private set; }
  20. /// <summary>
  21. /// Gets the F value.
  22. /// </summary>
  23. #if TUNING
  24. public BigInteger F
  25. {
  26. get { return _fBytes.ToBigInteger(); }
  27. }
  28. #else
  29. public BigInteger F { get; private set; }
  30. #endif
  31. /// <summary>
  32. /// Gets the signature of H.
  33. /// </summary>
  34. /// <value>The signature.</value>
  35. public byte[] Signature { get; private set; }
  36. #if TUNING
  37. /// <summary>
  38. /// Gets the size of the message in bytes.
  39. /// </summary>
  40. /// <value>
  41. /// The size of the messages in bytes.
  42. /// </value>
  43. protected override int BufferCapacity
  44. {
  45. get
  46. {
  47. var capacity = base.BufferCapacity;
  48. capacity += 4; // HostKey length
  49. capacity += HostKey.Length; // HostKey
  50. capacity += 4; // F length
  51. capacity += _fBytes.Length; // F
  52. capacity += 4; // Signature length
  53. capacity += Signature.Length; // Signature
  54. return capacity;
  55. }
  56. }
  57. #endif
  58. /// <summary>
  59. /// Called when type specific data need to be loaded.
  60. /// </summary>
  61. protected override void LoadData()
  62. {
  63. #if TUNING
  64. HostKey = ReadBinary();
  65. _fBytes = ReadBinary();
  66. Signature = ReadBinary();
  67. #else
  68. HostKey = ReadBinaryString();
  69. F = ReadBigInt();
  70. Signature = ReadBinaryString();
  71. #endif
  72. }
  73. /// <summary>
  74. /// Called when type specific data need to be saved.
  75. /// </summary>
  76. protected override void SaveData()
  77. {
  78. WriteBinaryString(HostKey);
  79. #if TUNING
  80. WriteBinaryString(_fBytes);
  81. #else
  82. Write(F);
  83. #endif
  84. WriteBinaryString(Signature);
  85. }
  86. }
  87. }