| | | 1 | | using System; |
| | | 2 | | |
| | | 3 | | namespace Renci.SshNet.Messages.Connection |
| | | 4 | | { |
| | | 5 | | /// <summary> |
| | | 6 | | /// Represents SSH_MSG_CHANNEL_DATA message. |
| | | 7 | | /// </summary> |
| | | 8 | | [Message("SSH_MSG_CHANNEL_DATA", MessageNumber)] |
| | | 9 | | public class ChannelDataMessage : ChannelMessage |
| | | 10 | | { |
| | | 11 | | internal const byte MessageNumber = 94; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Gets the message data. |
| | | 15 | | /// </summary> |
| | | 16 | | /// <value> |
| | | 17 | | /// The data. |
| | | 18 | | /// </value> |
| | | 19 | | /// <remarks> |
| | | 20 | | /// The actual data to read or write depends on the <see cref="Offset"/> and <see cref="Size"/>. |
| | | 21 | | /// </remarks> |
| | 178134 | 22 | | public byte[] Data { get; private set; } |
| | | 23 | | |
| | | 24 | | /// <summary> |
| | | 25 | | /// Gets the zero-based offset in <see cref="Data"/> at which the data begins. |
| | | 26 | | /// </summary> |
| | | 27 | | /// <value> |
| | | 28 | | /// The zero-based offset in <see cref="Data"/> at which the data begins. |
| | | 29 | | /// </value> |
| | 108617 | 30 | | public int Offset { get; private set; } |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// Gets the number of bytes of <see cref="Data"/> to read or write. |
| | | 34 | | /// </summary> |
| | | 35 | | /// <value> |
| | | 36 | | /// The number of bytes of <see cref="Data"/> to read or write. |
| | | 37 | | /// </value> |
| | 145534 | 38 | | public int Size { get; private set; } |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Gets the size of the message in bytes. |
| | | 42 | | /// </summary> |
| | | 43 | | /// <value> |
| | | 44 | | /// The size of the messages in bytes. |
| | | 45 | | /// </value> |
| | | 46 | | protected override int BufferCapacity |
| | | 47 | | { |
| | | 48 | | get |
| | 36917 | 49 | | { |
| | 36917 | 50 | | var capacity = base.BufferCapacity; |
| | 36917 | 51 | | capacity += 4; // Data length |
| | 36917 | 52 | | capacity += Size; // Data |
| | 36917 | 53 | | return capacity; |
| | 36917 | 54 | | } |
| | | 55 | | } |
| | | 56 | | |
| | | 57 | | internal override void Process(Session session) |
| | 34754 | 58 | | { |
| | 34754 | 59 | | session.OnChannelDataReceived(this); |
| | 34754 | 60 | | } |
| | | 61 | | |
| | | 62 | | /// <summary> |
| | | 63 | | /// Initializes a new instance of the <see cref="ChannelDataMessage"/> class. |
| | | 64 | | /// </summary> |
| | 34760 | 65 | | public ChannelDataMessage() |
| | 34760 | 66 | | { |
| | 34760 | 67 | | } |
| | | 68 | | |
| | | 69 | | /// <summary> |
| | | 70 | | /// Initializes a new instance of the <see cref="ChannelDataMessage"/> class. |
| | | 71 | | /// </summary> |
| | | 72 | | /// <param name="localChannelNumber">The local channel number.</param> |
| | | 73 | | /// <param name="data">Message data.</param> |
| | | 74 | | public ChannelDataMessage(uint localChannelNumber, byte[] data) |
| | 12 | 75 | | : base(localChannelNumber) |
| | 12 | 76 | | { |
| | 12 | 77 | | if (data is null) |
| | 3 | 78 | | { |
| | 3 | 79 | | throw new ArgumentNullException(nameof(data)); |
| | | 80 | | } |
| | | 81 | | |
| | 9 | 82 | | Data = data; |
| | 9 | 83 | | Offset = 0; |
| | 9 | 84 | | Size = data.Length; |
| | 9 | 85 | | } |
| | | 86 | | |
| | | 87 | | /// <summary> |
| | | 88 | | /// Initializes a new instance of the <see cref="ChannelDataMessage"/> class. |
| | | 89 | | /// </summary> |
| | | 90 | | /// <param name="localChannelNumber">The local channel number.</param> |
| | | 91 | | /// <param name="data">The message data.</param> |
| | | 92 | | /// <param name="offset">The zero-based byte offset in <paramref name="data"/> at which to begin reading or writ |
| | | 93 | | /// <param name="size">The number of bytes of <paramref name="data"/> to read or write.</param> |
| | | 94 | | public ChannelDataMessage(uint localChannelNumber, byte[] data, int offset, int size) |
| | 36925 | 95 | | : base(localChannelNumber) |
| | 36925 | 96 | | { |
| | 36925 | 97 | | if (data is null) |
| | 3 | 98 | | { |
| | 3 | 99 | | throw new ArgumentNullException(nameof(data)); |
| | | 100 | | } |
| | | 101 | | |
| | 36922 | 102 | | Data = data; |
| | 36922 | 103 | | Offset = offset; |
| | 36922 | 104 | | Size = size; |
| | 36922 | 105 | | } |
| | | 106 | | |
| | | 107 | | /// <summary> |
| | | 108 | | /// Loads the data. |
| | | 109 | | /// </summary> |
| | | 110 | | protected override void LoadData() |
| | 34757 | 111 | | { |
| | 34757 | 112 | | base.LoadData(); |
| | | 113 | | |
| | 34757 | 114 | | Data = ReadBinary(); |
| | 34757 | 115 | | Offset = 0; |
| | 34757 | 116 | | Size = Data.Length; |
| | 34757 | 117 | | } |
| | | 118 | | |
| | | 119 | | /// <summary> |
| | | 120 | | /// Saves the data. |
| | | 121 | | /// </summary> |
| | | 122 | | protected override void SaveData() |
| | 36917 | 123 | | { |
| | 36917 | 124 | | base.SaveData(); |
| | | 125 | | |
| | 36917 | 126 | | WriteBinary(Data, Offset, Size); |
| | 36917 | 127 | | } |
| | | 128 | | } |
| | | 129 | | } |