Skip to content

Commit 86dc811

Browse files
mus65Rob-Hague
andauthored
Drop net6.0 target (#1580)
* Drop net6.0 target * Update src/Renci.SshNet/Common/TaskToAsyncResult.cs Co-authored-by: Rob Hague <[email protected]> * remove redundant #if for some reason this made the compiler suddenly realize that the plain text variables are unused. * use TargetFrameworkIdentifier this doesn't work in Directory.Build.props, moved it to Directory.Build.targets. * fix null reference warnings in Benchmarks seems like the warnings were (somehow) disabled here before and were fixed by the previous TargetFrameworkIdentifier change. * fix unused plainTextOffset in AesGcmCipher.BclImpl * CI retry * more cosmetics * more * update README * Revert "use TargetFrameworkIdentifier" This reverts commit 076ede1. --------- Co-authored-by: Rob Hague <[email protected]> Co-authored-by: Robert Hague <[email protected]>
1 parent 99ef23c commit 86dc811

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+110
-133
lines changed

Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<!--
3232
Disable nullable warnings on old frameworks because of missing annotations.
3333
-->
34-
<PropertyGroup Condition=" !$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0')) ">
34+
<PropertyGroup Condition=" !$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0')) ">
3535
<NoWarn>$(NoWarn);CS8602;CS8604;CS8777</NoWarn>
3636
</PropertyGroup>
3737

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ Private keys in PuTTY private key format can be encrypted using the following ci
181181
**SSH.NET** supports the following target frameworks:
182182
* .NETFramework 4.6.2 (and higher)
183183
* .NET Standard 2.0 and 2.1
184-
* .NET 6 (and higher)
184+
* .NET 8 (and higher)
185185

186186
## Building the library
187187

Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1+
#if !NET
12
using System.Threading;
23
using System.Threading.Tasks;
34

45
namespace Renci.SshNet.Abstractions
56
{
67
internal static class CancellationTokenSourceExtensions
78
{
8-
#if !NET8_OR_GREATER
99
public static Task CancelAsync(this CancellationTokenSource cancellationTokenSource)
1010
{
1111
cancellationTokenSource.Cancel();
1212
return Task.CompletedTask;
1313
}
14-
#endif
1514
}
1615
}
16+
#endif

src/Renci.SshNet/Abstractions/SocketAbstraction.Async.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if NET6_0_OR_GREATER
1+
#if NET
22

33
using System;
44
using System.Diagnostics;
@@ -47,4 +47,4 @@ static async ValueTask SendAsyncCore(Socket socket, ReadOnlyMemory<byte> data, C
4747
}
4848
}
4949
}
50-
#endif // NET6_0_OR_GREATER
50+
#endif // NET

src/Renci.SshNet/Abstractions/SocketAbstraction.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ public static int Read(Socket socket, byte[] buffer, int offset, int size, TimeS
311311
return totalBytesRead;
312312
}
313313

