Skip to content

Commit bdeefa8

Browse files
authored
Merge branch 'develop' into bcl-ciphermode
2 parents a63cfdf + fd05d76 commit bdeefa8

33 files changed

+425
-198
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ jobs:
116116
uses: actions/setup-dotnet@v4
117117

118118
- name: Setup WSL2
119-
uses: Vampire/setup-wsl@f40fb59d850112c9a292b0218bca8271305b9127 # v5.0.0
119+
uses: Vampire/setup-wsl@3b46b44374d5d0ae94654c45d114a3ed7a0e07a8 # v5.0.1
120120
with:
121121
distribution: Ubuntu-24.04
122122

Directory.Packages.props

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44
<CentralPackageVersionOverrideEnabled>false</CentralPackageVersionOverrideEnabled>
55
</PropertyGroup>
66
<ItemGroup>
7-
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
8-
<PackageVersion Include="BouncyCastle.Cryptography" Version="2.5.1" />
7+
<PackageVersion Include="BenchmarkDotNet" Version="0.15.0" />
8+
<PackageVersion Include="BouncyCastle.Cryptography" Version="2.6.1" />
99
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
1010
<PackageVersion Include="coverlet.msbuild" Version="6.0.4" />
1111
<PackageVersion Include="GitHubActionsTestLogger" Version="2.4.1" />
12-
<PackageVersion Include="Meziantou.Analyzer" Version="2.0.188" />
12+
<PackageVersion Include="Meziantou.Analyzer" Version="2.0.201" />
1313

1414
<!-- Should stay on LTS .NET releases. -->
1515
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.3" />
16-
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="9.0.3" />
17-
<PackageVersion Include="MSTest" Version="3.8.3" />
16+
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="9.0.5" />
17+
<PackageVersion Include="MSTest" Version="3.9.1" />
1818
<PackageVersion Include="Moq" Version="4.20.72" />
1919
<PackageVersion Include="Nerdbank.GitVersioning" Version="3.7.115" />
2020
<PackageVersion Include="PolySharp" Version="1.15.0" />
21-
<PackageVersion Include="SonarAnalyzer.CSharp" Version="10.7.0.110445" />
21+
<PackageVersion Include="SonarAnalyzer.CSharp" Version="10.10.0.116381" />
2222
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
2323

2424
<!-- Should stay on LTS .NET releases. -->
2525
<PackageVersion Include="System.Formats.Asn1" Version="8.0.2" />
26-
<PackageVersion Include="Testcontainers" Version="4.3.0" />
26+
<PackageVersion Include="Testcontainers" Version="4.5.0" />
2727
</ItemGroup>
2828
</Project>

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "9.0.200",
3+
"version": "9.0.300",
44
"rollForward": "latestFeature"
55
}
66
}

src/Renci.SshNet/Channels/Channel.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,9 @@ protected virtual void OnWindowAdjust(uint bytesToAdd)
378378
/// Called when channel data is received.
379379
/// </summary>
380380
/// <param name="data">The data.</param>
381-
protected virtual void OnData(byte[] data)
381+
protected virtual void OnData(ArraySegment<byte> data)
382382
{
383-
AdjustDataWindow(data);
383+
AdjustDataWindow(data.Count);
384384

385385
DataReceived?.Invoke(this, new ChannelDataEventArgs(LocalChannelNumber, data));
386386
}
@@ -392,7 +392,7 @@ protected virtual void OnData(byte[] data)
392392
/// <param name="dataTypeCode">The data type code.</param>
393393
protected virtual void OnExtendedData(byte[] data, uint dataTypeCode)
394394
{
395-
AdjustDataWindow(data);
395+
AdjustDataWindow(data.Length);
396396

397397
ExtendedDataReceived?.Invoke(this, new ChannelExtendedDataEventArgs(LocalChannelNumber, data, dataTypeCode));
398398
}
@@ -651,7 +651,7 @@ private void OnChannelData(object sender, MessageEventArgs<ChannelDataMessage> e
651651
{
652652
try
653653
{
654-
OnData(e.Message.Data);
654+
OnData(new ArraySegment<byte>(e.Message.Data, e.Message.Offset, e.Message.Size));
655655
}
656656
catch (Exception ex)
657657
{
@@ -768,9 +768,9 @@ private void OnChannelFailure(object sender, MessageEventArgs<ChannelFailureMess
768768
}
769769
}
770770

771-
private void AdjustDataWindow(byte[] messageData)
771+
private void AdjustDataWindow(int count)
772772
{
773-
LocalWindowSize -= (uint)messageData.Length;
773+
LocalWindowSize -= (uint)count;
774774

775775
// Adjust window if window size is too low
776776
if (LocalWindowSize < LocalPacketSize)

src/Renci.SshNet/Channels/ChannelDirectTcpip.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ protected override void Close()
194194
/// Called when channel data is received.
195195
/// </summary>
196196
/// <param name="data">The data.</param>
197-
protected override void OnData(byte[] data)
197+
protected override void OnData(ArraySegment<byte> data)
198198
{
199199
base.OnData(data);
200200

@@ -204,7 +204,7 @@ protected override void OnData(byte[] data)
204204
{
205205
if (_socket.IsConnected())
206206
{
207-
SocketAbstraction.Send(_socket, data, 0, data.Length);
207+
SocketAbstraction.Send(_socket, data.Array, data.Offset, data.Count);
208208
}
209209
}
210210
}

src/Renci.SshNet/Channels/ChannelForwardedTcpip.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,14 @@ protected override void Close()
201201
/// Called when channel data is received.
202202
/// </summary>
203203
/// <param name="data">The data.</param>
204-
protected override void OnData(byte[] data)
204+
protected override void OnData(ArraySegment<byte> data)
205205
{
206206
base.OnData(data);
207207

208208
var socket = _socket;
209209
if (socket.IsConnected())
210210
{
211-
SocketAbstraction.Send(socket, data, 0, data.Length);
211+
SocketAbstraction.Send(socket, data.Array, data.Offset, data.Count);
212212
}
213213
}
214214
}

src/Renci.SshNet/Common/ChannelDataEventArgs.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,22 @@ internal class ChannelDataEventArgs : ChannelEventArgs
1313
/// <param name="channelNumber">Channel number.</param>
1414
/// <param name="data">Channel data.</param>
1515
/// <exception cref="ArgumentNullException"><paramref name="data"/> is <see langword="null"/>.</exception>
16-
public ChannelDataEventArgs(uint channelNumber, byte[] data)
16+
public ChannelDataEventArgs(uint channelNumber, ArraySegment<byte> data)
1717
: base(channelNumber)
1818
{
19-
ThrowHelper.ThrowIfNull(data);
19+
ThrowHelper.ThrowIfNull(data.Array);
2020

2121
Data = data;
2222
}
2323

24+
internal ChannelDataEventArgs(uint channelNumber, byte[] data)
25+
: this(channelNumber, new ArraySegment<byte>(data))
26+
{
27+
}
28+
2429
/// <summary>
2530
/// Gets channel data.
2631
/// </summary>
27-
public byte[] Data { get; }
32+
public ArraySegment<byte> Data { get; }
2833
}
2934
}

