From d4a1a7e07c998292210a6c09dfd47db9fbdb2e3f Mon Sep 17 00:00:00 2001 From: Marius Thesing Date: Sat, 10 May 2025 11:14:31 +0200 Subject: [PATCH] Drop netstandard2.1 target --- README.md | 2 +- src/Renci.SshNet/Abstractions/SocketExtensions.cs | 8 -------- src/Renci.SshNet/Abstractions/StreamExtensions.cs | 2 +- src/Renci.SshNet/ClientAuthentication.cs | 2 +- src/Renci.SshNet/Common/Extensions.cs | 10 +++++----- src/Renci.SshNet/Common/PipeStream.cs | 6 +++--- src/Renci.SshNet/Common/SshData.cs | 2 +- src/Renci.SshNet/Common/SshDataStream.cs | 6 +++--- src/Renci.SshNet/Connection/ProxyConnector.cs | 6 +++--- .../Messages/Authentication/FailureMessage.cs | 2 +- src/Renci.SshNet/Renci.SshNet.csproj | 2 +- src/Renci.SshNet/ScpClient.cs | 4 ++-- src/Renci.SshNet/Security/Cryptography/EcdsaKey.cs | 2 +- src/Renci.SshNet/Session.cs | 4 ++-- src/Renci.SshNet/Sftp/SftpSession.cs | 8 ++++---- src/Renci.SshNet/SftpClient.cs | 2 +- src/Renci.SshNet/ShellStream.cs | 4 ++-- 17 files changed, 32 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index e801510a1..f1382e365 100644 --- a/README.md +++ b/README.md @@ -176,7 +176,7 @@ OpenSSH certificate authentication is supported for all of the above, e.g. ssh-e **SSH.NET** supports the following target frameworks: * .NETFramework 4.6.2 (and higher) -* .NET Standard 2.0 and 2.1 +* .NET Standard 2.0 * .NET 8 (and higher) ## Building the library diff --git a/src/Renci.SshNet/Abstractions/SocketExtensions.cs b/src/Renci.SshNet/Abstractions/SocketExtensions.cs index 11c875643..a75605065 100644 --- a/src/Renci.SshNet/Abstractions/SocketExtensions.cs +++ b/src/Renci.SshNet/Abstractions/SocketExtensions.cs @@ -93,11 +93,7 @@ public static async Task ConnectAsync(this Socket socket, EndPoint remoteEndpoin { args.RemoteEndPoint = remoteEndpoint; -#if NETSTANDARD2_1 - await using (cancellationToken.Register(o => ((AwaitableSocketAsyncEventArgs)o).SetCancelled(), args, useSynchronizationContext: false).ConfigureAwait(continueOnCapturedContext: false)) -#else using (cancellationToken.Register(o => ((AwaitableSocketAsyncEventArgs)o).SetCancelled(), args, useSynchronizationContext: false)) -#endif { await args.ExecuteAsync(socket.ConnectAsync); } @@ -112,11 +108,7 @@ public static async Task ReceiveAsync(this Socket socket, byte[] buffer, in { args.SetBuffer(buffer, offset, length); -#if NETSTANDARD2_1 - await using (cancellationToken.Register(o => ((AwaitableSocketAsyncEventArgs)o).SetCancelled(), args, useSynchronizationContext: false).ConfigureAwait(continueOnCapturedContext: false)) -#else using (cancellationToken.Register(o => ((AwaitableSocketAsyncEventArgs)o).SetCancelled(), args, useSynchronizationContext: false)) -#endif { await args.ExecuteAsync(socket.ReceiveAsync); } diff --git a/src/Renci.SshNet/Abstractions/StreamExtensions.cs b/src/Renci.SshNet/Abstractions/StreamExtensions.cs index f0785ba9d..ec5ca185a 100644 --- a/src/Renci.SshNet/Abstractions/StreamExtensions.cs +++ b/src/Renci.SshNet/Abstractions/StreamExtensions.cs @@ -1,4 +1,4 @@ -#if NETFRAMEWORK || NETSTANDARD2_0 +#if !NET using System; using System.IO; using System.Threading.Tasks; diff --git a/src/Renci.SshNet/ClientAuthentication.cs b/src/Renci.SshNet/ClientAuthentication.cs index e527a88d5..ad755be82 100644 --- a/src/Renci.SshNet/ClientAuthentication.cs +++ b/src/Renci.SshNet/ClientAuthentication.cs @@ -105,7 +105,7 @@ private bool TryAuthenticate(ISession session, { authenticationException = new SshAuthenticationException(string.Format(CultureInfo.InvariantCulture, "No suitable authentication method found to complete authentication ({0}).", -#if NET || NETSTANDARD2_1 +#if NET string.Join(',', allowedAuthenticationMethods))) #else string.Join(",", allowedAuthenticationMethods))) diff --git a/src/Renci.SshNet/Common/Extensions.cs b/src/Renci.SshNet/Common/Extensions.cs index bc72c70ba..14b80ac74 100644 --- a/src/Renci.SshNet/Common/Extensions.cs +++ b/src/Renci.SshNet/Common/Extensions.cs @@ -50,7 +50,7 @@ internal static ServiceName ToServiceName(this byte[] data) internal static BigInteger ToBigInteger(this ReadOnlySpan data) { -#if NETSTANDARD2_1 || NET +#if NET return new BigInteger(data, isBigEndian: true); #else var reversed = data.ToArray(); @@ -61,7 +61,7 @@ internal static BigInteger ToBigInteger(this ReadOnlySpan data) internal static BigInteger ToBigInteger(this byte[] data) { -#if NETSTANDARD2_1 || NET +#if NET return new BigInteger(data, isBigEndian: true); #else var reversed = new byte[data.Length]; @@ -76,7 +76,7 @@ internal static BigInteger ToBigInteger(this byte[] data) /// public static BigInteger ToBigInteger2(this byte[] data) { -#if NETSTANDARD2_1 || NET +#if NET return new BigInteger(data, isBigEndian: true, isUnsigned: true); #else if ((data[0] & (1 << 7)) != 0) @@ -91,7 +91,7 @@ public static BigInteger ToBigInteger2(this byte[] data) #endif } -#if NETFRAMEWORK || NETSTANDARD2_0 +#if !NET public static byte[] ToByteArray(this BigInteger bigInt, bool isUnsigned = false, bool isBigEndian = false) { var data = bigInt.ToByteArray(); @@ -361,7 +361,7 @@ internal static string Join(this IEnumerable values, string separator) return string.Join(separator, values); } -#if NETFRAMEWORK || NETSTANDARD2_0 +#if !NET internal static bool TryAdd(this Dictionary dictionary, TKey key, TValue value) { if (!dictionary.ContainsKey(key)) diff --git a/src/Renci.SshNet/Common/PipeStream.cs b/src/Renci.SshNet/Common/PipeStream.cs index ae20df1de..49e48b6ee 100644 --- a/src/Renci.SshNet/Common/PipeStream.cs +++ b/src/Renci.SshNet/Common/PipeStream.cs @@ -51,7 +51,7 @@ public override int Read(byte[] buffer, int offset, int count) return Read(buffer.AsSpan(offset, count)); } -#if NETSTANDARD2_1 || NET +#if NET /// public override int Read(Span buffer) #else @@ -99,7 +99,7 @@ public override void Write(byte[] buffer, int offset, int count) } } -#if NETSTANDARD2_1 || NET +#if NET /// public override void Write(ReadOnlySpan buffer) { @@ -157,7 +157,7 @@ public override Task WriteAsync(byte[] buffer, int offset, int count, Cancellati return WriteAsync(buffer.AsMemory(offset, count), cancellationToken).AsTask(); } -#if NETSTANDARD2_1 || NET +#if NET /// public override async ValueTask WriteAsync(ReadOnlyMemory buffer, CancellationToken cancellationToken = default) #else diff --git a/src/Renci.SshNet/Common/SshData.cs b/src/Renci.SshNet/Common/SshData.cs index af1c5ead2..22fc86b54 100644 --- a/src/Renci.SshNet/Common/SshData.cs +++ b/src/Renci.SshNet/Common/SshData.cs @@ -372,7 +372,7 @@ protected void Write(BigInteger data) /// name-list data to write. protected void Write(string[] data) { -#if NET || NETSTANDARD2_1 +#if NET Write(string.Join(',', data), Ascii); #else Write(string.Join(",", data), Ascii); diff --git a/src/Renci.SshNet/Common/SshDataStream.cs b/src/Renci.SshNet/Common/SshDataStream.cs index f2ff82f70..af8be81bc 100644 --- a/src/Renci.SshNet/Common/SshDataStream.cs +++ b/src/Renci.SshNet/Common/SshDataStream.cs @@ -59,7 +59,7 @@ public bool IsEndOfData } } -#if NETFRAMEWORK || NETSTANDARD2_0 +#if !NET private void Write(ReadOnlySpan buffer) { var sharedBuffer = System.Buffers.ArrayPool.Shared.Rent(buffer.Length); @@ -129,7 +129,7 @@ public void Write(string s, Encoding encoding) ThrowHelper.ThrowIfNull(s); ThrowHelper.ThrowIfNull(encoding); -#if NETSTANDARD2_1 || NET +#if NET ReadOnlySpan value = s; var count = encoding.GetByteCount(value); var bytes = count <= 256 ? stackalloc byte[count] : new byte[count]; @@ -220,7 +220,7 @@ public void WriteBinary(byte[] buffer, int offset, int count) /// public BigInteger ReadBigInt() { -#if NETSTANDARD2_1 || NET +#if NET var data = ReadBinarySegment(); return new BigInteger(data, isBigEndian: true); #else diff --git a/src/Renci.SshNet/Connection/ProxyConnector.cs b/src/Renci.SshNet/Connection/ProxyConnector.cs index e76f81127..03f802a04 100644 --- a/src/Renci.SshNet/Connection/ProxyConnector.cs +++ b/src/Renci.SshNet/Connection/ProxyConnector.cs @@ -21,14 +21,14 @@ protected ProxyConnector(ISocketFactory socketFactory) // ToDo: Performs async/sync fallback, true async version should be implemented in derived classes protected virtual -#if NET || NETSTANDARD2_1 +#if NET async #endif Task HandleProxyConnectAsync(IConnectionInfo connectionInfo, Socket socket, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); -#if NET || NETSTANDARD2_1 +#if NET await using (cancellationToken.Register(o => ((Socket)o).Dispose(), socket, useSynchronizationContext: false).ConfigureAwait(continueOnCapturedContext: false)) #else using (cancellationToken.Register(o => ((Socket)o).Dispose(), socket, useSynchronizationContext: false)) @@ -39,7 +39,7 @@ Task HandleProxyConnectAsync(IConnectionInfo connectionInfo, Socket socket, Canc #pragma warning restore MA0042 // Do not use blocking calls in an async method } -#if !NET && !NETSTANDARD2_1 +#if !NET return Task.CompletedTask; #endif } diff --git a/src/Renci.SshNet/Messages/Authentication/FailureMessage.cs b/src/Renci.SshNet/Messages/Authentication/FailureMessage.cs index 24dceed71..bcb4f6b89 100644 --- a/src/Renci.SshNet/Messages/Authentication/FailureMessage.cs +++ b/src/Renci.SshNet/Messages/Authentication/FailureMessage.cs @@ -55,7 +55,7 @@ protected override void LoadData() PartialSuccess = ReadBoolean(); if (PartialSuccess) { -#if NET || NETSTANDARD2_1 +#if NET Message = string.Join(',', AllowedAuthentications); #else Message = string.Join(",", AllowedAuthentications); diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj index a76bbafe2..446865229 100644 --- a/src/Renci.SshNet/Renci.SshNet.csproj +++ b/src/Renci.SshNet/Renci.SshNet.csproj @@ -4,7 +4,7 @@ Renci.SshNet SSH.NET SSH.NET - net462;netstandard2.0;netstandard2.1;net8.0;net9.0 + net462;netstandard2.0;net8.0;net9.0 diff --git a/src/Renci.SshNet/ScpClient.cs b/src/Renci.SshNet/ScpClient.cs index ce9fbffaf..d128d3cc9 100644 --- a/src/Renci.SshNet/ScpClient.cs +++ b/src/Renci.SshNet/ScpClient.cs @@ -670,7 +670,7 @@ private string ReadString(Stream stream) /// The file or directory to upload. private void UploadTimes(IChannelSession channel, Stream input, FileSystemInfo fileOrDirectory) { -#if NET || NETSTANDARD2_1 +#if NET var zeroTime = DateTime.UnixEpoch; #else var zeroTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); @@ -851,7 +851,7 @@ private void InternalDownload(IChannelSession channel, Stream input, FileSystemI var mtime = long.Parse(match.Result("${mtime}"), CultureInfo.InvariantCulture); var atime = long.Parse(match.Result("${atime}"), CultureInfo.InvariantCulture); -#if NET || NETSTANDARD2_1 +#if NET var zeroTime = DateTime.UnixEpoch; #else var zeroTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); diff --git a/src/Renci.SshNet/Security/Cryptography/EcdsaKey.cs b/src/Renci.SshNet/Security/Cryptography/EcdsaKey.cs index f7490383a..f74500d85 100644 --- a/src/Renci.SshNet/Security/Cryptography/EcdsaKey.cs +++ b/src/Renci.SshNet/Security/Cryptography/EcdsaKey.cs @@ -147,7 +147,7 @@ public override BigInteger[] Public Buffer.BlockCopy(qy, 0, q, qx.Length + 1, qy.Length); // returns Curve-Name and x/y as ECPoint -#if NETSTANDARD2_1 || NET +#if NET return new[] { curve, new BigInteger(q, isBigEndian: true) }; #else Array.Reverse(q); diff --git a/src/Renci.SshNet/Session.cs b/src/Renci.SshNet/Session.cs index 800c0d5df..dc252c39c 100644 --- a/src/Renci.SshNet/Session.cs +++ b/src/Renci.SshNet/Session.cs @@ -1326,7 +1326,7 @@ private Message ReceiveMessage(Socket socket) if (_serverMac != null && _serverEtm) { var clientHash = _serverMac.ComputeHash(data, 0, data.Length - serverMacLength); -#if NETSTANDARD2_1 || NET +#if NET if (!CryptographicOperations.FixedTimeEquals(clientHash, new ReadOnlySpan(data, data.Length - serverMacLength, serverMacLength))) #else if (!Org.BouncyCastle.Utilities.Arrays.FixedTimeEquals(serverMacLength, clientHash, 0, data, data.Length - serverMacLength)) @@ -1354,7 +1354,7 @@ private Message ReceiveMessage(Socket socket) if (_serverMac != null && !_serverEtm) { var clientHash = _serverMac.ComputeHash(data, 0, data.Length - serverMacLength); -#if NETSTANDARD2_1 || NET +#if NET if (!CryptographicOperations.FixedTimeEquals(clientHash, new ReadOnlySpan(data, data.Length - serverMacLength, serverMacLength))) #else if (!Org.BouncyCastle.Utilities.Arrays.FixedTimeEquals(serverMacLength, clientHash, 0, data, data.Length - serverMacLength)) diff --git a/src/Renci.SshNet/Sftp/SftpSession.cs b/src/Renci.SshNet/Sftp/SftpSession.cs index de83bd887..ab71a9a03 100644 --- a/src/Renci.SshNet/Sftp/SftpSession.cs +++ b/src/Renci.SshNet/Sftp/SftpSession.cs @@ -135,7 +135,7 @@ public string GetCanonicalPath(string path) if (fullPath.EndsWith("/.", StringComparison.OrdinalIgnoreCase) || fullPath.EndsWith("/..", StringComparison.OrdinalIgnoreCase) || fullPath.Equals("/", StringComparison.OrdinalIgnoreCase) || -#if NET || NETSTANDARD2_1 +#if NET fullPath.IndexOf('/', StringComparison.OrdinalIgnoreCase) < 0) #else fullPath.IndexOf('/') < 0) @@ -146,7 +146,7 @@ public string GetCanonicalPath(string path) var pathParts = fullPath.Split('/'); -#if NET || NETSTANDARD2_1 +#if NET var partialFullPath = string.Join('/', pathParts, 0, pathParts.Length - 1); #else var partialFullPath = string.Join("/", pathParts, 0, pathParts.Length - 1); @@ -206,7 +206,7 @@ public async Task GetCanonicalPathAsync(string path, CancellationToken c if (fullPath.EndsWith("/.", StringComparison.Ordinal) || fullPath.EndsWith("/..", StringComparison.Ordinal) || fullPath.Equals("/", StringComparison.Ordinal) || -#if NET || NETSTANDARD2_1 +#if NET fullPath.IndexOf('/', StringComparison.Ordinal) < 0) #else fullPath.IndexOf('/') < 0) @@ -217,7 +217,7 @@ public async Task GetCanonicalPathAsync(string path, CancellationToken c var pathParts = fullPath.Split('/'); -#if NET || NETSTANDARD2_1 +#if NET var partialFullPath = string.Join('/', pathParts); #else var partialFullPath = string.Join("/", pathParts); diff --git a/src/Renci.SshNet/SftpClient.cs b/src/Renci.SshNet/SftpClient.cs index 50a2e9cbd..a636ad8a2 100644 --- a/src/Renci.SshNet/SftpClient.cs +++ b/src/Renci.SshNet/SftpClient.cs @@ -2308,7 +2308,7 @@ private List InternalListDirectory(string path, SftpListDirectoryAsyn var basePath = fullPath; -#if NET || NETSTANDARD2_1 +#if NET if (!basePath.EndsWith('/')) #else if (!basePath.EndsWith("/", StringComparison.Ordinal)) diff --git a/src/Renci.SshNet/ShellStream.cs b/src/Renci.SshNet/ShellStream.cs index 9a72532c8..d48ee587f 100644 --- a/src/Renci.SshNet/ShellStream.cs +++ b/src/Renci.SshNet/ShellStream.cs @@ -762,7 +762,7 @@ public override int Read(byte[] buffer, int offset, int count) return Read(buffer.AsSpan(offset, count)); } -#if NETSTANDARD2_1 || NET +#if NET /// public override int Read(Span buffer) #else @@ -838,7 +838,7 @@ public override void Write(byte[] buffer, int offset, int count) Write(buffer.AsSpan(offset, count)); } -#if NETSTANDARD2_1 || NET +#if NET /// public override void Write(ReadOnlySpan buffer) #else