314-
#if NET6_0_OR_GREATER == false
314+
#if !NET
315315
public static Task<int> ReadAsync(Socket socket, byte[] buffer, CancellationToken cancellationToken)
316316
{
317317
return socket.ReceiveAsync(buffer, 0, buffer.Length, cancellationToken);

src/Renci.SshNet/Abstractions/SocketExtensions.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if !NET6_0_OR_GREATER
1+
#if !NET
22
using System;
33
using System.Net;
44
using System.Net.Sockets;
@@ -93,11 +93,11 @@ public static async Task ConnectAsync(this Socket socket, EndPoint remoteEndpoin
9393
{
9494
args.RemoteEndPoint = remoteEndpoint;
9595

96-
#if NET || NETSTANDARD2_1_OR_GREATER
96+
#if NETSTANDARD2_1
9797
await using (cancellationToken.Register(o => ((AwaitableSocketAsyncEventArgs)o).SetCancelled(), args, useSynchronizationContext: false).ConfigureAwait(continueOnCapturedContext: false))
9898
#else
9999
using (cancellationToken.Register(o => ((AwaitableSocketAsyncEventArgs)o).SetCancelled(), args, useSynchronizationContext: false))
100-
#endif // NET || NETSTANDARD2_1_OR_GREATER
100+
#endif
101101
{
102102
await args.ExecuteAsync(socket.ConnectAsync);
103103
}
@@ -112,11 +112,11 @@ public static async Task<int> ReceiveAsync(this Socket socket, byte[] buffer, in
112112
{
113113
args.SetBuffer(buffer, offset, length);
114114

115-
#if NET || NETSTANDARD2_1_OR_GREATER
115+
#if NETSTANDARD2_1
116116
await using (cancellationToken.Register(o => ((AwaitableSocketAsyncEventArgs)o).SetCancelled(), args, useSynchronizationContext: false).ConfigureAwait(continueOnCapturedContext: false))
117117
#else
118118
using (cancellationToken.Register(o => ((AwaitableSocketAsyncEventArgs)o).SetCancelled(), args, useSynchronizationContext: false))
119-
#endif // NET || NETSTANDARD2_1_OR_GREATER
119+
#endif
120120
{
121121
await args.ExecuteAsync(socket.ReceiveAsync);
122122
}
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
#if !NET && !NETSTANDARD2_1_OR_GREATER
1+
#if NETFRAMEWORK || NETSTANDARD2_0
22
using System.IO;
33
using System.Threading.Tasks;
4-
#endif
54

65
namespace Renci.SshNet.Abstractions
76
{
87
internal static class StreamExtensions
98
{
10-
#if !NET && !NETSTANDARD2_1_OR_GREATER
119
public static ValueTask DisposeAsync(this Stream stream)
1210
{
1311
stream.Dispose();
1412
return default;
1513
}
16-
#endif
1714
}
1815
}
16+
#endif

src/Renci.SshNet/ClientAuthentication.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ private bool TryAuthenticate(ISession session,
105105
{
106106
authenticationException = new SshAuthenticationException(string.Format(CultureInfo.InvariantCulture,
107107
"No suitable authentication method found to complete authentication ({0}).",
108-
#if NET || NETSTANDARD2_1_OR_GREATER
108+
#if NET || NETSTANDARD2_1
109109
string.Join(',', allowedAuthenticationMethods)))
110110
#else
111111
string.Join(",", allowedAuthenticationMethods)))
112-
#endif // NET || NETSTANDARD2_1_OR_GREATER
112+
#endif
113113
;
114114
return false;
115115
}

src/Renci.SshNet/Common/Extensions.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ internal static ServiceName ToServiceName(this byte[] data)
4848

4949
internal static BigInteger ToBigInteger(this byte[] data)
5050
{
51-
#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
51+
#if NETSTANDARD2_1 || NET
5252
return new BigInteger(data, isBigEndian: true);
5353
#else
5454
var reversed = new byte[data.Length];
@@ -62,7 +62,7 @@ internal static BigInteger ToBigInteger(this byte[] data)
6262
/// </summary>
6363
public static BigInteger ToBigInteger2(this byte[] data)
6464
{
65-
#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
65+
#if NETSTANDARD2_1 || NET
6666
return new BigInteger(data, isBigEndian: true, isUnsigned: true);
6767
#else
6868
if ((data[0] & (1 << 7)) != 0)
@@ -95,7 +95,7 @@ public static byte[] ToByteArray(this BigInteger bigInt, bool isUnsigned = false
9595
}
9696
#endif
9797

98-
#if !NET6_0_OR_GREATER
98+
#if !NET
9999
public static long GetBitLength(this BigInteger bigint)
100100
{
101101
// Taken from https://github.com/dotnet/runtime/issues/31308

src/Renci.SshNet/Common/SshData.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -372,11 +372,11 @@ protected void Write(BigInteger data)
372372
/// <param name="data">name-list data to write.</param>
373373
protected void Write(string[] data)
374374
{
375-
#if NET || NETSTANDARD2_1_OR_GREATER
375+
#if NET || NETSTANDARD2_1
376376
Write(string.Join(',', data), Ascii);
377377
#else
378378
Write(string.Join(",", data), Ascii);
379-
#endif // NET || NETSTANDARD2_1_OR_GREATER
379+
#endif
380380
}
381381

382382
/// <summary>

src/Renci.SshNet/Common/SshDataStream.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public void Write(string s, Encoding encoding)
139139
{
140140
ThrowHelper.ThrowIfNull(encoding);
141141

142-
#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
142+
#if NETSTANDARD2_1 || NET
143143
ReadOnlySpan<char> value = s;
144144
var count = encoding.GetByteCount(value);
145145
var bytes = count <= 256 ? stackalloc byte[count] : new byte[count];
@@ -207,7 +207,7 @@ public BigInteger ReadBigInt()
207207
{
208208
var data = ReadBinary();
209209

210-
#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
210+
#if NETSTANDARD2_1 || NET
211211
return new BigInteger(data, isBigEndian: true);
212212
#else
213213
return new BigInteger(data.Reverse());

src/Renci.SshNet/Common/TaskToAsyncResult.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma warning disable
2-
#if !NET8_0_OR_GREATER
3-
// Copied verbatim from https://github.com/dotnet/runtime/blob/78bd7debe6d8b454294c673c9cb969c6b8a14692/src/libraries/Common/src/System/Threading/Tasks/TaskToAsyncResult.cs
2+
#if !NET
3+
// Copied verbatim from https://github.com/dotnet/runtime/blob/261611930d6b436d7c4395450356b624d903d9bf/src/libraries/Common/src/System/Threading/Tasks/TaskToAsyncResult.cs
44

55
// Licensed to the .NET Foundation under one or more agreements.
66
// The .NET Foundation licenses this file to you under the MIT license.
@@ -35,7 +35,7 @@ static class TaskToAsyncResult
3535
/// </remarks>
3636
public static IAsyncResult Begin(Task task, AsyncCallback? callback, object? state)
3737
{
38-
#if NET6_0_OR_GREATER
38+
#if NET
3939
ArgumentNullException.ThrowIfNull(task);
4040
#else
4141
if (task is null)
@@ -72,7 +72,7 @@ public static TResult End<TResult>(IAsyncResult asyncResult) =>
7272
/// <exception cref="ArgumentException"><paramref name="asyncResult"/> was not produced by a call to <see cref="Begin"/>.</exception>
7373
public static Task Unwrap(IAsyncResult asyncResult)
7474
{
75-
#if NET6_0_OR_GREATER
75+
#if NET
7676
ArgumentNullException.ThrowIfNull(asyncResult);
7777
#else
7878
if (asyncResult is null)
@@ -101,7 +101,7 @@ public static Task Unwrap(IAsyncResult asyncResult)
101101
/// </exception>
102102
public static Task<TResult> Unwrap<TResult>(IAsyncResult asyncResult)
103103
{
104-
#if NET6_0_OR_GREATER
104+
#if NET
105105
ArgumentNullException.ThrowIfNull(asyncResult);
106106
#else
107107
if (asyncResult is null)

src/Renci.SshNet/Common/ThrowHelper.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internal static class ThrowHelper
99
{
1010
public static void ThrowObjectDisposedIf(bool condition, object instance)
1111
{
12-
#if NET7_0_OR_GREATER
12+
#if NET
1313
ObjectDisposedException.ThrowIf(condition, instance);
1414
#else
1515
if (condition)
@@ -26,7 +26,7 @@ static void Throw(object? instance)
2626

2727
public static void ThrowIfNull([NotNull] object? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
2828
{
29-
#if NET6_0_OR_GREATER
29+
#if NET
3030
ArgumentNullException.ThrowIfNull(argument, paramName);
3131
#else
3232
if (argument is null)
@@ -44,7 +44,7 @@ static void Throw(string? paramName)
4444

4545
public static void ThrowIfNullOrWhiteSpace([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
4646
{
47-
#if NET8_0_OR_GREATER
47+
#if NET
4848
ArgumentException.ThrowIfNullOrWhiteSpace(argument, paramName);
4949
#else
5050
if (string.IsNullOrWhiteSpace(argument))
@@ -63,7 +63,7 @@ static void Throw(string? argument, string? paramName)
6363

6464
public static void ThrowIfNullOrEmpty([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
6565
{
66-
#if NET7_0_OR_GREATER
66+
#if NET
6767
ArgumentException.ThrowIfNullOrEmpty(argument, paramName);
6868
#else
6969
if (string.IsNullOrEmpty(argument))

src/Renci.SshNet/Compression/Zlib.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.IO;
2-
#if NET6_0_OR_GREATER
2+
#if NET
33
using System.IO.Compression;
44
#else
55
using Org.BouncyCastle.Utilities.Zlib;
@@ -14,7 +14,7 @@ namespace Renci.SshNet.Compression
1414
public class Zlib : Compressor
1515
#pragma warning restore CA1724 // Type names should not match namespaces
1616
{
17-
#if NET6_0_OR_GREATER
17+
#if NET
1818
private readonly ZLibStream _compressor;
1919
private readonly ZLibStream _decompressor;
2020
#else
@@ -45,7 +45,7 @@ protected Zlib(bool delayedCompression)
4545
_compressorStream = new MemoryStream();
4646
_decompressorStream = new MemoryStream();
4747

48-
#if NET6_0_OR_GREATER
48+
#if NET
4949
_compressor = new ZLibStream(_compressorStream, CompressionMode.Compress);
5050
_decompressor = new ZLibStream(_decompressorStream, CompressionMode.Decompress);
5151
#else
@@ -74,7 +74,7 @@ protected override byte[] CompressCore(byte[] data, int offset, int length)
7474
/// <inheritdoc/>
7575
protected override byte[] DecompressCore(byte[] data, int offset, int length)
7676
{
77-
#if NET6_0_OR_GREATER
77+
#if NET
7878
_decompressorStream.Write(data, offset, length);
7979
_decompressorStream.Position = 0;
8080

src/Renci.SshNet/Connection/HttpConnector.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ internal sealed partial class HttpConnector : ProxyConnector
3434
private const string HttpResponsePattern = @"HTTP/(?<version>\d[.]\d) (?<statusCode>\d{3}) (?<reasonPhrase>.+)$";
3535
private const string HttpHeaderPattern = @"(?<fieldName>[^\[\]()<>@,;:\""/?={} \t]+):(?<fieldValue>.+)?";
3636

37-
#if NET7_0_OR_GREATER
37+
#if NET
3838
private static readonly Regex HttpResponseRegex = GetHttpResponseRegex();
3939
private static readonly Regex HttpHeaderRegex = GetHttpHeaderRegex();
4040

src/Renci.SshNet/Connection/ProtocolVersionExchange.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal sealed partial class ProtocolVersionExchange : IProtocolVersionExchange
2424
private const byte Null = 0x00;
2525
private const string ServerVersionPattern = "^SSH-(?<protoversion>[^-]+)-(?<softwareversion>.*?)([ ](?<comments>.+))?$";
2626

27-
#if NET7_0_OR_GREATER
27+
#if NET
2828
private static readonly Regex ServerVersionRegex = GetServerVersionRegex();
2929

3030
[GeneratedRegex(ServerVersionPattern, RegexOptions.ExplicitCapture)]
@@ -89,11 +89,11 @@ public async Task<SshIdentification> StartAsync(string clientVersion, Socket soc
8989
{
9090
// Immediately send the identification string since the spec states both sides MUST send an identification string
9191
// when the connection has been established
92-
#if NET6_0_OR_GREATER
92+
#if NET
9393
await SocketAbstraction.SendAsync(socket, Encoding.UTF8.GetBytes(clientVersion + "\x0D\x0A"), cancellationToken).ConfigureAwait(false);
9494
#else
9595
SocketAbstraction.Send(socket, Encoding.UTF8.GetBytes(clientVersion + "\x0D\x0A"));
96-
#endif // NET6_0_OR_GREATER
96+
#endif // NET
9797

9898
var bytesReceived = new List<byte>();
9999

src/Renci.SshNet/Connection/ProxyConnector.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,27 @@ protected ProxyConnector(ISocketFactory socketFactory)
2121

2222
// ToDo: Performs async/sync fallback, true async version should be implemented in derived classes
2323
protected virtual
24-
#if NET || NETSTANDARD2_1_OR_GREATER
24+
#if NET || NETSTANDARD2_1
2525
async
26-
#endif // NET || NETSTANDARD2_1_OR_GREATER
26+
#endif
2727
Task HandleProxyConnectAsync(IConnectionInfo connectionInfo, Socket socket, CancellationToken cancellationToken)
2828
{
2929
cancellationToken.ThrowIfCancellationRequested();
3030

31-
#if NET || NETSTANDARD2_1_OR_GREATER
31+
#if NET || NETSTANDARD2_1
3232
await using (cancellationToken.Register(o => ((Socket)o).Dispose(), socket, useSynchronizationContext: false).ConfigureAwait(continueOnCapturedContext: false))
3333
#else
3434
using (cancellationToken.Register(o => ((Socket)o).Dispose(), socket, useSynchronizationContext: false))
35-
#endif // NET || NETSTANDARD2_1_OR_GREATER
35+
#endif
3636
{
3737
#pragma warning disable MA0042 // Do not use blocking calls in an async method; false positive caused by https://github.com/meziantou/Meziantou.Analyzer/issues/613
3838
HandleProxyConnect(connectionInfo, socket);
3939
#pragma warning restore MA0042 // Do not use blocking calls in an async method
4040
}
4141

42-
#if !NET && !NETSTANDARD2_1_OR_GREATER
42+
#if !NET && !NETSTANDARD2_1
4343
return Task.CompletedTask;
44-
#endif // !NET && !NETSTANDARD2_1_OR_GREATER
44+
#endif
4545
}
4646

4747
/// <summary>

src/Renci.SshNet/Messages/Authentication/FailureMessage.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ protected override void LoadData()
5555
PartialSuccess = ReadBoolean();
5656
if (PartialSuccess)
5757
{
58-
#if NET || NETSTANDARD2_1_OR_GREATER
58+
#if NET || NETSTANDARD2_1
5959
Message = string.Join(',', AllowedAuthentications);
6060
#else
6161
Message = string.Join(",", AllowedAuthentications);
62-
#endif // NET || NETSTANDARD2_1_OR_GREATER
62+
#endif
6363
}
6464
}
6565

src/Renci.SshNet/Netconf/NetConfSession.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal sealed partial class NetConfSession : SubsystemSession, INetConfSession
2121
private StringBuilder _rpcReply = new StringBuilder();
2222
private int _messageId;
2323

24-
#if NET7_0_OR_GREATER
24+
#if NET
2525
private static readonly Regex LengthRegex = GetLengthRegex();
2626
private static readonly Regex ReplyRegex = GetReplyRegex();
2727

@@ -181,11 +181,11 @@ protected override void OnDataReceived(byte[] data)
181181
position += match.Index + match.Length + fractionLength;
182182
}
183183

184-
#if NET7_0_OR_GREATER
184+
#if NET
185185
if (ReplyRegex.IsMatch(chunk.AsSpan(position)))
186186
#else
187187
if (ReplyRegex.IsMatch(chunk.Substring(position)))
188-
#endif // NET7_0_OR_GREATER
188+
#endif // NET
189189
{
190190
_ = _rpcReplyReceived.Set();
191191
}

0 commit comments

Comments
 (0)