src/Renci.SshNet/Common/ChannelExtendedDataEventArgs.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Renci.SshNet.Common
1+
using System;
2+
3+
namespace Renci.SshNet.Common
24
{
35
/// <summary>
46
/// Provides data for <see cref="Channels.Channel.ExtendedDataReceived"/> events.
@@ -12,7 +14,7 @@ internal sealed class ChannelExtendedDataEventArgs : ChannelDataEventArgs
1214
/// <param name="data">Channel data.</param>
1315
/// <param name="dataTypeCode">Channel data type code.</param>
1416
public ChannelExtendedDataEventArgs(uint channelNumber, byte[] data, uint dataTypeCode)
15-
: base(channelNumber, data)
17+
: base(channelNumber, new ArraySegment<byte>(data))
1618
{
1719
DataTypeCode = dataTypeCode;
1820
}

src/Renci.SshNet/Common/SshData.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ protected string ReadString(Encoding encoding = null)
232232
}
233233

234234
/// <summary>
235-
/// Reads next data type as byte array from internal buffer.
235+
/// Reads a length-prefixed byte array from the internal buffer.
236236
/// </summary>
237237
/// <returns>
238238
/// The bytes read.
@@ -242,6 +242,20 @@ protected byte[] ReadBinary()
242242
return _stream.ReadBinary();
243243
}
244244

245+
/// <summary>
246+
/// Reads a length-prefixed byte array from the internal buffer,
247+
/// returned as a view over the buffer.
248+
/// </summary>
249+
/// <remarks>
250+
/// When using this method, consider whether the underlying buffer is shared
251+
/// or reused, and whether the returned <see cref="ArraySegment{T}"/> may
252+
/// exist beyond the lifetime for which it is valid to be used.
253+
/// </remarks>
254+
private protected ArraySegment<byte> ReadBinarySegment()
255+
{
256+
return _stream.ReadBinarySegment();
257+
}
258+
245259
/// <summary>
246260
/// Reads next name-list data type from internal buffer.
247261
/// </summary>

src/Renci.SshNet/ISftpClient.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,21 @@ public interface ISftpClient : IBaseClient
700700
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
701701
SftpFileAttributes GetAttributes(string path);
702702

703+
/// <summary>
704+
/// Gets the <see cref="SftpFileAttributes"/> of the file on the path.
705+
/// </summary>
706+
/// <param name="path">The path to the file.</param>
707+
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to observe.</param>
708+
/// <returns>
709+
/// A <see cref="Task{SftpFileAttributes}"/> that represents the attribute retrieval operation.
710+
/// The task result contains the <see cref="SftpFileAttributes"/> of the file on the path.
711+
/// </returns>
712+
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
713+
/// <exception cref="SshConnectionException">Client is not connected.</exception>
714+
/// <exception cref="SftpPathNotFoundException"><paramref name="path"/> was not found on the remote host.</exception>
715+
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
716+
Task<SftpFileAttributes> GetAttributesAsync(string path, CancellationToken cancellationToken);
717+
703718
/// <summary>
704719
/// Returns the date and time the specified file or directory was last accessed.
705720
/// </summary>

0 commit comments

Comments
 (0)