PublicKeyMessage.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. namespace Renci.SshNet.Messages.Authentication
  2. {
  3. /// <summary>
  4. /// Represents SSH_MSG_USERAUTH_PK_OK message.
  5. /// </summary>
  6. [Message("SSH_MSG_USERAUTH_PK_OK", 60)]
  7. internal class PublicKeyMessage : Message
  8. {
  9. #if TUNING
  10. /// <summary>
  11. /// Gets the name of the public key algorithm as ASCII encoded byte array.
  12. /// </summary>
  13. /// <value>
  14. /// The name of the public key algorithm.
  15. /// </value>
  16. public byte[] PublicKeyAlgorithmName { get; private set; }
  17. #else
  18. /// <summary>
  19. /// Gets the name of the public key algorithm.
  20. /// </summary>
  21. /// <value>
  22. /// The name of the public key algorithm.
  23. /// </value>
  24. public string PublicKeyAlgorithmName { get; private set; }
  25. #endif
  26. /// <summary>
  27. /// Gets the public key data.
  28. /// </summary>
  29. public byte[] PublicKeyData { get; private set; }
  30. #if TUNING
  31. /// <summary>
  32. /// Gets the size of the message in bytes.
  33. /// </summary>
  34. /// <value>
  35. /// The size of the messages in bytes.
  36. /// </value>
  37. protected override int BufferCapacity
  38. {
  39. get
  40. {
  41. var capacity = base.BufferCapacity;
  42. capacity += 4; // PublicKeyAlgorithmName length
  43. capacity += PublicKeyAlgorithmName.Length; // PublicKeyAlgorithmName
  44. capacity += 4; // PublicKeyData length
  45. capacity += PublicKeyData.Length; // PublicKeyData
  46. return capacity;
  47. }
  48. }
  49. #endif
  50. /// <summary>
  51. /// Called when type specific data need to be loaded.
  52. /// </summary>
  53. protected override void LoadData()
  54. {
  55. #if TUNING
  56. PublicKeyAlgorithmName = ReadBinary();
  57. PublicKeyData = ReadBinary();
  58. #else
  59. PublicKeyAlgorithmName = ReadAsciiString();
  60. PublicKeyData = ReadBinaryString();
  61. #endif
  62. }
  63. /// <summary>
  64. /// Called when type specific data need to be saved.
  65. /// </summary>
  66. protected override void SaveData()
  67. {
  68. #if TUNING
  69. WriteBinaryString(PublicKeyAlgorithmName);
  70. WriteBinaryString(PublicKeyData);
  71. #else
  72. WriteAscii(PublicKeyAlgorithmName);
  73. WriteBinaryString(PublicKeyData);
  74. #endif
  75. }
  76. }
  77. }