From 63890fff18ed2c6e5eefdda0014f8d412bc7afa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Nag=C3=B3rski?= Date: Mon, 8 May 2023 10:19:34 +0200 Subject: [PATCH 01/23] Use always FEATURE_REGEX_COMPILE --- src/Renci.SshNet/Connection/ProtocolVersionExchange.cs | 4 ---- src/Renci.SshNet/PrivateKeyFile.cs | 5 +---- src/Renci.SshNet/Renci.SshNet.csproj | 2 +- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/Renci.SshNet/Connection/ProtocolVersionExchange.cs b/src/Renci.SshNet/Connection/ProtocolVersionExchange.cs index 4e6957c10..469b1b768 100644 --- a/src/Renci.SshNet/Connection/ProtocolVersionExchange.cs +++ b/src/Renci.SshNet/Connection/ProtocolVersionExchange.cs @@ -24,11 +24,7 @@ internal class ProtocolVersionExchange : IProtocolVersionExchange { private const byte Null = 0x00; -#if FEATURE_REGEX_COMPILE private static readonly Regex ServerVersionRe = new Regex("^SSH-(?[^-]+)-(?.+?)([ ](?.+))?$", RegexOptions.Compiled); -#else - private static readonly Regex ServerVersionRe = new Regex("^SSH-(?[^-]+)-(?.+?)([ ](?.+))?$"); -#endif /// /// Performs the SSH protocol version exchange. diff --git a/src/Renci.SshNet/PrivateKeyFile.cs b/src/Renci.SshNet/PrivateKeyFile.cs index f29b3e958..65a311569 100644 --- a/src/Renci.SshNet/PrivateKeyFile.cs +++ b/src/Renci.SshNet/PrivateKeyFile.cs @@ -66,11 +66,8 @@ namespace Renci.SshNet public class PrivateKeyFile : IPrivateKeySource, IDisposable { private static readonly Regex PrivateKeyRegex = new Regex(@"^-+ *BEGIN (?\w+( \w+)*) PRIVATE KEY *-+\r?\n((Proc-Type: 4,ENCRYPTED\r?\nDEK-Info: (?[A-Z0-9-]+),(?[A-F0-9]+)\r?\n\r?\n)|(Comment: ""?[^\r\n]*""?\r?\n))?(?([a-zA-Z0-9/+=]{1,80}\r?\n)+)-+ *END \k PRIVATE KEY *-+", -#if FEATURE_REGEX_COMPILE RegexOptions.Compiled | RegexOptions.Multiline); -#else - RegexOptions.Multiline); -#endif + private Key _key; diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj index d9399877b..99dbb2241 100644 --- a/src/Renci.SshNet/Renci.SshNet.csproj +++ b/src/Renci.SshNet/Renci.SshNet.csproj @@ -11,7 +11,7 @@ - FEATURE_STRINGBUILDER_CLEAR;FEATURE_HASHALGORITHM_DISPOSE;FEATURE_REGEX_COMPILE;FEATURE_BINARY_SERIALIZATION;FEATURE_RNG_CREATE;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_SELECT;FEATURE_SOCKET_POLL;FEATURE_SOCKET_DISPOSE;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_DIAGNOSTICS_TRACESOURCE;FEATURE_ENCODING_ASCII;FEATURE_ECDSA;FEATURE_TAP + FEATURE_STRINGBUILDER_CLEAR;FEATURE_HASHALGORITHM_DISPOSE;FEATURE_BINARY_SERIALIZATION;FEATURE_RNG_CREATE;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_SELECT;FEATURE_SOCKET_POLL;FEATURE_SOCKET_DISPOSE;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_DIAGNOSTICS_TRACESOURCE;FEATURE_ENCODING_ASCII;FEATURE_ECDSA;FEATURE_TAP From c24c4f5112bb6fc4ec28d4bfcef3032a5dbae772 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Nag=C3=B3rski?= Date: Mon, 8 May 2023 10:38:23 +0200 Subject: [PATCH 02/23] Remove FEATURE_STRINGBUILDER_CLEAR --- src/Renci.SshNet/Common/Extensions.cs | 12 ------------ src/Renci.SshNet/Renci.SshNet.csproj | 4 ++-- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/Renci.SshNet/Common/Extensions.cs b/src/Renci.SshNet/Common/Extensions.cs index 17d72d7fb..46b219a1f 100644 --- a/src/Renci.SshNet/Common/Extensions.cs +++ b/src/Renci.SshNet/Common/Extensions.cs @@ -350,17 +350,5 @@ internal static void Dispose(this System.Security.Cryptography.HashAlgorithm alg algorithm.Clear(); } #endif // FEATURE_HASHALGORITHM_DISPOSE - -#if !FEATURE_STRINGBUILDER_CLEAR - /// - /// Clears the contents of the string builder. - /// - /// The to clear. - public static void Clear(this StringBuilder value) - { - value.Length = 0; - value.Capacity = 16; - } -#endif // !FEATURE_STRINGBUILDER_CLEAR } } diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj index 99dbb2241..766abee2c 100644 --- a/src/Renci.SshNet/Renci.SshNet.csproj +++ b/src/Renci.SshNet/Renci.SshNet.csproj @@ -11,7 +11,7 @@ - FEATURE_STRINGBUILDER_CLEAR;FEATURE_HASHALGORITHM_DISPOSE;FEATURE_BINARY_SERIALIZATION;FEATURE_RNG_CREATE;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_SELECT;FEATURE_SOCKET_POLL;FEATURE_SOCKET_DISPOSE;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_DIAGNOSTICS_TRACESOURCE;FEATURE_ENCODING_ASCII;FEATURE_ECDSA;FEATURE_TAP + FEATURE_HASHALGORITHM_DISPOSE;FEATURE_BINARY_SERIALIZATION;FEATURE_RNG_CREATE;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_SELECT;FEATURE_SOCKET_POLL;FEATURE_SOCKET_DISPOSE;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_DIAGNOSTICS_TRACESOURCE;FEATURE_ENCODING_ASCII;FEATURE_ECDSA;FEATURE_TAP @@ -19,6 +19,6 @@ - FEATURE_STRINGBUILDER_CLEAR;FEATURE_HASHALGORITHM_DISPOSE;FEATURE_ENCODING_ASCII;FEATURE_DIAGNOSTICS_TRACESOURCE;FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_MEMORYSTREAM_TRYGETBUFFER;FEATURE_RNG_CREATE;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_SELECT;FEATURE_SOCKET_POLL;FEATURE_SOCKET_DISPOSE;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_ECDSA;FEATURE_TAP + FEATURE_HASHALGORITHM_DISPOSE;FEATURE_ENCODING_ASCII;FEATURE_DIAGNOSTICS_TRACESOURCE;FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_MEMORYSTREAM_TRYGETBUFFER;FEATURE_RNG_CREATE;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_SELECT;FEATURE_SOCKET_POLL;FEATURE_SOCKET_DISPOSE;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_ECDSA;FEATURE_TAP From d01d47cde8712a426953d78294ed7a88124a8136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Nag=C3=B3rski?= Date: Mon, 8 May 2023 10:40:04 +0200 Subject: [PATCH 03/23] Remove FEATURE_HASHALGORITHM_DISPOSE --- src/Renci.SshNet/Common/Extensions.cs | 18 ------------------ src/Renci.SshNet/Renci.SshNet.csproj | 4 ++-- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/src/Renci.SshNet/Common/Extensions.cs b/src/Renci.SshNet/Common/Extensions.cs index 46b219a1f..9b603ba89 100644 --- a/src/Renci.SshNet/Common/Extensions.cs +++ b/src/Renci.SshNet/Common/Extensions.cs @@ -5,9 +5,6 @@ using System.Net; using System.Net.Sockets; using System.Text; -#if !FEATURE_WAITHANDLE_DISPOSE -using System.Threading; -#endif // !FEATURE_WAITHANDLE_DISPOSE using Renci.SshNet.Abstractions; using Renci.SshNet.Messages; @@ -335,20 +332,5 @@ internal static void Dispose(this WaitHandle handle) handle.Close(); } #endif // !FEATURE_WAITHANDLE_DISPOSE - -#if !FEATURE_HASHALGORITHM_DISPOSE - /// - /// Disposes the specified algorithm. - /// - /// The algorithm. - [DebuggerNonUserCode] - internal static void Dispose(this System.Security.Cryptography.HashAlgorithm algorithm) - { - if (algorithm == null) - throw new NullReferenceException(); - - algorithm.Clear(); - } -#endif // FEATURE_HASHALGORITHM_DISPOSE } } diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj index 766abee2c..df32576cc 100644 --- a/src/Renci.SshNet/Renci.SshNet.csproj +++ b/src/Renci.SshNet/Renci.SshNet.csproj @@ -11,7 +11,7 @@ - FEATURE_HASHALGORITHM_DISPOSE;FEATURE_BINARY_SERIALIZATION;FEATURE_RNG_CREATE;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_SELECT;FEATURE_SOCKET_POLL;FEATURE_SOCKET_DISPOSE;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_DIAGNOSTICS_TRACESOURCE;FEATURE_ENCODING_ASCII;FEATURE_ECDSA;FEATURE_TAP + FEATURE_BINARY_SERIALIZATION;FEATURE_RNG_CREATE;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_SELECT;FEATURE_SOCKET_POLL;FEATURE_SOCKET_DISPOSE;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_DIAGNOSTICS_TRACESOURCE;FEATURE_ENCODING_ASCII;FEATURE_ECDSA;FEATURE_TAP @@ -19,6 +19,6 @@ - FEATURE_HASHALGORITHM_DISPOSE;FEATURE_ENCODING_ASCII;FEATURE_DIAGNOSTICS_TRACESOURCE;FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_MEMORYSTREAM_TRYGETBUFFER;FEATURE_RNG_CREATE;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_SELECT;FEATURE_SOCKET_POLL;FEATURE_SOCKET_DISPOSE;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_ECDSA;FEATURE_TAP + FEATURE_ENCODING_ASCII;FEATURE_DIAGNOSTICS_TRACESOURCE;FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_MEMORYSTREAM_TRYGETBUFFER;FEATURE_RNG_CREATE;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_SELECT;FEATURE_SOCKET_POLL;FEATURE_SOCKET_DISPOSE;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_ECDSA;FEATURE_TAP From 7939c7eadcd4c0a8f7a92d3823fd6206398d1ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Nag=C3=B3rski?= Date: Mon, 8 May 2023 10:42:06 +0200 Subject: [PATCH 04/23] Remove FEATURE_ENCODING_ASCII --- src/Renci.SshNet/Common/ASCIIEncoding.cs | 167 ------------------ src/Renci.SshNet/Common/PacketDump.cs | 8 +- src/Renci.SshNet/Common/SshData.cs | 5 +- .../Connection/Socks4Connector.cs | 4 - src/Renci.SshNet/Renci.SshNet.csproj | 4 +- 5 files changed, 5 insertions(+), 183 deletions(-) delete mode 100644 src/Renci.SshNet/Common/ASCIIEncoding.cs diff --git a/src/Renci.SshNet/Common/ASCIIEncoding.cs b/src/Renci.SshNet/Common/ASCIIEncoding.cs deleted file mode 100644 index f41c49de8..000000000 --- a/src/Renci.SshNet/Common/ASCIIEncoding.cs +++ /dev/null @@ -1,167 +0,0 @@ -#if !FEATURE_ENCODING_ASCII - -using System; -using System.Text; - -namespace Renci.SshNet.Common -{ - /// - /// Implementation of ASCII Encoding - /// - public class ASCIIEncoding : Encoding - { - private readonly char _fallbackChar; - - private static readonly char[] ByteToChar; - - static ASCIIEncoding() - { - if (ByteToChar == null) - { - ByteToChar = new char[128]; - var ch = '\0'; - for (byte i = 0; i < 128; i++) - { - ByteToChar[i] = ch++; - } - } - } - - /// - /// Initializes a new instance of the class. - /// - public ASCIIEncoding() - { - _fallbackChar = '?'; - } - - /// - /// Calculates the number of bytes produced by encoding a set of characters from the specified character array. - /// - /// The character array containing the set of characters to encode. - /// The index of the first character to encode. - /// The number of characters to encode. - /// - /// The number of bytes produced by encoding the specified characters. - /// - /// is null. - /// or is less than zero.-or- and do not denote a valid range in . - public override int GetByteCount(char[] chars, int index, int count) - { - return count; - } - - /// - /// Encodes a set of characters from the specified character array into the specified byte array. - /// - /// The character array containing the set of characters to encode. - /// The index of the first character to encode. - /// The number of characters to encode. - /// The byte array to contain the resulting sequence of bytes. - /// The index at which to start writing the resulting sequence of bytes. - /// - /// The actual number of bytes written into . - /// - /// is null.-or- is null. - /// or or is less than zero.-or- and do not denote a valid range in .-or- is not a valid index in . - /// does not have enough capacity from to the end of the array to accommodate the resulting bytes. - public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) - { - for (var i = 0; i < charCount && i < chars.Length; i++) - { - var b = (byte)chars[i + charIndex]; - - if (b > 127) - b = (byte) _fallbackChar; - - bytes[i + byteIndex] = b; - } - return charCount; - } - - /// - /// Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. - /// - /// The byte array containing the sequence of bytes to decode. - /// The index of the first byte to decode. - /// The number of bytes to decode. - /// - /// The number of characters produced by decoding the specified sequence of bytes. - /// - /// is null. - /// or is less than zero.-or- and do not denote a valid range in . - public override int GetCharCount(byte[] bytes, int index, int count) - { - return count; - } - - /// - /// Decodes a sequence of bytes from the specified byte array into the specified character array. - /// - /// The byte array containing the sequence of bytes to decode. - /// The index of the first byte to decode. - /// The number of bytes to decode. - /// The character array to contain the resulting set of characters. - /// The index at which to start writing the resulting set of characters. - /// - /// The actual number of characters written into . - /// - /// is null.-or- is null. - /// or or is less than zero.-or- and do not denote a valid range in .-or- is not a valid index in . - /// does not have enough capacity from to the end of the array to accommodate the resulting characters. - public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) - { - for (var i = 0; i < byteCount; i++) - { - var b = bytes[i + byteIndex]; - char ch; - - if (b > 127) - { - ch = _fallbackChar; - } - else - { - ch = ByteToChar[b]; - } - - chars[i + charIndex] = ch; - } - return byteCount; - } - - /// - /// Calculates the maximum number of bytes produced by encoding the specified number of characters. - /// - /// The number of characters to encode. - /// - /// The maximum number of bytes produced by encoding the specified number of characters. - /// - /// is less than zero. - public override int GetMaxByteCount(int charCount) - { - if (charCount < 0) - throw new ArgumentOutOfRangeException("charCount", "Non-negative number required."); - - return charCount + 1; - } - - /// - /// Calculates the maximum number of characters produced by decoding the specified number of bytes. - /// - /// The number of bytes to decode. - /// - /// The maximum number of characters produced by decoding the specified number of bytes. - /// - /// is less than zero. - public override int GetMaxCharCount(int byteCount) - { - if (byteCount < 0) - throw new ArgumentOutOfRangeException("byteCount", "Non-negative number required."); - - return byteCount; - } - } -} - -#endif // !FEATURE_ENCODING_ASCII \ No newline at end of file diff --git a/src/Renci.SshNet/Common/PacketDump.cs b/src/Renci.SshNet/Common/PacketDump.cs index 7b50582cb..cd68549d6 100644 --- a/src/Renci.SshNet/Common/PacketDump.cs +++ b/src/Renci.SshNet/Common/PacketDump.cs @@ -79,13 +79,9 @@ private static string AsHex(byte[] data, int length) private static string AsAscii(byte[] data, int length) { -#if FEATURE_ENCODING_ASCII - var encoding = Encoding.ASCII; -#else - var encoding = new ASCIIEncoding(); -#endif + var encoding = Encoding.ASCII; - var ascii = new StringBuilder(); + var ascii = new StringBuilder(); const char dot = '.'; for (var i = 0; i < length; i++) diff --git a/src/Renci.SshNet/Common/SshData.cs b/src/Renci.SshNet/Common/SshData.cs index 8e4eca406..844bace7a 100644 --- a/src/Renci.SshNet/Common/SshData.cs +++ b/src/Renci.SshNet/Common/SshData.cs @@ -11,11 +11,8 @@ public abstract class SshData { internal const int DefaultCapacity = 64; -#if FEATURE_ENCODING_ASCII internal static readonly Encoding Ascii = Encoding.ASCII; -#else - internal static readonly Encoding Ascii = new ASCIIEncoding(); -#endif + internal static readonly Encoding Utf8 = Encoding.UTF8; private SshDataStream _stream; diff --git a/src/Renci.SshNet/Connection/Socks4Connector.cs b/src/Renci.SshNet/Connection/Socks4Connector.cs index ccf4e1456..d507872c6 100644 --- a/src/Renci.SshNet/Connection/Socks4Connector.cs +++ b/src/Renci.SshNet/Connection/Socks4Connector.cs @@ -125,11 +125,7 @@ private static byte[] GetProxyUserBytes(string proxyUser) return Array.Empty; } -#if FEATURE_ENCODING_ASCII return Encoding.ASCII.GetBytes(proxyUser); -#else - return new ASCIIEncoding().GetBytes(proxyUser); -#endif } } } diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj index df32576cc..0e02e1755 100644 --- a/src/Renci.SshNet/Renci.SshNet.csproj +++ b/src/Renci.SshNet/Renci.SshNet.csproj @@ -11,7 +11,7 @@ - FEATURE_BINARY_SERIALIZATION;FEATURE_RNG_CREATE;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_SELECT;FEATURE_SOCKET_POLL;FEATURE_SOCKET_DISPOSE;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_DIAGNOSTICS_TRACESOURCE;FEATURE_ENCODING_ASCII;FEATURE_ECDSA;FEATURE_TAP + FEATURE_BINARY_SERIALIZATION;FEATURE_RNG_CREATE;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_SELECT;FEATURE_SOCKET_POLL;FEATURE_SOCKET_DISPOSE;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_DIAGNOSTICS_TRACESOURCE;FEATURE_ECDSA;FEATURE_TAP @@ -19,6 +19,6 @@ - FEATURE_ENCODING_ASCII;FEATURE_DIAGNOSTICS_TRACESOURCE;FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_MEMORYSTREAM_TRYGETBUFFER;FEATURE_RNG_CREATE;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_SELECT;FEATURE_SOCKET_POLL;FEATURE_SOCKET_DISPOSE;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_ECDSA;FEATURE_TAP + FEATURE_DIAGNOSTICS_TRACESOURCE;FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_MEMORYSTREAM_TRYGETBUFFER;FEATURE_RNG_CREATE;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_SELECT;FEATURE_SOCKET_POLL;FEATURE_SOCKET_DISPOSE;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_ECDSA;FEATURE_TAP From 7cb38a5d0a22a63d62d0c91560dcea05f775655a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Nag=C3=B3rski?= Date: Mon, 8 May 2023 10:46:54 +0200 Subject: [PATCH 05/23] Remove FEATURE_DIAGNOSTICS_TRACESOURCE --- src/Renci.SshNet/Abstractions/DiagnosticAbstraction.cs | 7 ------- src/Renci.SshNet/Renci.SshNet.csproj | 4 ++-- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/Renci.SshNet/Abstractions/DiagnosticAbstraction.cs b/src/Renci.SshNet/Abstractions/DiagnosticAbstraction.cs index 6fc1308ee..16ee1c0ab 100644 --- a/src/Renci.SshNet/Abstractions/DiagnosticAbstraction.cs +++ b/src/Renci.SshNet/Abstractions/DiagnosticAbstraction.cs @@ -1,14 +1,10 @@ using System.Diagnostics; -#if FEATURE_DIAGNOSTICS_TRACESOURCE using System.Threading; -#endif // FEATURE_DIAGNOSTICS_TRACESOURCE namespace Renci.SshNet.Abstractions { internal static class DiagnosticAbstraction { -#if FEATURE_DIAGNOSTICS_TRACESOURCE - private static readonly SourceSwitch SourceSwitch = new SourceSwitch("SshNetSwitch"); public static bool IsEnabled(TraceEventType traceEventType) @@ -22,14 +18,11 @@ public static bool IsEnabled(TraceEventType traceEventType) #else new TraceSource("SshNet.Logging"); #endif // DEBUG -#endif // FEATURE_DIAGNOSTICS_TRACESOURCE [Conditional("DEBUG")] public static void Log(string text) { -#if FEATURE_DIAGNOSTICS_TRACESOURCE Loggging.TraceEvent(TraceEventType.Verbose, Thread.CurrentThread.ManagedThreadId, text); -#endif // FEATURE_DIAGNOSTICS_TRACESOURCE } } } diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj index 0e02e1755..c3cef3d0d 100644 --- a/src/Renci.SshNet/Renci.SshNet.csproj +++ b/src/Renci.SshNet/Renci.SshNet.csproj @@ -11,7 +11,7 @@ - FEATURE_BINARY_SERIALIZATION;FEATURE_RNG_CREATE;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_SELECT;FEATURE_SOCKET_POLL;FEATURE_SOCKET_DISPOSE;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_DIAGNOSTICS_TRACESOURCE;FEATURE_ECDSA;FEATURE_TAP + FEATURE_BINARY_SERIALIZATION;FEATURE_RNG_CREATE;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_SELECT;FEATURE_SOCKET_POLL;FEATURE_SOCKET_DISPOSE;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_ECDSA;FEATURE_TAP @@ -19,6 +19,6 @@ - FEATURE_DIAGNOSTICS_TRACESOURCE;FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_MEMORYSTREAM_TRYGETBUFFER;FEATURE_RNG_CREATE;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_SELECT;FEATURE_SOCKET_POLL;FEATURE_SOCKET_DISPOSE;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_ECDSA;FEATURE_TAP + FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_MEMORYSTREAM_TRYGETBUFFER;FEATURE_RNG_CREATE;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_SELECT;FEATURE_SOCKET_POLL;FEATURE_SOCKET_DISPOSE;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_ECDSA;FEATURE_TAP From 4999b11f6252c3bff2b82680078b30bf59ed71f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Nag=C3=B3rski?= Date: Mon, 8 May 2023 10:50:38 +0200 Subject: [PATCH 06/23] Remove FEATURE_MEMORYSTREAM_GETBUFFER and FEATURE_MEMORYSTREAM_TRYGETBUFFER --- src/Renci.SshNet/Common/SshDataStream.cs | 6 ------ src/Renci.SshNet/Renci.SshNet.csproj | 4 ++-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/Renci.SshNet/Common/SshDataStream.cs b/src/Renci.SshNet/Common/SshDataStream.cs index 010800c3e..0e024491c 100644 --- a/src/Renci.SshNet/Common/SshDataStream.cs +++ b/src/Renci.SshNet/Common/SshDataStream.cs @@ -252,13 +252,7 @@ public override byte[] ToArray() { if (Capacity == Length) { -#if FEATURE_MEMORYSTREAM_GETBUFFER return GetBuffer(); -#elif FEATURE_MEMORYSTREAM_TRYGETBUFFER - ArraySegment buffer; - if (TryGetBuffer(out buffer)) - return buffer.Array; -#endif } return base.ToArray(); } diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj index c3cef3d0d..bd940849f 100644 --- a/src/Renci.SshNet/Renci.SshNet.csproj +++ b/src/Renci.SshNet/Renci.SshNet.csproj @@ -11,7 +11,7 @@ - FEATURE_BINARY_SERIALIZATION;FEATURE_RNG_CREATE;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_SELECT;FEATURE_SOCKET_POLL;FEATURE_SOCKET_DISPOSE;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_ECDSA;FEATURE_TAP + FEATURE_BINARY_SERIALIZATION;FEATURE_RNG_CREATE;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_SELECT;FEATURE_SOCKET_POLL;FEATURE_SOCKET_DISPOSE;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160;FEATURE_ECDSA;FEATURE_TAP @@ -19,6 +19,6 @@ - FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_MEMORYSTREAM_TRYGETBUFFER;FEATURE_RNG_CREATE;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_SELECT;FEATURE_SOCKET_POLL;FEATURE_SOCKET_DISPOSE;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_ECDSA;FEATURE_TAP + FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_RNG_CREATE;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_SELECT;FEATURE_SOCKET_POLL;FEATURE_SOCKET_DISPOSE;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_ECDSA;FEATURE_TAP From 4e5af008511ec88b0f322bcd90b05b9fe5f47f35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Nag=C3=B3rski?= Date: Mon, 8 May 2023 10:54:24 +0200 Subject: [PATCH 07/23] Remove FEATURE_RNG_CREATE --- .../Abstractions/CryptoAbstraction.cs | 18 ------------------ src/Renci.SshNet/Renci.SshNet.csproj | 4 ++-- .../crypto/prng/CryptoApiRandomGenerator.cs | 10 ---------- .../Security/Cryptography/Bcrypt.cs | 8 ++------ 4 files changed, 4 insertions(+), 36 deletions(-) diff --git a/src/Renci.SshNet/Abstractions/CryptoAbstraction.cs b/src/Renci.SshNet/Abstractions/CryptoAbstraction.cs index ff9e50a52..eb2c3c3d6 100644 --- a/src/Renci.SshNet/Abstractions/CryptoAbstraction.cs +++ b/src/Renci.SshNet/Abstractions/CryptoAbstraction.cs @@ -5,9 +5,7 @@ namespace Renci.SshNet.Abstractions { internal static class CryptoAbstraction { -#if FEATURE_RNG_CREATE || FEATURE_RNG_CSP private static readonly System.Security.Cryptography.RandomNumberGenerator Randomizer = CreateRandomNumberGenerator(); -#endif /// /// Generates a array of the specified length, and fills it with a @@ -31,29 +29,13 @@ public static byte[] GenerateRandom(int length) /// public static void GenerateRandom(byte[] data) { -#if FEATURE_RNG_CREATE || FEATURE_RNG_CSP Randomizer.GetBytes(data); -#else - if(data == null) - throw new ArgumentNullException("data"); - - var buffer = Windows.Security.Cryptography.CryptographicBuffer.GenerateRandom((uint) data.Length); - System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeBufferExtensions.CopyTo(buffer, data); -#endif } -#if FEATURE_RNG_CREATE || FEATURE_RNG_CSP public static System.Security.Cryptography.RandomNumberGenerator CreateRandomNumberGenerator() { -#if FEATURE_RNG_CREATE return System.Security.Cryptography.RandomNumberGenerator.Create(); -#elif FEATURE_RNG_CSP - return new System.Security.Cryptography.RNGCryptoServiceProvider(); -#else -#error Creation of RandomNumberGenerator is not implemented. -#endif } -#endif // FEATURE_RNG_CREATE || FEATURE_RNG_CSP #if FEATURE_HASH_MD5 public static System.Security.Cryptography.MD5 CreateMD5() diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj index bd940849f..d10ed23b1 100644 --- a/src/Renci.SshNet/Renci.SshNet.csproj +++ b/src/Renci.SshNet/Renci.SshNet.csproj @@ -11,7 +11,7 @@ - FEATURE_BINARY_SERIALIZATION;FEATURE_RNG_CREATE;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_SELECT;FEATURE_SOCKET_POLL;FEATURE_SOCKET_DISPOSE;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160;FEATURE_ECDSA;FEATURE_TAP + FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_SELECT;FEATURE_SOCKET_POLL;FEATURE_SOCKET_DISPOSE;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160;FEATURE_ECDSA;FEATURE_TAP @@ -19,6 +19,6 @@ - FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_RNG_CREATE;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_SELECT;FEATURE_SOCKET_POLL;FEATURE_SOCKET_DISPOSE;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_ECDSA;FEATURE_TAP + FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_SELECT;FEATURE_SOCKET_POLL;FEATURE_SOCKET_DISPOSE;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_ECDSA;FEATURE_TAP diff --git a/src/Renci.SshNet/Security/BouncyCastle/crypto/prng/CryptoApiRandomGenerator.cs b/src/Renci.SshNet/Security/BouncyCastle/crypto/prng/CryptoApiRandomGenerator.cs index 5dd468b04..50ae6f38d 100644 --- a/src/Renci.SshNet/Security/BouncyCastle/crypto/prng/CryptoApiRandomGenerator.cs +++ b/src/Renci.SshNet/Security/BouncyCastle/crypto/prng/CryptoApiRandomGenerator.cs @@ -9,9 +9,7 @@ internal class CryptoApiRandomGenerator private readonly RandomNumberGenerator rndProv; public CryptoApiRandomGenerator() -#if FEATURE_RNG_CREATE || FEATURE_RNG_CSP : this(Abstractions.CryptoAbstraction.CreateRandomNumberGenerator()) -#endif { } @@ -34,15 +32,7 @@ public virtual void AddSeedMaterial(long seed) public virtual void NextBytes(byte[] bytes) { -#if FEATURE_RNG_CREATE || FEATURE_RNG_CSP rndProv.GetBytes(bytes); -#else - if (bytes == null) - throw new ArgumentNullException("bytes"); - - var buffer = Windows.Security.Cryptography.CryptographicBuffer.GenerateRandom((uint)bytes.Length); - System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeBufferExtensions.CopyTo(buffer, bytes); -#endif } public virtual void NextBytes(byte[] bytes, int start, int len) diff --git a/src/Renci.SshNet/Security/Cryptography/Bcrypt.cs b/src/Renci.SshNet/Security/Cryptography/Bcrypt.cs index 837d00318..14f6169a5 100644 --- a/src/Renci.SshNet/Security/Cryptography/Bcrypt.cs +++ b/src/Renci.SshNet/Security/Cryptography/Bcrypt.cs @@ -499,14 +499,10 @@ public static string GenerateSalt(int workFactor) throw new ArgumentOutOfRangeException("workFactor", "The work factor must be between 4 and 31 (inclusive)"); byte[] rnd = new byte[BCRYPT_SALT_LEN]; -#if FEATURE_RNG_CREATE + RandomNumberGenerator rng = RandomNumberGenerator.Create(); -#elif FEATURE_RNG_CSP - RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); -#endif -#if FEATURE_RNG_CREATE || FEATURE_RNG_CSP + rng.GetBytes(rnd); -#endif StringBuilder rs = new StringBuilder(); rs.AppendFormat("$2a${0:00}$", workFactor); From aed2db9ee67af26b07c696c1a3183c72b578a169 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Nag=C3=B3rski?= Date: Mon, 8 May 2023 10:58:50 +0200 Subject: [PATCH 08/23] Remove FEATURE_SOCKET_POLL and FEATURE_SOCKET_SELECT --- .../Abstractions/SocketAbstraction.cs | 8 --- src/Renci.SshNet/Renci.SshNet.csproj | 4 +- src/Renci.SshNet/Session.cs | 63 ------------------- 3 files changed, 2 insertions(+), 73 deletions(-) diff --git a/src/Renci.SshNet/Abstractions/SocketAbstraction.cs b/src/Renci.SshNet/Abstractions/SocketAbstraction.cs index e358767a1..88ab3654c 100644 --- a/src/Renci.SshNet/Abstractions/SocketAbstraction.cs +++ b/src/Renci.SshNet/Abstractions/SocketAbstraction.cs @@ -17,11 +17,7 @@ public static bool CanRead(Socket socket) { if (socket.Connected) { -#if FEATURE_SOCKET_POLL return socket.Poll(-1, SelectMode.SelectRead) && socket.Available > 0; -#else - return true; -#endif // FEATURE_SOCKET_POLL } return false; @@ -40,11 +36,7 @@ public static bool CanWrite(Socket socket) { if (socket != null && socket.Connected) { -#if FEATURE_SOCKET_POLL return socket.Poll(-1, SelectMode.SelectWrite); -#else - return true; -#endif // FEATURE_SOCKET_POLL } return false; diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj index d10ed23b1..115c2fe0b 100644 --- a/src/Renci.SshNet/Renci.SshNet.csproj +++ b/src/Renci.SshNet/Renci.SshNet.csproj @@ -11,7 +11,7 @@ - FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_SELECT;FEATURE_SOCKET_POLL;FEATURE_SOCKET_DISPOSE;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160;FEATURE_ECDSA;FEATURE_TAP + FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_DISPOSE;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160;FEATURE_ECDSA;FEATURE_TAP @@ -19,6 +19,6 @@ - FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_SELECT;FEATURE_SOCKET_POLL;FEATURE_SOCKET_DISPOSE;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_ECDSA;FEATURE_TAP + FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_DISPOSE;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_ECDSA;FEATURE_TAP diff --git a/src/Renci.SshNet/Session.cs b/src/Renci.SshNet/Session.cs index 0846cb2cd..e5ca23f76 100644 --- a/src/Renci.SshNet/Session.cs +++ b/src/Renci.SshNet/Session.cs @@ -172,13 +172,11 @@ public class Session : ISession /// private Socket _socket; -#if FEATURE_SOCKET_POLL /// /// Holds an object that is used to ensure only a single thread can read from /// at any given time. /// private readonly object _socketReadLock = new object(); -#endif // FEATURE_SOCKET_POLL /// /// Holds an object that is used to ensure only a single thread can write to @@ -1150,13 +1148,11 @@ private Message ReceiveMessage(Socket socket) byte[] data; uint packetLength; -#if FEATURE_SOCKET_POLL // avoid reading from socket while IsSocketConnected is attempting to determine whether the // socket is still connected by invoking Socket.Poll(...) and subsequently verifying value of // Socket.Available lock (_socketReadLock) { -#endif // FEATURE_SOCKET_POLL // Read first block - which starts with the packet length var firstBlock = new byte[blockSize]; if (TrySocketRead(socket, firstBlock, 0, blockSize) == 0) @@ -1204,9 +1200,7 @@ private Message ReceiveMessage(Socket socket) return null; } } -#if FEATURE_SOCKET_POLL } -#endif // FEATURE_SOCKET_POLL if (_serverCipher != null) { @@ -1767,7 +1761,6 @@ internal static string ToHex(byte[] bytes) #endregion -#if FEATURE_SOCKET_POLL /// /// Gets a value indicating whether the socket is connected. /// @@ -1807,23 +1800,10 @@ internal static string ToHex(byte[] bytes) /// we synchronize reads from the . /// /// -#else - /// - /// Gets a value indicating whether the socket is connected. - /// - /// - /// true if the socket is connected; otherwise, false. - /// - /// - /// We verify whether is true. However, this only returns the state - /// of the socket as of the last I/O operation. - /// -#endif private bool IsSocketConnected() { lock (_socketDisposeLock) { -#if FEATURE_SOCKET_POLL if (!_socket.IsConnected()) { return false; @@ -1834,9 +1814,6 @@ private bool IsSocketConnected() var connectionClosedOrDataAvailable = _socket.Poll(0, SelectMode.SelectRead); return !(connectionClosedOrDataAvailable && _socket.Available == 0); } -#else - return _socket.IsConnected(); -#endif // FEATURE_SOCKET_POLL } } @@ -1915,10 +1892,8 @@ private void MessageListener() break; } -#if FEATURE_SOCKET_POLL || FEATURE_SOCKET_SELECT try { -#if FEATURE_SOCKET_POLL // Block until either data is available or the socket is closed var connectionClosedOrDataAvailable = socket.Poll(-1, SelectMode.SelectRead); if (connectionClosedOrDataAvailable && socket.Available == 0) @@ -1926,43 +1901,6 @@ private void MessageListener() // connection with SSH server was closed or connection was reset break; } -#elif FEATURE_SOCKET_SELECT - var readSockets = new List { socket }; - - // if the socket is already disposed when Select is invoked, then a SocketException - // stating "An operation was attempted on something that is not a socket" is thrown; - // we attempt to avoid this exception by having an IsConnected() that can break the - // message loop - // - // note that there's no guarantee that the socket will not be disposed between the - // IsConnected() check and the Select invocation; we can't take a "dispose" lock - // that includes the Select invocation as we want Dispose() to be able to interrupt - // the Select - - // perform a blocking select to determine whether there's is data available to be - // read; we do not use a blocking read to allow us to use Socket.Poll to determine - // if the connection is still available (in IsSocketConnected) - - Socket.Select(readSockets, null, null, -1); - - // the Select invocation will be interrupted in one of the following conditions: - // * data is available to be read - // => the socket will not be removed from "readSockets" - // * the socket connection is closed during the Select invocation - // => the socket will be removed from "readSockets" - // * the socket is disposed during the Select invocation - // => the socket will not be removed from "readSocket" - // - // since we handle the second and third condition the same way and Socket.Connected - // allows us to check for both conditions, we use that instead of both checking for - // the removal from "readSockets" and the Connection check - if (!socket.IsConnected()) - { - // connection with SSH server was closed or socket was disposed; - // break out of the message loop - break; - } -#endif // FEATURE_SOCKET_SELECT } catch (ObjectDisposedException) { @@ -1972,7 +1910,6 @@ private void MessageListener() // * a SSH_MSG_DISCONNECT received from server break; } -#endif // FEATURE_SOCKET_POLL || FEATURE_SOCKET_SELECT var message = ReceiveMessage(socket); if (message == null) From bd58ddc3f31c943bc7635282b08a6e541138c2b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Nag=C3=B3rski?= Date: Mon, 8 May 2023 11:00:13 +0200 Subject: [PATCH 09/23] Remove FEATURE_SOCKET_DISPOSE --- ..._Dispose_SessionIsConnectedAndChannelIsOpen.cs | 3 --- .../Common/AsyncSocketListener.cs | 3 --- src/Renci.SshNet/Common/Extensions.cs | 15 --------------- src/Renci.SshNet/Connection/ProxyConnector.cs | 5 +---- src/Renci.SshNet/Renci.SshNet.csproj | 4 ++-- 5 files changed, 3 insertions(+), 27 deletions(-) diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs index a75d407d3..da7739694 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs @@ -5,9 +5,6 @@ using System.Threading; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; -#if !FEATURE_SOCKET_DISPOSE -using Renci.SshNet.Common; -#endif // !FEATURE_SOCKET_DISPOSE using Renci.SshNet.Channels; using Renci.SshNet.Messages.Connection; using Renci.SshNet.Tests.Common; diff --git a/src/Renci.SshNet.Tests/Common/AsyncSocketListener.cs b/src/Renci.SshNet.Tests/Common/AsyncSocketListener.cs index 8fa81a301..78319f76f 100644 --- a/src/Renci.SshNet.Tests/Common/AsyncSocketListener.cs +++ b/src/Renci.SshNet.Tests/Common/AsyncSocketListener.cs @@ -3,9 +3,6 @@ using System.Net; using System.Net.Sockets; using System.Threading; -#if !FEATURE_SOCKET_DISPOSE -using Renci.SshNet.Common; -#endif // !FEATURE_SOCKET_DISPOSE namespace Renci.SshNet.Tests.Common { diff --git a/src/Renci.SshNet/Common/Extensions.cs b/src/Renci.SshNet/Common/Extensions.cs index 9b603ba89..6b10675c7 100644 --- a/src/Renci.SshNet/Common/Extensions.cs +++ b/src/Renci.SshNet/Common/Extensions.cs @@ -303,21 +303,6 @@ internal static bool IsConnected(this Socket socket) return socket.Connected; } -#if !FEATURE_SOCKET_DISPOSE - /// - /// Disposes the specified socket. - /// - /// The socket. - [DebuggerNonUserCode] - internal static void Dispose(this Socket socket) - { - if (socket == null) - throw new NullReferenceException(); - - socket.Close(); - } -#endif // !FEATURE_SOCKET_DISPOSE - #if !FEATURE_WAITHANDLE_DISPOSE /// /// Disposes the specified handle. diff --git a/src/Renci.SshNet/Connection/ProxyConnector.cs b/src/Renci.SshNet/Connection/ProxyConnector.cs index 6cc2ac9d4..635357c54 100644 --- a/src/Renci.SshNet/Connection/ProxyConnector.cs +++ b/src/Renci.SshNet/Connection/ProxyConnector.cs @@ -1,7 +1,4 @@ -#if !FEATURE_SOCKET_DISPOSE -using Renci.SshNet.Common; -#endif -using System; +using System; using System.Net.Sockets; #if FEATURE_TAP using System.Threading; diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj index 115c2fe0b..ffeb59629 100644 --- a/src/Renci.SshNet/Renci.SshNet.csproj +++ b/src/Renci.SshNet/Renci.SshNet.csproj @@ -11,7 +11,7 @@ - FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_DISPOSE;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160;FEATURE_ECDSA;FEATURE_TAP + FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160;FEATURE_ECDSA;FEATURE_TAP @@ -19,6 +19,6 @@ - FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_DISPOSE;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_ECDSA;FEATURE_TAP + FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_ECDSA;FEATURE_TAP From 0e870e560a2e2fb36ff79670342efd47a34aa421 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Nag=C3=B3rski?= Date: Mon, 8 May 2023 11:16:39 +0200 Subject: [PATCH 10/23] Remove FEATURE_TAP --- .../Sftp/SftpFileStreamAsyncTestBase.cs | 4 +-- ...eStreamTest_OpenAsync_FileAccessInvalid.cs | 4 +-- ...OpenAsync_FileModeAppend_FileAccessRead.cs | 4 +-- ...sync_FileModeAppend_FileAccessReadWrite.cs | 4 +-- ...penAsync_FileModeAppend_FileAccessWrite.cs | 4 +-- ...nAsync_FileModeCreateNew_FileAccessRead.cs | 4 +-- ...c_FileModeCreateNew_FileAccessReadWrite.cs | 4 +-- ...Async_FileModeCreateNew_FileAccessWrite.cs | 4 +-- ...OpenAsync_FileModeCreate_FileAccessRead.cs | 4 +-- ...te_FileAccessReadWrite_FileDoesNotExist.cs | 4 +-- ...deCreate_FileAccessReadWrite_FileExists.cs | 4 +-- ...Create_FileAccessWrite_FileDoesNotExist.cs | 5 +-- ...leModeCreate_FileAccessWrite_FileExists.cs | 6 ++-- ...ileStreamTest_OpenAsync_FileModeInvalid.cs | 4 +-- ...ync_FileModeOpenOrCreate_FileAccessRead.cs | 6 ++-- ...ileModeOpenOrCreate_FileAccessReadWrite.cs | 4 +-- ...nc_FileModeOpenOrCreate_FileAccessWrite.cs | 4 +-- ...t_OpenAsync_FileModeOpen_FileAccessRead.cs | 4 +-- ...nAsync_FileModeOpen_FileAccessReadWrite.cs | 4 +-- ..._OpenAsync_FileModeOpen_FileAccessWrite.cs | 4 +-- ...enAsync_FileModeTruncate_FileAccessRead.cs | 4 +-- ...nc_FileModeTruncate_FileAccessReadWrite.cs | 4 +-- ...nAsync_FileModeTruncate_FileAccessWrite.cs | 6 ++-- ...FromServerThanCountAndEqualToBufferSize.cs | 6 ++-- ...romServerThanCountAndLessThanBufferSize.cs | 4 +-- ...fferAndReadMoreBytesFromServerThanCount.cs | 4 +-- ...tGreatherThanTwoTimesTheWriteBufferSize.cs | 4 +-- .../Classes/SftpClientTest.ConnectAsync.cs | 6 ++-- .../Classes/SftpClientTest.DeleteFileAsync.cs | 6 ++-- .../Classes/SftpClientTest.RenameFileAsync.cs | 4 +-- .../Renci.SshNet.Tests.csproj | 2 +- .../Abstractions/DnsAbstraction.cs | 6 ---- .../Abstractions/SocketAbstraction.cs | 7 +---- .../Abstractions/SocketExtensions.cs | 4 +-- src/Renci.SshNet/BaseClient.cs | 7 +---- src/Renci.SshNet/Connection/ConnectorBase.cs | 7 ----- .../Connection/DirectConnector.cs | 2 -- src/Renci.SshNet/Connection/IConnector.cs | 2 -- .../Connection/IProtocolVersionExchange.cs | 2 -- .../Connection/ProtocolVersionExchange.cs | 7 ----- src/Renci.SshNet/Connection/ProxyConnector.cs | 7 +---- src/Renci.SshNet/IBaseClient.cs | 4 --- src/Renci.SshNet/ISession.cs | 4 --- src/Renci.SshNet/ISftpClient.cs | 13 -------- src/Renci.SshNet/Renci.SshNet.csproj | 4 +-- src/Renci.SshNet/Session.cs | 4 --- src/Renci.SshNet/Sftp/ISftpSession.cs | 24 -------------- src/Renci.SshNet/Sftp/SftpFileStream.cs | 13 +------- src/Renci.SshNet/Sftp/SftpSession.cs | 31 ------------------- src/Renci.SshNet/SftpClient.cs | 14 --------- 50 files changed, 44 insertions(+), 253 deletions(-) diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamAsyncTestBase.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamAsyncTestBase.cs index b8b7b4ae9..110a20bed 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamAsyncTestBase.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamAsyncTestBase.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using System; +using System; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; @@ -66,4 +65,3 @@ protected byte[] GenerateRandom(uint length, Random random) } } } -#endif \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileAccessInvalid.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileAccessInvalid.cs index fab12dad6..4febea075 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileAccessInvalid.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileAccessInvalid.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using System; +using System; using System.IO; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -54,4 +53,3 @@ public void CtorShouldHaveThrownArgumentException() } } } -#endif \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeAppend_FileAccessRead.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeAppend_FileAccessRead.cs index 0ffeaeb6c..14a2338b0 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeAppend_FileAccessRead.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeAppend_FileAccessRead.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using System; +using System; using System.IO; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -55,4 +54,3 @@ public void CtorShouldHaveThrownArgumentException() } } } -#endif \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeAppend_FileAccessReadWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeAppend_FileAccessReadWrite.cs index 2ed8cd14f..c58f33873 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeAppend_FileAccessReadWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeAppend_FileAccessReadWrite.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using System; +using System; using System.IO; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -55,4 +54,3 @@ public void CtorShouldHaveThrownArgumentException() } } } -#endif \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeAppend_FileAccessWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeAppend_FileAccessWrite.cs index 8d9bc960b..a95be4233 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeAppend_FileAccessWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeAppend_FileAccessWrite.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using System; +using System; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -152,4 +151,3 @@ public void RequestFStatOnSftpSessionShouldBeInvokedOnce() } } } -#endif \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreateNew_FileAccessRead.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreateNew_FileAccessRead.cs index eb83af777..a697a3c53 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreateNew_FileAccessRead.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreateNew_FileAccessRead.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using System; +using System; using System.IO; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -55,4 +54,3 @@ public void CtorShouldHaveThrownArgumentException() } } } -#endif \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreateNew_FileAccessReadWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreateNew_FileAccessReadWrite.cs index 5c2318086..c1b271dd3 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreateNew_FileAccessReadWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreateNew_FileAccessReadWrite.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using System; +using System; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -133,4 +132,3 @@ public void RequestOpenOnSftpSessionShouldBeInvokedOnce() } } } -#endif \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreateNew_FileAccessWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreateNew_FileAccessWrite.cs index 7671fe300..b6c6487df 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreateNew_FileAccessWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreateNew_FileAccessWrite.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using System; +using System; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -133,4 +132,3 @@ public void RequestOpenOnSftpSessionShouldBeInvokedOnce() } } } -#endif \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessRead.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessRead.cs index 2c6d28a6e..460081fca 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessRead.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessRead.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using System; +using System; using System.IO; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -55,4 +54,3 @@ public void CtorShouldHaveThrownArgumentException() } } } -#endif \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessReadWrite_FileDoesNotExist.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessReadWrite_FileDoesNotExist.cs index 5fe519f17..9563b9fcd 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessReadWrite_FileDoesNotExist.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessReadWrite_FileDoesNotExist.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using System; +using System; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -133,4 +132,3 @@ public void RequestOpenOnSftpSessionShouldBeInvokedOnce() } } } -#endif \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessReadWrite_FileExists.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessReadWrite_FileExists.cs index a313afb96..e2d5d061c 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessReadWrite_FileExists.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessReadWrite_FileExists.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using System; +using System; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -133,4 +132,3 @@ public void RequestOpenOnSftpSessionShouldBeInvokedOnce() } } } -#endif \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessWrite_FileDoesNotExist.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessWrite_FileDoesNotExist.cs index c1d7fc960..17ac610d4 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessWrite_FileDoesNotExist.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessWrite_FileDoesNotExist.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using System; +using System; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -132,5 +131,3 @@ public void RequestOpenOnSftpSessionShouldBeInvokedOnceWithTruncateAndOnceWithCr SftpSessionMock.Verify(p => p.RequestOpenAsync(_path, Flags.Write | Flags.CreateNewOrOpen | Flags.Truncate, _cancellationToken), Times.Once); } } -} -#endif \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessWrite_FileExists.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessWrite_FileExists.cs index 834299706..ed001ab2a 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessWrite_FileExists.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessWrite_FileExists.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using System; +using System; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -132,5 +131,4 @@ public void RequestOpenOnSftpSessionShouldBeInvokedOnce() SftpSessionMock.Verify(p => p.RequestOpenAsync(_path, Flags.Write | Flags.CreateNewOrOpen | Flags.Truncate, _cancellationToken), Times.Once); } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeInvalid.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeInvalid.cs index 9cfc4a37f..075967ac2 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeInvalid.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeInvalid.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using System; +using System; using System.IO; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -54,4 +53,3 @@ public void CtorShouldHaveThrownArgumentException() } } } -#endif \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpenOrCreate_FileAccessRead.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpenOrCreate_FileAccessRead.cs index f9360c40c..15a40915a 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpenOrCreate_FileAccessRead.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpenOrCreate_FileAccessRead.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using System; +using System; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -137,5 +136,4 @@ public void RequestOpenOnSftpSessionShouldBeInvokedOnce() SftpSessionMock.Verify(p => p.RequestOpenAsync(_path, Flags.Read | Flags.CreateNewOrOpen, _cancellationToken), Times.Once); } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpenOrCreate_FileAccessReadWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpenOrCreate_FileAccessReadWrite.cs index 7e5e4d867..c7cd5d4a4 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpenOrCreate_FileAccessReadWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpenOrCreate_FileAccessReadWrite.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using System; +using System; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -133,4 +132,3 @@ public void RequestOpenOnSftpSessionShouldBeInvokedOnce() } } } -#endif \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpenOrCreate_FileAccessWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpenOrCreate_FileAccessWrite.cs index edccf9b99..0b69f581e 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpenOrCreate_FileAccessWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpenOrCreate_FileAccessWrite.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using System; +using System; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -133,4 +132,3 @@ public void RequestOpenOnSftpSessionShouldBeInvokedOnce() } } } -#endif \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpen_FileAccessRead.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpen_FileAccessRead.cs index 1d4f686fa..76387888f 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpen_FileAccessRead.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpen_FileAccessRead.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using System; +using System; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -139,4 +138,3 @@ public void RequestOpenOnSftpSessionShouldBeInvokedOnce() } } } -#endif \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpen_FileAccessReadWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpen_FileAccessReadWrite.cs index 8ee641337..56589f668 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpen_FileAccessReadWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpen_FileAccessReadWrite.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using System; +using System; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -133,4 +132,3 @@ public void RequestOpenOnSftpSessionShouldBeInvokedOnce() } } } -#endif \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpen_FileAccessWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpen_FileAccessWrite.cs index 4be281731..db61a2a6e 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpen_FileAccessWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpen_FileAccessWrite.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using System; +using System; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -133,4 +132,3 @@ public void RequestOpenOnSftpSessionShouldBeInvokedOnce() } } } -#endif \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeTruncate_FileAccessRead.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeTruncate_FileAccessRead.cs index 9883a5a76..9247274e8 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeTruncate_FileAccessRead.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeTruncate_FileAccessRead.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using System; +using System; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -56,4 +55,3 @@ public void CtorShouldHaveThrownArgumentException() } } } -#endif \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeTruncate_FileAccessReadWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeTruncate_FileAccessReadWrite.cs index 2d0efd24f..ecde02148 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeTruncate_FileAccessReadWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeTruncate_FileAccessReadWrite.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using System; +using System; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -133,4 +132,3 @@ public void RequestOpenOnSftpSessionShouldBeInvokedOnce() } } } -#endif \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeTruncate_FileAccessWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeTruncate_FileAccessWrite.cs index 5f61e1984..0c06eba6a 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeTruncate_FileAccessWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeTruncate_FileAccessWrite.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using System; +using System; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -132,5 +131,4 @@ public void RequestOpenOnSftpSessionShouldBeInvokedOnce() SftpSessionMock.Verify(p => p.RequestOpenAsync(_path, Flags.Write | Flags.Truncate, _cancellationToken), Times.Once); } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_ReadAsync_ReadMode_NoDataInReaderBufferAndReadLessBytesFromServerThanCountAndEqualToBufferSize.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_ReadAsync_ReadMode_NoDataInReaderBufferAndReadLessBytesFromServerThanCountAndEqualToBufferSize.cs index 13f3e1255..d3b5983be 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_ReadAsync_ReadMode_NoDataInReaderBufferAndReadLessBytesFromServerThanCountAndEqualToBufferSize.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_ReadAsync_ReadMode_NoDataInReaderBufferAndReadLessBytesFromServerThanCountAndEqualToBufferSize.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using System; +using System; using System.IO; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -155,5 +154,4 @@ public async Task ReadShouldReturnAllRemaningBytesFromReadBufferAndReadAgainWhen SftpSessionMock.Verify(p => p.RequestReadAsync(_handle, (ulong)(_serverData1Length + _serverData2Length), _readBufferSize, default)); } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_ReadAsync_ReadMode_NoDataInReaderBufferAndReadLessBytesFromServerThanCountAndLessThanBufferSize.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_ReadAsync_ReadMode_NoDataInReaderBufferAndReadLessBytesFromServerThanCountAndLessThanBufferSize.cs index 2da0a4385..29121639c 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_ReadAsync_ReadMode_NoDataInReaderBufferAndReadLessBytesFromServerThanCountAndLessThanBufferSize.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_ReadAsync_ReadMode_NoDataInReaderBufferAndReadLessBytesFromServerThanCountAndLessThanBufferSize.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using System; +using System; using System.IO; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -149,4 +148,3 @@ public async Task SubsequentReadShouldReadAgainFromCurrentPositionFromServerAndN } } } -#endif \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_ReadAsync_ReadMode_NoDataInReaderBufferAndReadMoreBytesFromServerThanCount.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_ReadAsync_ReadMode_NoDataInReaderBufferAndReadMoreBytesFromServerThanCount.cs index 80895217e..d95ffd0a0 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_ReadAsync_ReadMode_NoDataInReaderBufferAndReadMoreBytesFromServerThanCount.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_ReadAsync_ReadMode_NoDataInReaderBufferAndReadMoreBytesFromServerThanCount.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using System; +using System; using System.IO; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; @@ -140,4 +139,3 @@ public async Task SubsequentReadShouldReturnAllRemaningBytesFromReadBufferAndRea } } } -#endif \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_WriteAsync_SessionOpen_CountGreatherThanTwoTimesTheWriteBufferSize.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_WriteAsync_SessionOpen_CountGreatherThanTwoTimesTheWriteBufferSize.cs index dcbfedf63..a9f4587b0 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_WriteAsync_SessionOpen_CountGreatherThanTwoTimesTheWriteBufferSize.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_WriteAsync_SessionOpen_CountGreatherThanTwoTimesTheWriteBufferSize.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using System; +using System; using System.Globalization; using System.IO; using System.Threading; @@ -140,4 +139,3 @@ public async Task FlushShouldFlushBuffer() } } } -#endif \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/SftpClientTest.ConnectAsync.cs b/src/Renci.SshNet.Tests/Classes/SftpClientTest.ConnectAsync.cs index 75602ea2c..df7a8f0b6 100644 --- a/src/Renci.SshNet.Tests/Classes/SftpClientTest.ConnectAsync.cs +++ b/src/Renci.SshNet.Tests/Classes/SftpClientTest.ConnectAsync.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using System; +using System; using System.Net.Sockets; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -44,5 +43,4 @@ public async Task ConnectAsync_ProxyHostNameInvalid_ShouldThrowSocketExceptionWi } } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/SftpClientTest.DeleteFileAsync.cs b/src/Renci.SshNet.Tests/Classes/SftpClientTest.DeleteFileAsync.cs index 20e68e812..9d8464377 100644 --- a/src/Renci.SshNet.Tests/Classes/SftpClientTest.DeleteFileAsync.cs +++ b/src/Renci.SshNet.Tests/Classes/SftpClientTest.DeleteFileAsync.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Renci.SshNet.Tests.Properties; using System; using System.Threading.Tasks; @@ -23,5 +22,4 @@ public async Task Test_Sftp_DeleteFileAsync_Null() } } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/SftpClientTest.RenameFileAsync.cs b/src/Renci.SshNet.Tests/Classes/SftpClientTest.RenameFileAsync.cs index 38d651f97..a24ec0942 100644 --- a/src/Renci.SshNet.Tests/Classes/SftpClientTest.RenameFileAsync.cs +++ b/src/Renci.SshNet.Tests/Classes/SftpClientTest.RenameFileAsync.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Renci.SshNet.Tests.Properties; using System; using System.IO; @@ -63,4 +62,3 @@ public async Task Test_Sftp_RenameFileAsync_Null() } } } -#endif \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj b/src/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj index b577179e2..665ccf11f 100644 --- a/src/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj +++ b/src/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj @@ -7,7 +7,7 @@ - FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_TPL;FEATURE_TAP + FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_TPL diff --git a/src/Renci.SshNet/Abstractions/DnsAbstraction.cs b/src/Renci.SshNet/Abstractions/DnsAbstraction.cs index a2ac9d58f..707521eae 100644 --- a/src/Renci.SshNet/Abstractions/DnsAbstraction.cs +++ b/src/Renci.SshNet/Abstractions/DnsAbstraction.cs @@ -1,10 +1,7 @@ using System; using System.Net; using System.Net.Sockets; - -#if FEATURE_TAP using System.Threading.Tasks; -#endif #if FEATURE_DNS_SYNC #elif FEATURE_DNS_APM @@ -92,7 +89,6 @@ public static IPAddress[] GetHostAddresses(string hostNameOrAddress) #endif } -#if FEATURE_TAP /// /// Returns the Internet Protocol (IP) addresses for the specified host. /// @@ -107,7 +103,5 @@ public static Task GetHostAddressesAsync(string hostNameOrAddress) { return Dns.GetHostAddressesAsync(hostNameOrAddress); } -#endif - } } diff --git a/src/Renci.SshNet/Abstractions/SocketAbstraction.cs b/src/Renci.SshNet/Abstractions/SocketAbstraction.cs index 88ab3654c..f57ea8482 100644 --- a/src/Renci.SshNet/Abstractions/SocketAbstraction.cs +++ b/src/Renci.SshNet/Abstractions/SocketAbstraction.cs @@ -3,9 +3,8 @@ using System.Net; using System.Net.Sockets; using System.Threading; -#if FEATURE_TAP using System.Threading.Tasks; -#endif + using Renci.SshNet.Common; using Renci.SshNet.Messages.Transport; @@ -54,12 +53,10 @@ public static void Connect(Socket socket, IPEndPoint remoteEndpoint, TimeSpan co ConnectCore(socket, remoteEndpoint, connectTimeout, false); } -#if FEATURE_TAP public static async Task ConnectAsync(Socket socket, IPEndPoint remoteEndpoint, CancellationToken cancellationToken) { await socket.ConnectAsync(remoteEndpoint, cancellationToken).ConfigureAwait(false); } -#endif private static void ConnectCore(Socket socket, IPEndPoint remoteEndpoint, TimeSpan connectTimeout, bool ownsSocket) { @@ -319,12 +316,10 @@ public static byte[] Read(Socket socket, int size, TimeSpan timeout) return buffer; } -#if FEATURE_TAP public static Task ReadAsync(Socket socket, byte[] buffer, int offset, int length, CancellationToken cancellationToken) { return socket.ReceiveAsync(buffer, offset, length, cancellationToken); } -#endif /// /// Receives data from a bound into a receive buffer. diff --git a/src/Renci.SshNet/Abstractions/SocketExtensions.cs b/src/Renci.SshNet/Abstractions/SocketExtensions.cs index d763e1a34..7d3c30f93 100644 --- a/src/Renci.SshNet/Abstractions/SocketExtensions.cs +++ b/src/Renci.SshNet/Abstractions/SocketExtensions.cs @@ -1,5 +1,4 @@ -#if FEATURE_TAP -using System; +using System; using System.Net; using System.Net.Sockets; using System.Runtime.CompilerServices; @@ -116,4 +115,3 @@ public static async Task ReceiveAsync(this Socket socket, byte[] buffer, in } } } -#endif \ No newline at end of file diff --git a/src/Renci.SshNet/BaseClient.cs b/src/Renci.SshNet/BaseClient.cs index 754396108..fdc4e3a39 100644 --- a/src/Renci.SshNet/BaseClient.cs +++ b/src/Renci.SshNet/BaseClient.cs @@ -1,9 +1,8 @@ using System; using System.Net.Sockets; using System.Threading; -#if FEATURE_TAP using System.Threading.Tasks; -#endif + using Renci.SshNet.Abstractions; using Renci.SshNet.Common; using Renci.SshNet.Messages.Transport; @@ -242,7 +241,6 @@ public void Connect() StartKeepAliveTimer(); } -#if FEATURE_TAP /// /// Asynchronously connects client to the server. /// @@ -297,7 +295,6 @@ public async Task ConnectAsync(CancellationToken cancellationToken) } StartKeepAliveTimer(); } -#endif /// /// Disconnects client from the server. @@ -533,7 +530,6 @@ private ISession CreateAndConnectSession() } } -#if FEATURE_TAP private async Task CreateAndConnectSessionAsync(CancellationToken cancellationToken) { var session = _serviceFactory.CreateSession(ConnectionInfo, _serviceFactory.CreateSocketFactory()); @@ -551,7 +547,6 @@ private async Task CreateAndConnectSessionAsync(CancellationToken canc throw; } } -#endif private void DisposeSession(ISession session) { diff --git a/src/Renci.SshNet/Connection/ConnectorBase.cs b/src/Renci.SshNet/Connection/ConnectorBase.cs index ffa026750..6bcd556fd 100644 --- a/src/Renci.SshNet/Connection/ConnectorBase.cs +++ b/src/Renci.SshNet/Connection/ConnectorBase.cs @@ -5,10 +5,7 @@ using System.Net; using System.Net.Sockets; using System.Threading; - -#if FEATURE_TAP using System.Threading.Tasks; -#endif namespace Renci.SshNet.Connection { @@ -26,9 +23,7 @@ protected ConnectorBase(ISocketFactory socketFactory) public abstract Socket Connect(IConnectionInfo connectionInfo); -#if FEATURE_TAP public abstract Task ConnectAsync(IConnectionInfo connectionInfo, CancellationToken cancellationToken); -#endif /// /// Establishes a socket connection to the specified host and port. @@ -63,7 +58,6 @@ protected Socket SocketConnect(string host, int port, TimeSpan timeout) } } -#if FEATURE_TAP /// /// Establishes a socket connection to the specified host and port. /// @@ -97,7 +91,6 @@ protected async Task SocketConnectAsync(string host, int port, Cancellat throw; } } -#endif protected static byte SocketReadByte(Socket socket) { diff --git a/src/Renci.SshNet/Connection/DirectConnector.cs b/src/Renci.SshNet/Connection/DirectConnector.cs index 0d07bb936..0f428fc31 100644 --- a/src/Renci.SshNet/Connection/DirectConnector.cs +++ b/src/Renci.SshNet/Connection/DirectConnector.cs @@ -14,11 +14,9 @@ public override Socket Connect(IConnectionInfo connectionInfo) return SocketConnect(connectionInfo.Host, connectionInfo.Port, connectionInfo.Timeout); } -#if FEATURE_TAP public override System.Threading.Tasks.Task ConnectAsync(IConnectionInfo connectionInfo, CancellationToken cancellationToken) { return SocketConnectAsync(connectionInfo.Host, connectionInfo.Port, cancellationToken); } -#endif } } diff --git a/src/Renci.SshNet/Connection/IConnector.cs b/src/Renci.SshNet/Connection/IConnector.cs index 9eccabe62..e49587b74 100644 --- a/src/Renci.SshNet/Connection/IConnector.cs +++ b/src/Renci.SshNet/Connection/IConnector.cs @@ -7,8 +7,6 @@ internal interface IConnector { Socket Connect(IConnectionInfo connectionInfo); -#if FEATURE_TAP System.Threading.Tasks.Task ConnectAsync(IConnectionInfo connectionInfo, CancellationToken cancellationToken); -#endif } } diff --git a/src/Renci.SshNet/Connection/IProtocolVersionExchange.cs b/src/Renci.SshNet/Connection/IProtocolVersionExchange.cs index c804c291f..252cda986 100644 --- a/src/Renci.SshNet/Connection/IProtocolVersionExchange.cs +++ b/src/Renci.SshNet/Connection/IProtocolVersionExchange.cs @@ -19,8 +19,6 @@ internal interface IProtocolVersionExchange /// SshIdentification Start(string clientVersion, Socket socket, TimeSpan timeout); -#if FEATURE_TAP System.Threading.Tasks.Task StartAsync(string clientVersion, Socket socket, System.Threading.CancellationToken cancellationToken); -#endif } } diff --git a/src/Renci.SshNet/Connection/ProtocolVersionExchange.cs b/src/Renci.SshNet/Connection/ProtocolVersionExchange.cs index 469b1b768..716b8a42c 100644 --- a/src/Renci.SshNet/Connection/ProtocolVersionExchange.cs +++ b/src/Renci.SshNet/Connection/ProtocolVersionExchange.cs @@ -8,9 +8,7 @@ using System.Text; using System.Text.RegularExpressions; using System.Threading; -#if FEATURE_TAP using System.Threading.Tasks; -#endif namespace Renci.SshNet.Connection { @@ -78,7 +76,6 @@ public SshIdentification Start(string clientVersion, Socket socket, TimeSpan tim } } -#if FEATURE_TAP public async Task StartAsync(string clientVersion, Socket socket, CancellationToken cancellationToken) { // Immediately send the identification string since the spec states both sides MUST send an identification string @@ -121,7 +118,6 @@ public async Task StartAsync(string clientVersion, Socket soc } } } -#endif private static string GetGroupValue(Match match, string groupName) { @@ -199,7 +195,6 @@ private static string SocketReadLine(Socket socket, TimeSpan timeout, List return null; } -#if FEATURE_TAP private static async Task SocketReadLineAsync(Socket socket, CancellationToken cancellationToken, List buffer) { var data = new byte[1]; @@ -250,7 +245,5 @@ private static async Task SocketReadLineAsync(Socket socket, Cancellatio } } } -#endif - } } diff --git a/src/Renci.SshNet/Connection/ProxyConnector.cs b/src/Renci.SshNet/Connection/ProxyConnector.cs index 635357c54..164ae4835 100644 --- a/src/Renci.SshNet/Connection/ProxyConnector.cs +++ b/src/Renci.SshNet/Connection/ProxyConnector.cs @@ -1,9 +1,8 @@ using System; using System.Net.Sockets; -#if FEATURE_TAP using System.Threading; using System.Threading.Tasks; -#endif + namespace Renci.SshNet.Connection { @@ -16,7 +15,6 @@ public ProxyConnector(ISocketFactory socketFactory) : protected abstract void HandleProxyConnect(IConnectionInfo connectionInfo, Socket socket); -#if FEATURE_TAP // ToDo: Performs async/sync fallback, true async version should be implemented in derived classes protected virtual Task HandleProxyConnectAsync(IConnectionInfo connectionInfo, Socket socket, CancellationToken cancellationToken) { @@ -28,7 +26,6 @@ protected virtual Task HandleProxyConnectAsync(IConnectionInfo connectionInfo, S } return Task.CompletedTask; } -#endif public override Socket Connect(IConnectionInfo connectionInfo) { @@ -48,7 +45,6 @@ public override Socket Connect(IConnectionInfo connectionInfo) } } -#if FEATURE_TAP public override async Task ConnectAsync(IConnectionInfo connectionInfo, CancellationToken cancellationToken) { var socket = await SocketConnectAsync(connectionInfo.ProxyHost, connectionInfo.ProxyPort, cancellationToken).ConfigureAwait(false); @@ -66,6 +62,5 @@ public override async Task ConnectAsync(IConnectionInfo connectionInfo, throw; } } -#endif } } diff --git a/src/Renci.SshNet/IBaseClient.cs b/src/Renci.SshNet/IBaseClient.cs index bd9518ac4..c11adb4f6 100644 --- a/src/Renci.SshNet/IBaseClient.cs +++ b/src/Renci.SshNet/IBaseClient.cs @@ -2,9 +2,7 @@ using System; using System.Net.Sockets; using System.Threading; -#if FEATURE_TAP using System.Threading.Tasks; -#endif namespace Renci.SshNet { @@ -68,7 +66,6 @@ public interface IBaseClient /// Failed to establish proxy connection. void Connect(); -#if FEATURE_TAP /// /// Asynchronously connects client to the server. /// @@ -82,7 +79,6 @@ public interface IBaseClient /// Authentication of SSH session failed. /// Failed to establish proxy connection. Task ConnectAsync(CancellationToken cancellationToken); -#endif /// /// Disconnects client from the server. diff --git a/src/Renci.SshNet/ISession.cs b/src/Renci.SshNet/ISession.cs index cde647a46..bc123c776 100644 --- a/src/Renci.SshNet/ISession.cs +++ b/src/Renci.SshNet/ISession.cs @@ -6,9 +6,7 @@ using Renci.SshNet.Messages; using Renci.SshNet.Messages.Authentication; using Renci.SshNet.Messages.Connection; -#if FEATURE_TAP using System.Threading.Tasks; -#endif namespace Renci.SshNet { @@ -57,7 +55,6 @@ internal interface ISession : IDisposable /// Failed to establish proxy connection. void Connect(); -#if FEATURE_TAP /// /// Asynchronously connects to the server. /// @@ -68,7 +65,6 @@ internal interface ISession : IDisposable /// Authentication of SSH session failed. /// Failed to establish proxy connection. Task ConnectAsync(CancellationToken cancellationToken); -#endif /// /// Create a new SSH session channel. diff --git a/src/Renci.SshNet/ISftpClient.cs b/src/Renci.SshNet/ISftpClient.cs index eda042eff..99e1e7b06 100644 --- a/src/Renci.SshNet/ISftpClient.cs +++ b/src/Renci.SshNet/ISftpClient.cs @@ -4,10 +4,8 @@ using System.Text; using Renci.SshNet.Sftp; using Renci.SshNet.Common; -#if FEATURE_TAP using System.Threading; using System.Threading.Tasks; -#endif namespace Renci.SshNet { @@ -492,7 +490,6 @@ public interface ISftpClient : IBaseClient, IDisposable /// The method was called after the client was disposed. void DeleteFile(string path); -#if FEATURE_TAP /// /// Asynchronously deletes remote file specified by path. /// @@ -506,7 +503,6 @@ public interface ISftpClient : IBaseClient, IDisposable /// A SSH error where is the message from the remote host. /// The method was called after the client was disposed. Task DeleteFileAsync(string path, CancellationToken cancellationToken); -#endif /// /// Downloads remote file specified by the path into the stream. @@ -673,7 +669,6 @@ public interface ISftpClient : IBaseClient, IDisposable /// The method was called after the client was disposed. SftpFileSytemInformation GetStatus(string path); -#if FEATURE_TAP /// /// Asynchronously gets status using statvfs@openssh.com request. /// @@ -687,7 +682,6 @@ public interface ISftpClient : IBaseClient, IDisposable /// is null. /// The method was called after the client was disposed. Task GetStatusAsync(string path, CancellationToken cancellationToken); -#endif /// /// Retrieves list of files in remote directory. @@ -704,8 +698,6 @@ public interface ISftpClient : IBaseClient, IDisposable /// The method was called after the client was disposed. IEnumerable ListDirectory(string path, Action listCallback = null); -#if FEATURE_TAP - /// /// Asynchronously retrieves list of files in remote directory. /// @@ -721,7 +713,6 @@ public interface ISftpClient : IBaseClient, IDisposable /// A SSH error where is the message from the remote host. /// The method was called after the client was disposed. Task> ListDirectoryAsync(string path, CancellationToken cancellationToken); -#endif /// /// Opens a on the specified path with read/write access. @@ -750,7 +741,6 @@ public interface ISftpClient : IBaseClient, IDisposable /// The method was called after the client was disposed. SftpFileStream Open(string path, FileMode mode, FileAccess access); -#if FEATURE_TAP /// /// Asynchronously opens a on the specified path, with the specified mode and access. /// @@ -766,7 +756,6 @@ public interface ISftpClient : IBaseClient, IDisposable /// Client is not connected. /// The method was called after the client was disposed. Task OpenAsync(string path, FileMode mode, FileAccess access, CancellationToken cancellationToken); -#endif /// /// Opens an existing file for reading. @@ -906,7 +895,6 @@ public interface ISftpClient : IBaseClient, IDisposable /// The method was called after the client was disposed. void RenameFile(string oldPath, string newPath); -#if FEATURE_TAP /// /// Asynchronously renames remote file from old path to new path. /// @@ -920,7 +908,6 @@ public interface ISftpClient : IBaseClient, IDisposable /// A SSH error where is the message from the remote host. /// The method was called after the client was disposed. Task RenameFileAsync(string oldPath, string newPath, CancellationToken cancellationToken); -#endif /// /// Renames remote file from old path to new path. diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj index ffeb59629..f6d12a276 100644 --- a/src/Renci.SshNet/Renci.SshNet.csproj +++ b/src/Renci.SshNet/Renci.SshNet.csproj @@ -11,7 +11,7 @@ - FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160;FEATURE_ECDSA;FEATURE_TAP + FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160;FEATURE_ECDSA @@ -19,6 +19,6 @@ - FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_ECDSA;FEATURE_TAP + FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_ECDSA diff --git a/src/Renci.SshNet/Session.cs b/src/Renci.SshNet/Session.cs index e5ca23f76..13764e386 100644 --- a/src/Renci.SshNet/Session.cs +++ b/src/Renci.SshNet/Session.cs @@ -16,9 +16,7 @@ using System.Linq; using Renci.SshNet.Abstractions; using Renci.SshNet.Security.Cryptography; -#if FEATURE_TAP using System.Threading.Tasks; -#endif namespace Renci.SshNet { @@ -671,7 +669,6 @@ public void Connect() } } -#if FEATURE_TAP /// /// Asynchronously connects to the server. /// @@ -775,7 +772,6 @@ public async Task ConnectAsync(CancellationToken cancellationToken) RegisterMessage("SSH_MSG_CHANNEL_EOF"); RegisterMessage("SSH_MSG_CHANNEL_CLOSE"); } -#endif /// /// Disconnects from the server. diff --git a/src/Renci.SshNet/Sftp/ISftpSession.cs b/src/Renci.SshNet/Sftp/ISftpSession.cs index 4a3648bd4..8971bd571 100644 --- a/src/Renci.SshNet/Sftp/ISftpSession.cs +++ b/src/Renci.SshNet/Sftp/ISftpSession.cs @@ -2,9 +2,7 @@ using System.Collections.Generic; using System.Threading; using Renci.SshNet.Sftp.Responses; -#if FEATURE_TAP using System.Threading.Tasks; -#endif namespace Renci.SshNet.Sftp { @@ -41,9 +39,7 @@ internal interface ISftpSession : ISubsystemSession /// string GetCanonicalPath(string path); -#if FEATURE_TAP Task GetCanonicalPathAsync(string path, CancellationToken cancellationToken); -#endif /// /// Performs SSH_FXP_FSTAT request. @@ -55,9 +51,7 @@ internal interface ISftpSession : ISubsystemSession /// SftpFileAttributes RequestFStat(byte[] handle, bool nullOnError); -#if FEATURE_TAP Task RequestFStatAsync(byte[] handle, CancellationToken cancellationToken); -#endif /// /// Performs SSH_FXP_STAT request. @@ -135,9 +129,7 @@ internal interface ISftpSession : ISubsystemSession /// File handle. byte[] RequestOpen(string path, Flags flags, bool nullOnError = false); -#if FEATURE_TAP Task RequestOpenAsync(string path, Flags flags, CancellationToken cancellationToken); -#endif /// /// Performs SSH_FXP_OPEN request @@ -173,9 +165,7 @@ internal interface ISftpSession : ISubsystemSession /// File handle. byte[] RequestOpenDir(string path, bool nullOnError = false); -#if FEATURE_TAP Task RequestOpenDirAsync(string path, CancellationToken cancellationToken); -#endif /// /// Performs posix-rename@openssh.com extended request. @@ -220,9 +210,7 @@ internal interface ISftpSession : ISubsystemSession /// is null. byte[] EndRead(SftpReadAsyncResult asyncResult); -#if FEATURE_TAP Task RequestReadAsync(byte[] handle, ulong offset, uint length, CancellationToken cancellationToken); -#endif /// /// Performs SSH_FXP_READDIR request @@ -231,9 +219,7 @@ internal interface ISftpSession : ISubsystemSession /// KeyValuePair[] RequestReadDir(byte[] handle); -#if FEATURE_TAP Task[]> RequestReadDirAsync(byte[] handle, CancellationToken cancellationToken); -#endif /// /// Performs SSH_FXP_REALPATH request. @@ -262,9 +248,7 @@ internal interface ISftpSession : ISubsystemSession /// The path. void RequestRemove(string path); -#if FEATURE_TAP Task RequestRemoveAsync(string path, CancellationToken cancellationToken); -#endif /// /// Performs SSH_FXP_RENAME request. @@ -273,9 +257,7 @@ internal interface ISftpSession : ISubsystemSession /// The new path. void RequestRename(string oldPath, string newPath); -#if FEATURE_TAP Task RequestRenameAsync(string oldPath, string newPath, CancellationToken cancellationToken); -#endif /// /// Performs SSH_FXP_RMDIR request. @@ -298,9 +280,7 @@ internal interface ISftpSession : ISubsystemSession /// SftpFileSytemInformation RequestStatVfs(string path, bool nullOnError = false); -#if FEATURE_TAP Task RequestStatVfsAsync(string path, CancellationToken cancellationToken); -#endif /// /// Performs SSH_FXP_SYMLINK request. @@ -334,9 +314,7 @@ void RequestWrite(byte[] handle, AutoResetEvent wait, Action writeCompleted = null); -#if FEATURE_TAP Task RequestWriteAsync(byte[] handle, ulong serverOffset, byte[] data, int offset, int length, CancellationToken cancellationToken); -#endif /// /// Performs SSH_FXP_CLOSE request. @@ -344,9 +322,7 @@ void RequestWrite(byte[] handle, /// The handle. void RequestClose(byte[] handle); -#if FEATURE_TAP Task RequestCloseAsync(byte[] handle, CancellationToken cancellationToken); -#endif /// /// Performs SSH_FXP_CLOSE request. diff --git a/src/Renci.SshNet/Sftp/SftpFileStream.cs b/src/Renci.SshNet/Sftp/SftpFileStream.cs index b47023687..a266b35b8 100644 --- a/src/Renci.SshNet/Sftp/SftpFileStream.cs +++ b/src/Renci.SshNet/Sftp/SftpFileStream.cs @@ -3,9 +3,7 @@ using System.Threading; using System.Diagnostics.CodeAnalysis; using Renci.SshNet.Common; -#if FEATURE_TAP using System.Threading.Tasks; -#endif namespace Renci.SshNet.Sftp { @@ -293,7 +291,6 @@ internal SftpFileStream(ISftpSession session, string path, FileMode mode, FileAc } } -#if FEATURE_TAP internal static async Task OpenAsync(ISftpSession session, string path, FileMode mode, FileAccess access, int bufferSize, CancellationToken cancellationToken) { if (session == null) @@ -390,7 +387,6 @@ internal static async Task OpenAsync(ISftpSession session, strin return new SftpFileStream(session, path, access, bufferSize, handle, position); } -#endif /// /// Releases unmanaged resources and performs other cleanup operations before the @@ -423,7 +419,6 @@ public override void Flush() } } -#if FEATURE_TAP /// /// Asynchronously clears all buffers for this stream and causes any buffered data to be written to the file. /// @@ -446,7 +441,6 @@ public override Task FlushAsync(CancellationToken cancellationToken) return Task.CompletedTask; } -#endif /// /// Reads a sequence of bytes from the current stream and advances the position within the stream by the @@ -588,7 +582,6 @@ public override int Read(byte[] buffer, int offset, int count) return readLen; } -#if FEATURE_TAP /// /// Asynchronously reads a sequence of bytes from the current stream and advances the position within the stream by the /// number of bytes read. @@ -700,7 +693,6 @@ public override async Task ReadAsync(byte[] buffer, int offset, int count, // return the number of bytes that were read to the caller. return readLen; } -#endif /// /// Reads a byte from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream. @@ -986,7 +978,7 @@ public override void Write(byte[] buffer, int offset, int count) } } -#if FEATURE_TAP + /// /// Asynchronously writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written. /// @@ -1062,7 +1054,6 @@ public override async Task WriteAsync(byte[] buffer, int offset, int count, Canc _bufferPosition = 0; } } -#endif /// /// Writes a byte to the current position in the stream and advances the position within the stream by one byte. @@ -1181,7 +1172,6 @@ private void FlushWriteBuffer() } } -#if FEATURE_TAP private async Task FlushWriteBufferAsync(CancellationToken cancellationToken) { if (_bufferPosition > 0) @@ -1190,7 +1180,6 @@ private async Task FlushWriteBufferAsync(CancellationToken cancellationToken) _bufferPosition = 0; } } -#endif /// /// Setups the read. diff --git a/src/Renci.SshNet/Sftp/SftpSession.cs b/src/Renci.SshNet/Sftp/SftpSession.cs index c33c70e34..dd38bd36e 100644 --- a/src/Renci.SshNet/Sftp/SftpSession.cs +++ b/src/Renci.SshNet/Sftp/SftpSession.cs @@ -6,9 +6,7 @@ using System.Globalization; using Renci.SshNet.Sftp.Responses; using Renci.SshNet.Sftp.Requests; -#if FEATURE_TAP using System.Threading.Tasks; -#endif namespace Renci.SshNet.Sftp { @@ -139,7 +137,6 @@ public string GetCanonicalPath(string path) return string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", canonizedPath, slash, pathParts[pathParts.Length - 1]); } -#if FEATURE_TAP public async Task GetCanonicalPathAsync(string path, CancellationToken cancellationToken) { var fullPath = GetFullRemotePath(path); @@ -185,7 +182,6 @@ public async Task GetCanonicalPathAsync(string path, CancellationToken c slash = "/"; return canonizedPath + slash + pathParts[pathParts.Length - 1]; } -#endif public ISftpFileReader CreateFileReader(byte[] handle, ISftpSession sftpSession, uint chunkSize, int maxPendingReads, long? fileSize) { @@ -436,7 +432,6 @@ public byte[] RequestOpen(string path, Flags flags, bool nullOnError = false) return handle; } -#if FEATURE_TAP public async Task RequestOpenAsync(string path, Flags flags, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); @@ -452,7 +447,6 @@ public async Task RequestOpenAsync(string path, Flags flags, Cancellatio return await tcs.Task.ConfigureAwait(false); } } -#endif /// /// Performs SSH_FXP_OPEN request @@ -541,7 +535,6 @@ public void RequestClose(byte[] handle) } } -#if FEATURE_TAP public async Task RequestCloseAsync(byte[] handle, CancellationToken cancellationToken) { TaskCompletionSource tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); @@ -566,8 +559,6 @@ public async Task RequestCloseAsync(byte[] handle, CancellationToken cancellatio await tcs.Task.ConfigureAwait(false); } } -#endif - /// /// Performs SSH_FXP_CLOSE request. @@ -732,7 +723,6 @@ public byte[] RequestRead(byte[] handle, ulong offset, uint length) return data; } -#if FEATURE_TAP public async Task RequestReadAsync(byte[] handle, ulong offset, uint length, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); @@ -758,7 +748,6 @@ public async Task RequestReadAsync(byte[] handle, ulong offset, uint len return await tcs.Task.ConfigureAwait(false); } } -#endif /// /// Performs SSH_FXP_WRITE request. @@ -804,7 +793,6 @@ public void RequestWrite(byte[] handle, } } -#if FEATURE_TAP public async Task RequestWriteAsync(byte[] handle, ulong serverOffset, byte[] data, int offset, int length, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); @@ -829,7 +817,6 @@ public async Task RequestWriteAsync(byte[] handle, ulong serverOffset, byte[] da await tcs.Task.ConfigureAwait(false); } } -#endif /// /// Performs SSH_FXP_LSTAT request. @@ -963,7 +950,6 @@ public SftpFileAttributes RequestFStat(byte[] handle, bool nullOnError) return attributes; } -#if FEATURE_TAP public async Task RequestFStatAsync(byte[] handle, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); @@ -979,7 +965,6 @@ public async Task RequestFStatAsync(byte[] handle, Cancellat return await tcs.Task.ConfigureAwait(false); } } -#endif /// /// Performs SSH_FXP_SETSTAT request. @@ -1078,7 +1063,6 @@ public byte[] RequestOpenDir(string path, bool nullOnError = false) return handle; } -#if FEATURE_TAP public async Task RequestOpenDirAsync(string path, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); @@ -1094,7 +1078,6 @@ public async Task RequestOpenDirAsync(string path, CancellationToken can return await tcs.Task.ConfigureAwait(false); } } -#endif /// /// Performs SSH_FXP_READDIR request @@ -1137,7 +1120,6 @@ public KeyValuePair[] RequestReadDir(byte[] handle) return result; } -#if FEATURE_TAP public async Task[]> RequestReadDirAsync(byte[] handle, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); @@ -1163,8 +1145,6 @@ public async Task[]> RequestReadDirAsyn return await tcs.Task.ConfigureAwait(false); } } -#endif - /// /// Performs SSH_FXP_REMOVE request. @@ -1194,7 +1174,6 @@ public void RequestRemove(string path) } } -#if FEATURE_TAP public async Task RequestRemoveAsync(string path, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); @@ -1219,8 +1198,6 @@ public async Task RequestRemoveAsync(string path, CancellationToken cancellation await tcs.Task.ConfigureAwait(false); } } -#endif - /// /// Performs SSH_FXP_MKDIR request. @@ -1319,7 +1296,6 @@ internal KeyValuePair[] RequestRealPath(string path, return result; } -#if FEATURE_TAP internal async Task[]> RequestRealPathAsync(string path, bool nullOnError, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); @@ -1345,7 +1321,6 @@ internal async Task[]> RequestRealPathA return await tcs.Task.ConfigureAwait(false); } } -#endif /// /// Performs SSH_FXP_REALPATH request. @@ -1528,8 +1503,6 @@ public void RequestRename(string oldPath, string newPath) } } - -#if FEATURE_TAP public async Task RequestRenameAsync(string oldPath, string newPath, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); @@ -1554,7 +1527,6 @@ public async Task RequestRenameAsync(string oldPath, string newPath, Cancellatio await tcs.Task.ConfigureAwait(false); } } -#endif /// /// Performs SSH_FXP_READLINK request. @@ -1722,8 +1694,6 @@ public SftpFileSytemInformation RequestStatVfs(string path, bool nullOnError = f return information; } - -#if FEATURE_TAP public async Task RequestStatVfsAsync(string path, CancellationToken cancellationToken) { if (ProtocolVersion < 3) @@ -1744,7 +1714,6 @@ public async Task RequestStatVfsAsync(string path, Can return await tcs.Task.ConfigureAwait(false); } } -#endif /// /// Performs fstatvfs@openssh.com extended request. diff --git a/src/Renci.SshNet/SftpClient.cs b/src/Renci.SshNet/SftpClient.cs index a7ce34538..2705382ad 100644 --- a/src/Renci.SshNet/SftpClient.cs +++ b/src/Renci.SshNet/SftpClient.cs @@ -10,9 +10,7 @@ using Renci.SshNet.Abstractions; using Renci.SshNet.Common; using Renci.SshNet.Sftp; -#if FEATURE_TAP using System.Threading.Tasks; -#endif namespace Renci.SshNet { @@ -376,7 +374,6 @@ public void DeleteFile(string path) _sftpSession.RequestRemove(fullPath); } -#if FEATURE_TAP /// /// Asynchronously deletes remote file specified by path. /// @@ -401,7 +398,6 @@ public async Task DeleteFileAsync(string path, CancellationToken cancellationTok var fullPath = await _sftpSession.GetCanonicalPathAsync(path, cancellationToken).ConfigureAwait(false); await _sftpSession.RequestRemoveAsync(fullPath, cancellationToken).ConfigureAwait(false); } -#endif /// /// Renames remote file from old path to new path. @@ -418,7 +414,6 @@ public void RenameFile(string oldPath, string newPath) RenameFile(oldPath, newPath, false); } -#if FEATURE_TAP /// /// Asynchronously renames remote file from old path to new path. /// @@ -446,7 +441,6 @@ public async Task RenameFileAsync(string oldPath, string newPath, CancellationTo var newFullPath = await _sftpSession.GetCanonicalPathAsync(newPath, cancellationToken).ConfigureAwait(false); await _sftpSession.RequestRenameAsync(oldFullPath, newFullPath, cancellationToken).ConfigureAwait(false); } -#endif /// /// Renames remote file from old path to new path. @@ -536,8 +530,6 @@ public IEnumerable ListDirectory(string path, Action listCallbac return InternalListDirectory(path, listCallback); } -#if FEATURE_TAP - /// /// Asynchronously retrieves list of files in remote directory. /// @@ -594,8 +586,6 @@ public async Task> ListDirectoryAsync(string path, Cancel return result; } -#endif - /// /// Begins an asynchronous operation of retrieving list of files in remote directory. /// @@ -1129,7 +1119,6 @@ public SftpFileSytemInformation GetStatus(string path) return _sftpSession.RequestStatVfs(fullPath); } -#if FEATURE_TAP /// /// Asynchronously gets status using statvfs@openssh.com request. /// @@ -1154,7 +1143,6 @@ public async Task GetStatusAsync(string path, Cancella var fullPath = await _sftpSession.GetCanonicalPathAsync(path, cancellationToken).ConfigureAwait(false); return await _sftpSession.RequestStatVfsAsync(fullPath, cancellationToken).ConfigureAwait(false); } -#endif #region File Methods @@ -1503,7 +1491,6 @@ public SftpFileStream Open(string path, FileMode mode, FileAccess access) return new SftpFileStream(_sftpSession, path, mode, access, (int) _bufferSize); } -#if FEATURE_TAP /// /// Asynchronously opens a on the specified path, with the specified mode and access. /// @@ -1529,7 +1516,6 @@ public Task OpenAsync(string path, FileMode mode, FileAccess acc return SftpFileStream.OpenAsync(_sftpSession, path, mode, access, (int)_bufferSize, cancellationToken); } -#endif /// /// Opens an existing file for reading. From e81d37421a97504041c7e47c25d0a4b338339d9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Nag=C3=B3rski?= Date: Mon, 8 May 2023 11:17:20 +0200 Subject: [PATCH 11/23] fix build --- ..._OpenAsync_FileModeCreate_FileAccessWrite_FileDoesNotExist.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessWrite_FileDoesNotExist.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessWrite_FileDoesNotExist.cs index 17ac610d4..aa29b7397 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessWrite_FileDoesNotExist.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessWrite_FileDoesNotExist.cs @@ -131,3 +131,4 @@ public void RequestOpenOnSftpSessionShouldBeInvokedOnceWithTruncateAndOnceWithCr SftpSessionMock.Verify(p => p.RequestOpenAsync(_path, Flags.Write | Flags.CreateNewOrOpen | Flags.Truncate, _cancellationToken), Times.Once); } } +} \ No newline at end of file From 148a0b915ec8f4a74993a3dd593797c12267dd4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Nag=C3=B3rski?= Date: Mon, 8 May 2023 11:21:42 +0200 Subject: [PATCH 12/23] Remove FEATURE_ECDSA --- src/Renci.SshNet/ConnectionInfo.cs | 2 -- src/Renci.SshNet/PrivateKeyFile.cs | 4 ---- src/Renci.SshNet/Renci.SshNet.csproj | 4 ++-- .../Security/Cryptography/EcdsaDigitalSignature.cs | 4 +--- src/Renci.SshNet/Security/Cryptography/EcdsaKey.cs | 4 +--- 5 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/Renci.SshNet/ConnectionInfo.cs b/src/Renci.SshNet/ConnectionInfo.cs index af8e1ca5c..f0f8b57c7 100644 --- a/src/Renci.SshNet/ConnectionInfo.cs +++ b/src/Renci.SshNet/ConnectionInfo.cs @@ -382,11 +382,9 @@ public ConnectionInfo(string host, int port, string username, ProxyTypes proxyTy HostKeyAlgorithms = new Dictionary> { {"ssh-ed25519", data => new KeyHostAlgorithm("ssh-ed25519", new ED25519Key(), data)}, -#if FEATURE_ECDSA {"ecdsa-sha2-nistp256", data => new KeyHostAlgorithm("ecdsa-sha2-nistp256", new EcdsaKey(), data)}, {"ecdsa-sha2-nistp384", data => new KeyHostAlgorithm("ecdsa-sha2-nistp384", new EcdsaKey(), data)}, {"ecdsa-sha2-nistp521", data => new KeyHostAlgorithm("ecdsa-sha2-nistp521", new EcdsaKey(), data)}, -#endif {"ssh-rsa", data => new KeyHostAlgorithm("ssh-rsa", new RsaKey(), data)}, {"ssh-dss", data => new KeyHostAlgorithm("ssh-dss", new DsaKey(), data)}, //{"x509v3-sign-rsa", () => { ... }, diff --git a/src/Renci.SshNet/PrivateKeyFile.cs b/src/Renci.SshNet/PrivateKeyFile.cs index 65a311569..5ec7f248d 100644 --- a/src/Renci.SshNet/PrivateKeyFile.cs +++ b/src/Renci.SshNet/PrivateKeyFile.cs @@ -218,12 +218,10 @@ private void Open(Stream privateKey, string passPhrase) _key = new DsaKey(decryptedData); HostKey = new KeyHostAlgorithm("ssh-dss", _key); break; -#if FEATURE_ECDSA case "EC": _key = new EcdsaKey(decryptedData); HostKey = new KeyHostAlgorithm(_key.ToString(), _key); break; -#endif case "OPENSSH": _key = ParseOpenSshV1Key(decryptedData, passPhrase); HostKey = new KeyHostAlgorithm(_key.ToString(), _key); @@ -494,7 +492,6 @@ private Key ParseOpenSshV1Key(byte[] keyFileData, string passPhrase) unencryptedPrivateKey = privateKeyReader.ReadBignum2(); parsedKey = new ED25519Key(publicKey.Reverse(), unencryptedPrivateKey); break; -#if FEATURE_ECDSA case "ecdsa-sha2-nistp256": case "ecdsa-sha2-nistp384": case "ecdsa-sha2-nistp521": @@ -507,7 +504,6 @@ private Key ParseOpenSshV1Key(byte[] keyFileData, string passPhrase) unencryptedPrivateKey = privateKeyReader.ReadBignum2(); parsedKey = new EcdsaKey(curve, publicKey, unencryptedPrivateKey.TrimLeadingZeros()); break; -#endif case "ssh-rsa": var modulus = privateKeyReader.ReadBignum(); //n var exponent = privateKeyReader.ReadBignum(); //e diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj index f6d12a276..4ea329945 100644 --- a/src/Renci.SshNet/Renci.SshNet.csproj +++ b/src/Renci.SshNet/Renci.SshNet.csproj @@ -11,7 +11,7 @@ - FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160;FEATURE_ECDSA + FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160 @@ -19,6 +19,6 @@ - FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_ECDSA + FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512 diff --git a/src/Renci.SshNet/Security/Cryptography/EcdsaDigitalSignature.cs b/src/Renci.SshNet/Security/Cryptography/EcdsaDigitalSignature.cs index 920614672..b5561b5da 100644 --- a/src/Renci.SshNet/Security/Cryptography/EcdsaDigitalSignature.cs +++ b/src/Renci.SshNet/Security/Cryptography/EcdsaDigitalSignature.cs @@ -1,5 +1,4 @@ -#if FEATURE_ECDSA -using System; +using System; using Renci.SshNet.Common; using System.Globalization; using System.Security.Cryptography; @@ -186,4 +185,3 @@ protected override int BufferCapacity } } } -#endif \ No newline at end of file diff --git a/src/Renci.SshNet/Security/Cryptography/EcdsaKey.cs b/src/Renci.SshNet/Security/Cryptography/EcdsaKey.cs index 46f1dcc65..1674a6677 100644 --- a/src/Renci.SshNet/Security/Cryptography/EcdsaKey.cs +++ b/src/Renci.SshNet/Security/Cryptography/EcdsaKey.cs @@ -1,5 +1,4 @@ -#if FEATURE_ECDSA -using System; +using System; using System.IO; using System.Text; using System.Runtime.InteropServices; @@ -467,4 +466,3 @@ protected virtual void Dispose(bool disposing) #endregion } } -#endif \ No newline at end of file From d1d77ebce45fc9ac272138b04eaff94e55a145bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Nag=C3=B3rski?= Date: Mon, 8 May 2023 11:25:17 +0200 Subject: [PATCH 13/23] Remove FEATURE_HASH_MD5 --- src/Renci.SshNet/Abstractions/CryptoAbstraction.cs | 7 ------- src/Renci.SshNet/Renci.SshNet.csproj | 4 ++-- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/Renci.SshNet/Abstractions/CryptoAbstraction.cs b/src/Renci.SshNet/Abstractions/CryptoAbstraction.cs index eb2c3c3d6..b94106f70 100644 --- a/src/Renci.SshNet/Abstractions/CryptoAbstraction.cs +++ b/src/Renci.SshNet/Abstractions/CryptoAbstraction.cs @@ -37,17 +37,10 @@ public static System.Security.Cryptography.RandomNumberGenerator CreateRandomNum return System.Security.Cryptography.RandomNumberGenerator.Create(); } -#if FEATURE_HASH_MD5 public static System.Security.Cryptography.MD5 CreateMD5() { return System.Security.Cryptography.MD5.Create(); } -#else - public static global::SshNet.Security.Cryptography.MD5 CreateMD5() - { - return new global::SshNet.Security.Cryptography.MD5(); - } -#endif // FEATURE_HASH_MD5 #if FEATURE_HASH_SHA1_CREATE || FEATURE_HASH_SHA1_MANAGED public static System.Security.Cryptography.SHA1 CreateSHA1() diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj index 4ea329945..26c4c3c4f 100644 --- a/src/Renci.SshNet/Renci.SshNet.csproj +++ b/src/Renci.SshNet/Renci.SshNet.csproj @@ -11,7 +11,7 @@ - FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160 + FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160 @@ -19,6 +19,6 @@ - FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512 + FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512 From a3a07338d219401ab7cce06f9b821b9b3135c2e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Nag=C3=B3rski?= Date: Mon, 8 May 2023 11:26:46 +0200 Subject: [PATCH 14/23] Remove FEATURE_HASH_SHA1_CREATE --- src/Renci.SshNet/Abstractions/CryptoAbstraction.cs | 11 ----------- src/Renci.SshNet/Renci.SshNet.csproj | 4 ++-- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/Renci.SshNet/Abstractions/CryptoAbstraction.cs b/src/Renci.SshNet/Abstractions/CryptoAbstraction.cs index b94106f70..b2cc3581e 100644 --- a/src/Renci.SshNet/Abstractions/CryptoAbstraction.cs +++ b/src/Renci.SshNet/Abstractions/CryptoAbstraction.cs @@ -42,21 +42,10 @@ public static System.Security.Cryptography.MD5 CreateMD5() return System.Security.Cryptography.MD5.Create(); } -#if FEATURE_HASH_SHA1_CREATE || FEATURE_HASH_SHA1_MANAGED public static System.Security.Cryptography.SHA1 CreateSHA1() { -#if FEATURE_HASH_SHA1_CREATE return System.Security.Cryptography.SHA1.Create(); -#elif FEATURE_HASH_SHA1_MANAGED - return new System.Security.Cryptography.SHA1Managed(); -#endif } -#else - public static global::SshNet.Security.Cryptography.SHA1 CreateSHA1() - { - return new global::SshNet.Security.Cryptography.SHA1(); - } -#endif #if FEATURE_HASH_SHA256_CREATE || FEATURE_HASH_SHA256_MANAGED public static System.Security.Cryptography.SHA256 CreateSHA256() diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj index 26c4c3c4f..a62c34a65 100644 --- a/src/Renci.SshNet/Renci.SshNet.csproj +++ b/src/Renci.SshNet/Renci.SshNet.csproj @@ -11,7 +11,7 @@ - FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160 + FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160 @@ -19,6 +19,6 @@ - FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512 + FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512 From 564896079b72b91ad2b61bddb96f816131695087 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Nag=C3=B3rski?= Date: Mon, 8 May 2023 11:52:49 +0200 Subject: [PATCH 15/23] Remove FEATURE_HASH_SHA256_CREATE and FEATURE_HASH_SHA384_CREATE and FEATURE_HASH_SHA512_CREATE --- .../Abstractions/CryptoAbstraction.cs | 33 ------------------- src/Renci.SshNet/Renci.SshNet.csproj | 4 +-- 2 files changed, 2 insertions(+), 35 deletions(-) diff --git a/src/Renci.SshNet/Abstractions/CryptoAbstraction.cs b/src/Renci.SshNet/Abstractions/CryptoAbstraction.cs index b2cc3581e..522c25335 100644 --- a/src/Renci.SshNet/Abstractions/CryptoAbstraction.cs +++ b/src/Renci.SshNet/Abstractions/CryptoAbstraction.cs @@ -47,53 +47,20 @@ public static System.Security.Cryptography.SHA1 CreateSHA1() return System.Security.Cryptography.SHA1.Create(); } -#if FEATURE_HASH_SHA256_CREATE || FEATURE_HASH_SHA256_MANAGED public static System.Security.Cryptography.SHA256 CreateSHA256() { -#if FEATURE_HASH_SHA256_CREATE return System.Security.Cryptography.SHA256.Create(); -#elif FEATURE_HASH_SHA256_MANAGED - return new System.Security.Cryptography.SHA256Managed(); -#endif - } -#else - public static global::SshNet.Security.Cryptography.SHA256 CreateSHA256() - { - return new global::SshNet.Security.Cryptography.SHA256(); } -#endif -#if FEATURE_HASH_SHA384_CREATE || FEATURE_HASH_SHA384_MANAGED public static System.Security.Cryptography.SHA384 CreateSHA384() { -#if FEATURE_HASH_SHA384_CREATE return System.Security.Cryptography.SHA384.Create(); -#elif FEATURE_HASH_SHA384_MANAGED - return new System.Security.Cryptography.SHA384Managed(); -#endif } -#else - public static global::SshNet.Security.Cryptography.SHA384 CreateSHA384() - { - return new global::SshNet.Security.Cryptography.SHA384(); - } -#endif -#if FEATURE_HASH_SHA512_CREATE || FEATURE_HASH_SHA512_MANAGED public static System.Security.Cryptography.SHA512 CreateSHA512() { -#if FEATURE_HASH_SHA512_CREATE return System.Security.Cryptography.SHA512.Create(); -#elif FEATURE_HASH_SHA512_MANAGED - return new System.Security.Cryptography.SHA512Managed(); -#endif } -#else - public static global::SshNet.Security.Cryptography.SHA512 CreateSHA512() - { - return new global::SshNet.Security.Cryptography.SHA512(); - } -#endif #if FEATURE_HASH_RIPEMD160_CREATE || FEATURE_HASH_RIPEMD160_MANAGED public static System.Security.Cryptography.RIPEMD160 CreateRIPEMD160() diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj index a62c34a65..b77abb4c9 100644 --- a/src/Renci.SshNet/Renci.SshNet.csproj +++ b/src/Renci.SshNet/Renci.SshNet.csproj @@ -11,7 +11,7 @@ - FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160 + FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160 @@ -19,6 +19,6 @@ - FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512 + FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512 From 9a1f6759d55f1dfd7798b6f83c73502897a327e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Nag=C3=B3rski?= Date: Mon, 8 May 2023 12:41:08 +0200 Subject: [PATCH 16/23] Remove FEATURE_HMAC_* --- .../Abstractions/CryptoAbstraction.cs | 60 ------------------- src/Renci.SshNet/Renci.SshNet.csproj | 4 +- .../Security/Cryptography/HMACMD5.cs | 6 +- .../Security/Cryptography/HMACSHA1.cs | 6 +- .../Security/Cryptography/HMACSHA256.cs | 6 +- .../Security/Cryptography/HMACSHA384.cs | 6 +- .../Security/Cryptography/HMACSHA512.cs | 6 +- 7 files changed, 7 insertions(+), 87 deletions(-) diff --git a/src/Renci.SshNet/Abstractions/CryptoAbstraction.cs b/src/Renci.SshNet/Abstractions/CryptoAbstraction.cs index 522c25335..2c7d38b0c 100644 --- a/src/Renci.SshNet/Abstractions/CryptoAbstraction.cs +++ b/src/Renci.SshNet/Abstractions/CryptoAbstraction.cs @@ -78,7 +78,6 @@ public static System.Security.Cryptography.RIPEMD160 CreateRIPEMD160() } #endif // FEATURE_HASH_RIPEMD160 -#if FEATURE_HMAC_MD5 public static System.Security.Cryptography.HMACMD5 CreateHMACMD5(byte[] key) { return new System.Security.Cryptography.HMACMD5(key); @@ -88,19 +87,7 @@ public static HMACMD5 CreateHMACMD5(byte[] key, int hashSize) { return new HMACMD5(key, hashSize); } -#else - public static global::SshNet.Security.Cryptography.HMACMD5 CreateHMACMD5(byte[] key) - { - return new global::SshNet.Security.Cryptography.HMACMD5(key); - } - - public static global::SshNet.Security.Cryptography.HMACMD5 CreateHMACMD5(byte[] key, int hashSize) - { - return new global::SshNet.Security.Cryptography.HMACMD5(key, hashSize); - } -#endif // FEATURE_HMAC_MD5 -#if FEATURE_HMAC_SHA1 public static System.Security.Cryptography.HMACSHA1 CreateHMACSHA1(byte[] key) { return new System.Security.Cryptography.HMACSHA1(key); @@ -110,19 +97,7 @@ public static HMACSHA1 CreateHMACSHA1(byte[] key, int hashSize) { return new HMACSHA1(key, hashSize); } -#else - public static global::SshNet.Security.Cryptography.HMACSHA1 CreateHMACSHA1(byte[] key) - { - return new global::SshNet.Security.Cryptography.HMACSHA1(key); - } - - public static global::SshNet.Security.Cryptography.HMACSHA1 CreateHMACSHA1(byte[] key, int hashSize) - { - return new global::SshNet.Security.Cryptography.HMACSHA1(key, hashSize); - } -#endif // FEATURE_HMAC_SHA1 -#if FEATURE_HMAC_SHA256 public static System.Security.Cryptography.HMACSHA256 CreateHMACSHA256(byte[] key) { return new System.Security.Cryptography.HMACSHA256(key); @@ -132,19 +107,7 @@ public static HMACSHA256 CreateHMACSHA256(byte[] key, int hashSize) { return new HMACSHA256(key, hashSize); } -#else - public static global::SshNet.Security.Cryptography.HMACSHA256 CreateHMACSHA256(byte[] key) - { - return new global::SshNet.Security.Cryptography.HMACSHA256(key); - } - public static global::SshNet.Security.Cryptography.HMACSHA256 CreateHMACSHA256(byte[] key, int hashSize) - { - return new global::SshNet.Security.Cryptography.HMACSHA256(key, hashSize); - } -#endif // FEATURE_HMAC_SHA256 - -#if FEATURE_HMAC_SHA384 public static System.Security.Cryptography.HMACSHA384 CreateHMACSHA384(byte[] key) { return new System.Security.Cryptography.HMACSHA384(key); @@ -154,19 +117,7 @@ public static HMACSHA384 CreateHMACSHA384(byte[] key, int hashSize) { return new HMACSHA384(key, hashSize); } -#else - public static global::SshNet.Security.Cryptography.HMACSHA384 CreateHMACSHA384(byte[] key) - { - return new global::SshNet.Security.Cryptography.HMACSHA384(key); - } - public static global::SshNet.Security.Cryptography.HMACSHA384 CreateHMACSHA384(byte[] key, int hashSize) - { - return new global::SshNet.Security.Cryptography.HMACSHA384(key, hashSize); - } -#endif // FEATURE_HMAC_SHA384 - -#if FEATURE_HMAC_SHA512 public static System.Security.Cryptography.HMACSHA512 CreateHMACSHA512(byte[] key) { return new System.Security.Cryptography.HMACSHA512(key); @@ -176,17 +127,6 @@ public static HMACSHA512 CreateHMACSHA512(byte[] key, int hashSize) { return new HMACSHA512(key, hashSize); } -#else - public static global::SshNet.Security.Cryptography.HMACSHA512 CreateHMACSHA512(byte[] key) - { - return new global::SshNet.Security.Cryptography.HMACSHA512(key); - } - - public static global::SshNet.Security.Cryptography.HMACSHA512 CreateHMACSHA512(byte[] key, int hashSize) - { - return new global::SshNet.Security.Cryptography.HMACSHA512(key, hashSize); - } -#endif // FEATURE_HMAC_SHA512 #if FEATURE_HMAC_RIPEMD160 public static System.Security.Cryptography.HMACRIPEMD160 CreateHMACRIPEMD160(byte[] key) diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj index b77abb4c9..a464645a7 100644 --- a/src/Renci.SshNet/Renci.SshNet.csproj +++ b/src/Renci.SshNet/Renci.SshNet.csproj @@ -11,7 +11,7 @@ - FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160 + FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_RIPEMD160 @@ -19,6 +19,6 @@ - FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512 + FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE diff --git a/src/Renci.SshNet/Security/Cryptography/HMACMD5.cs b/src/Renci.SshNet/Security/Cryptography/HMACMD5.cs index 86b246432..cd129fe69 100644 --- a/src/Renci.SshNet/Security/Cryptography/HMACMD5.cs +++ b/src/Renci.SshNet/Security/Cryptography/HMACMD5.cs @@ -1,6 +1,4 @@ -#if FEATURE_HMAC_MD5 - -using System.Security.Cryptography; +using System.Security.Cryptography; using Renci.SshNet.Common; namespace Renci.SshNet.Security.Cryptography @@ -57,5 +55,3 @@ protected override byte[] HashFinal() } } } - -#endif // FEATURE_HMAC_MD5 diff --git a/src/Renci.SshNet/Security/Cryptography/HMACSHA1.cs b/src/Renci.SshNet/Security/Cryptography/HMACSHA1.cs index d8f47af12..49ad384d4 100644 --- a/src/Renci.SshNet/Security/Cryptography/HMACSHA1.cs +++ b/src/Renci.SshNet/Security/Cryptography/HMACSHA1.cs @@ -1,6 +1,4 @@ -#if FEATURE_HMAC_SHA1 - -using System.Security.Cryptography; +using System.Security.Cryptography; using Renci.SshNet.Common; namespace Renci.SshNet.Security.Cryptography @@ -57,5 +55,3 @@ protected override byte[] HashFinal() } } } - -#endif // FEATURE_HMAC_SHA1 diff --git a/src/Renci.SshNet/Security/Cryptography/HMACSHA256.cs b/src/Renci.SshNet/Security/Cryptography/HMACSHA256.cs index cb1c31859..2598704e4 100644 --- a/src/Renci.SshNet/Security/Cryptography/HMACSHA256.cs +++ b/src/Renci.SshNet/Security/Cryptography/HMACSHA256.cs @@ -1,6 +1,4 @@ -#if FEATURE_HMAC_SHA256 - -using System.Security.Cryptography; +using System.Security.Cryptography; using Renci.SshNet.Common; namespace Renci.SshNet.Security.Cryptography @@ -58,5 +56,3 @@ protected override byte[] HashFinal() } } } - -#endif // FEATURE_HMAC_SHA256 diff --git a/src/Renci.SshNet/Security/Cryptography/HMACSHA384.cs b/src/Renci.SshNet/Security/Cryptography/HMACSHA384.cs index 142e51ed7..f5f0b26c5 100644 --- a/src/Renci.SshNet/Security/Cryptography/HMACSHA384.cs +++ b/src/Renci.SshNet/Security/Cryptography/HMACSHA384.cs @@ -1,6 +1,4 @@ -#if FEATURE_HMAC_SHA384 - -using System.Security.Cryptography; +using System.Security.Cryptography; using Renci.SshNet.Common; namespace Renci.SshNet.Security.Cryptography @@ -57,5 +55,3 @@ protected override byte[] HashFinal() } } } - -#endif // FEATURE_HMAC_SHA384 diff --git a/src/Renci.SshNet/Security/Cryptography/HMACSHA512.cs b/src/Renci.SshNet/Security/Cryptography/HMACSHA512.cs index a297ed088..72e758155 100644 --- a/src/Renci.SshNet/Security/Cryptography/HMACSHA512.cs +++ b/src/Renci.SshNet/Security/Cryptography/HMACSHA512.cs @@ -1,6 +1,4 @@ -#if FEATURE_HMAC_SHA512 - -using System.Security.Cryptography; +using System.Security.Cryptography; using Renci.SshNet.Common; namespace Renci.SshNet.Security.Cryptography @@ -57,5 +55,3 @@ protected override byte[] HashFinal() } } } - -#endif // FEATURE_HMAC_SHA512 From 6fa98bba02751d9c4f4e0acbd8d59f772acedc5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Nag=C3=B3rski?= Date: Mon, 8 May 2023 12:42:12 +0200 Subject: [PATCH 17/23] Remove FEATURE_WAITHANDLE_DISPOSE --- src/Renci.SshNet/Common/Extensions.cs | 15 --------------- src/Renci.SshNet/NoneAuthenticationMethod.cs | 3 --- src/Renci.SshNet/Renci.SshNet.csproj | 4 ++-- 3 files changed, 2 insertions(+), 20 deletions(-) diff --git a/src/Renci.SshNet/Common/Extensions.cs b/src/Renci.SshNet/Common/Extensions.cs index 6b10675c7..3a5311f07 100644 --- a/src/Renci.SshNet/Common/Extensions.cs +++ b/src/Renci.SshNet/Common/Extensions.cs @@ -302,20 +302,5 @@ internal static bool IsConnected(this Socket socket) return false; return socket.Connected; } - -#if !FEATURE_WAITHANDLE_DISPOSE - /// - /// Disposes the specified handle. - /// - /// The handle. - [DebuggerNonUserCode] - internal static void Dispose(this WaitHandle handle) - { - if (handle == null) - throw new NullReferenceException(); - - handle.Close(); - } -#endif // !FEATURE_WAITHANDLE_DISPOSE } } diff --git a/src/Renci.SshNet/NoneAuthenticationMethod.cs b/src/Renci.SshNet/NoneAuthenticationMethod.cs index a5d842fd7..93586ade9 100644 --- a/src/Renci.SshNet/NoneAuthenticationMethod.cs +++ b/src/Renci.SshNet/NoneAuthenticationMethod.cs @@ -1,8 +1,5 @@ using System; using System.Threading; -#if !FEATURE_WAITHANDLE_DISPOSE -using Renci.SshNet.Common; -#endif // !FEATURE_WAITHANDLE_DISPOSE using Renci.SshNet.Messages.Authentication; using Renci.SshNet.Messages; diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj index a464645a7..6fc73eae9 100644 --- a/src/Renci.SshNet/Renci.SshNet.csproj +++ b/src/Renci.SshNet/Renci.SshNet.csproj @@ -11,7 +11,7 @@ - FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_RIPEMD160 + FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_RIPEMD160 @@ -19,6 +19,6 @@ - FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_WAITHANDLE_DISPOSE + FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP From 1b6977ea36b223ebf9ce08ad8ef2758154e1ba33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Nag=C3=B3rski?= Date: Mon, 8 May 2023 12:43:07 +0200 Subject: [PATCH 18/23] Remove FEATURE_THREAD_THREADPOOL --- src/Renci.SshNet/Abstractions/ThreadAbstraction.cs | 6 ------ src/Renci.SshNet/Renci.SshNet.csproj | 4 ++-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/Renci.SshNet/Abstractions/ThreadAbstraction.cs b/src/Renci.SshNet/Abstractions/ThreadAbstraction.cs index 8c344404b..bff46f358 100644 --- a/src/Renci.SshNet/Abstractions/ThreadAbstraction.cs +++ b/src/Renci.SshNet/Abstractions/ThreadAbstraction.cs @@ -41,16 +41,10 @@ public static void ExecuteThreadLongRunning(Action action) /// The action to execute. public static void ExecuteThread(Action action) { -#if FEATURE_THREAD_THREADPOOL if (action == null) throw new ArgumentNullException("action"); System.Threading.ThreadPool.QueueUserWorkItem(o => action()); -#elif FEATURE_THREAD_TAP - System.Threading.Tasks.Task.Run(action); -#else - #error Execution of action in a separate thread is not implemented. -#endif } } } diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj index 6fc73eae9..26691ceea 100644 --- a/src/Renci.SshNet/Renci.SshNet.csproj +++ b/src/Renci.SshNet/Renci.SshNet.csproj @@ -11,7 +11,7 @@ - FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_RIPEMD160 + FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_SLEEP;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_RIPEMD160 @@ -19,6 +19,6 @@ - FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP + FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_SLEEP From 60aacc3bc33995ba268ff3b187c7ade55cb4c369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Nag=C3=B3rski?= Date: Mon, 8 May 2023 12:44:34 +0200 Subject: [PATCH 19/23] Remove FEATURE_THREAD_COUNTDOWNEVENT --- .../Classes/Common/CountdownEventTest.cs | 3 - .../CountdownEventTest_Dispose_NotSet.cs | 4 - .../Common/CountdownEventTest_Dispose_Set.cs | 4 - .../Renci.SshNet.Tests.csproj | 2 +- src/Renci.SshNet/Common/CountdownEvent.cs | 171 ------------------ src/Renci.SshNet/Renci.SshNet.csproj | 4 +- 6 files changed, 3 insertions(+), 185 deletions(-) delete mode 100644 src/Renci.SshNet/Common/CountdownEvent.cs diff --git a/src/Renci.SshNet.Tests/Classes/Common/CountdownEventTest.cs b/src/Renci.SshNet.Tests/Classes/Common/CountdownEventTest.cs index 6954beb14..6ab52acef 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/CountdownEventTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/CountdownEventTest.cs @@ -2,9 +2,6 @@ using System.Diagnostics; using System.Threading; using Microsoft.VisualStudio.TestTools.UnitTesting; -#if !FEATURE_THREAD_COUNTDOWNEVENT -using CountdownEvent = Renci.SshNet.Common.CountdownEvent; -#endif namespace Renci.SshNet.Tests.Classes.Common { diff --git a/src/Renci.SshNet.Tests/Classes/Common/CountdownEventTest_Dispose_NotSet.cs b/src/Renci.SshNet.Tests/Classes/Common/CountdownEventTest_Dispose_NotSet.cs index 3d5a5d17d..a2badf97e 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/CountdownEventTest_Dispose_NotSet.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/CountdownEventTest_Dispose_NotSet.cs @@ -1,10 +1,6 @@ using System; using Microsoft.VisualStudio.TestTools.UnitTesting; -#if !FEATURE_THREAD_COUNTDOWNEVENT -using CountdownEvent = Renci.SshNet.Common.CountdownEvent; -#else using System.Threading; -#endif namespace Renci.SshNet.Tests.Classes.Common { diff --git a/src/Renci.SshNet.Tests/Classes/Common/CountdownEventTest_Dispose_Set.cs b/src/Renci.SshNet.Tests/Classes/Common/CountdownEventTest_Dispose_Set.cs index 60f13c302..df5f5b979 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/CountdownEventTest_Dispose_Set.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/CountdownEventTest_Dispose_Set.cs @@ -1,10 +1,6 @@ using System; using Microsoft.VisualStudio.TestTools.UnitTesting; -#if !FEATURE_THREAD_COUNTDOWNEVENT -using CountdownEvent = Renci.SshNet.Common.CountdownEvent; -#else using System.Threading; -#endif namespace Renci.SshNet.Tests.Classes.Common { diff --git a/src/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj b/src/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj index 665ccf11f..80c36aa70 100644 --- a/src/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj +++ b/src/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj @@ -7,7 +7,7 @@ - FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_TPL + FEATURE_TPL diff --git a/src/Renci.SshNet/Common/CountdownEvent.cs b/src/Renci.SshNet/Common/CountdownEvent.cs deleted file mode 100644 index 7387a786f..000000000 --- a/src/Renci.SshNet/Common/CountdownEvent.cs +++ /dev/null @@ -1,171 +0,0 @@ -#if !FEATURE_THREAD_COUNTDOWNEVENT - -using System; -using System.Threading; - -namespace Renci.SshNet.Common -{ - /// - /// Represents a synchronization primitive that is signaled when its count reaches zero. - /// - internal class CountdownEvent : IDisposable - { - private int _count; - private ManualResetEvent _event; - private bool _disposed; - - /// - /// Initializes a new instance of class with the specified count. - /// - /// The number of signals initially required to set the . - /// is less than zero. - /// - /// If is zero, the event is created in a signaled state. - /// - public CountdownEvent(int initialCount) - { - if (initialCount < 0) - { - throw new ArgumentOutOfRangeException("initialCount"); - } - - _count = initialCount; - - var initialState = _count == 0; - _event = new ManualResetEvent(initialState); - } - - /// - /// Gets the number of remaining signals required to set the event. - /// - /// - /// The number of remaining signals required to set the event. - /// - public int CurrentCount - { - get { return _count; } - } - - /// - /// Indicates whether the 's current count has reached zero. - /// - /// - /// true if the current count is zero; otherwise, false. - /// - public bool IsSet - { - get { return _count == 0; } - } - - /// - /// Gets a that is used to wait for the event to be set. - /// - /// - /// A that is used to wait for the event to be set. - /// - /// The current instance has already been disposed. - public WaitHandle WaitHandle - { - get - { - EnsureNotDisposed(); - - return _event; - } - } - - - /// - /// Registers a signal with the , decrementing the value of . - /// - /// - /// true if the signal caused the count to reach zero and the event was set; otherwise, false. - /// - /// The current instance has already been disposed. - /// The current instance is already set. - public bool Signal() - { - EnsureNotDisposed(); - - if (_count <= 0) - throw new InvalidOperationException("Invalid attempt made to decrement the event's count below zero."); - - var newCount = Interlocked.Decrement(ref _count); - if (newCount == 0) - { - _event.Set(); - return true; - } - - return false; - } - - /// - /// Increments the 's current count by one. - /// - /// The current instance has already been disposed. - /// The current instance is already set. - /// is equal to or greather than . - public void AddCount() - { - EnsureNotDisposed(); - - if (_count == int.MaxValue) - throw new InvalidOperationException("TODO"); - - Interlocked.Increment(ref _count); - } - - /// - /// Blocks the current thread until the is set, using a - /// to measure the timeout. - /// - /// A that represents the number of milliseconds to wait, or a that represents -1 milliseconds to wait indefinitely. - /// - /// true if the was set; otherwise, false. - /// - /// The current instance has already been disposed. - public bool Wait(TimeSpan timeout) - { - EnsureNotDisposed(); - - return _event.WaitOne(timeout); - } - - /// - /// Releases all resources used by the current instance of the class. - /// - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - /// - /// Releases the unmanaged resources used by the , and optionally releases the managed resources. - /// - /// true to release both managed and unmanaged resources; false to release only unmanaged resources. - protected virtual void Dispose(bool disposing) - { - if (disposing) - { - var theEvent = _event; - if (theEvent != null) - { - _event = null; - theEvent.Dispose(); - } - - _disposed = true; - } - } - - private void EnsureNotDisposed() - { - if (_disposed) - throw new ObjectDisposedException(GetType().Name); - } - } -} - -#endif // FEATURE_THREAD_COUNTDOWNEVENT \ No newline at end of file diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj index 26691ceea..7acb673b9 100644 --- a/src/Renci.SshNet/Renci.SshNet.csproj +++ b/src/Renci.SshNet/Renci.SshNet.csproj @@ -11,7 +11,7 @@ - FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_SLEEP;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_RIPEMD160 + FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_SLEEP;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_RIPEMD160 @@ -19,6 +19,6 @@ - FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_TAP;FEATURE_THREAD_SLEEP + FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_TAP;FEATURE_THREAD_SLEEP From c685b6e1408c4428e877a84fe0d8d60d4ee38c7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Nag=C3=B3rski?= Date: Mon, 8 May 2023 12:48:27 +0200 Subject: [PATCH 20/23] Remove FEATURE_THREAD_SLEEP and FEATURE_THREAD_TAP --- src/Renci.SshNet/Abstractions/ThreadAbstraction.cs | 13 ------------- src/Renci.SshNet/Renci.SshNet.csproj | 4 ++-- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/src/Renci.SshNet/Abstractions/ThreadAbstraction.cs b/src/Renci.SshNet/Abstractions/ThreadAbstraction.cs index bff46f358..35824ee10 100644 --- a/src/Renci.SshNet/Abstractions/ThreadAbstraction.cs +++ b/src/Renci.SshNet/Abstractions/ThreadAbstraction.cs @@ -10,13 +10,7 @@ internal static class ThreadAbstraction /// The number of milliseconds for which the thread is suspended. public static void Sleep(int millisecondsTimeout) { -#if FEATURE_THREAD_SLEEP System.Threading.Thread.Sleep(millisecondsTimeout); -#elif FEATURE_THREAD_TAP - System.Threading.Tasks.Task.Delay(millisecondsTimeout).GetAwaiter().GetResult(); -#else - #error Suspend of the current thread is not implemented. -#endif } public static void ExecuteThreadLongRunning(Action action) @@ -24,15 +18,8 @@ public static void ExecuteThreadLongRunning(Action action) if (action == null) throw new ArgumentNullException("action"); -#if FEATURE_THREAD_TAP var taskCreationOptions = System.Threading.Tasks.TaskCreationOptions.LongRunning; System.Threading.Tasks.Task.Factory.StartNew(action, taskCreationOptions); -#else - new System.Threading.Thread(() => action()) - { - IsBackground = true - }.Start(); -#endif } /// diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj index 7acb673b9..39e2ada6c 100644 --- a/src/Renci.SshNet/Renci.SshNet.csproj +++ b/src/Renci.SshNet/Renci.SshNet.csproj @@ -11,7 +11,7 @@ - FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_SLEEP;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_RIPEMD160 + FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_RIPEMD160 @@ -19,6 +19,6 @@ - FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP;FEATURE_THREAD_TAP;FEATURE_THREAD_SLEEP + FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP From f7782beb1a19f9c465d78ec2261cd46f2092abe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Nag=C3=B3rski?= Date: Mon, 8 May 2023 12:51:49 +0200 Subject: [PATCH 21/23] Remove FEATURE_STREAM_APM and FEATURE_STREAM_TAP --- src/Renci.SshNet/Renci.SshNet.csproj | 4 ++-- src/Renci.SshNet/Shell.cs | 18 ------------------ 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj index 39e2ada6c..ee071bb8b 100644 --- a/src/Renci.SshNet/Renci.SshNet.csproj +++ b/src/Renci.SshNet/Renci.SshNet.csproj @@ -11,7 +11,7 @@ - FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_RIPEMD160 + FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_DNS_SYNC;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_RIPEMD160 @@ -19,6 +19,6 @@ - FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP;FEATURE_STREAM_APM;FEATURE_STREAM_TAP + FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP diff --git a/src/Renci.SshNet/Shell.cs b/src/Renci.SshNet/Shell.cs index c508be896..3e68e6b12 100644 --- a/src/Renci.SshNet/Shell.cs +++ b/src/Renci.SshNet/Shell.cs @@ -129,7 +129,6 @@ public void Start() while (_channel.IsOpen) { -#if FEATURE_STREAM_TAP var readTask = _input.ReadAsync(buffer, 0, buffer.Length); var readWaitHandle = ((IAsyncResult) readTask).AsyncWaitHandle; @@ -139,24 +138,7 @@ public void Start() _channel.SendData(buffer, 0, read); continue; } -#elif FEATURE_STREAM_APM - var asyncResult = _input.BeginRead(buffer, 0, buffer.Length, result => - { - // If input stream is closed and disposed already don't finish reading the stream - if (_input == null) - return; - var read = _input.EndRead(result); - _channel.SendData(buffer, 0, read); - }, null); - - WaitHandle.WaitAny(new[] { asyncResult.AsyncWaitHandle, _channelClosedWaitHandle }); - - if (asyncResult.IsCompleted) - continue; -#else - #error Async receive is not implemented. -#endif break; } } From 8f18f8531cc79a3a4aaa7be4fea79ded642ac4b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Nag=C3=B3rski?= Date: Mon, 8 May 2023 13:23:14 +0200 Subject: [PATCH 22/23] Remove FEATURE_SOCKET_EAP --- .../Abstractions/SocketAbstraction.cs | 347 +----------------- src/Renci.SshNet/Renci.SshNet.csproj | 4 +- 2 files changed, 3 insertions(+), 348 deletions(-) diff --git a/src/Renci.SshNet/Abstractions/SocketAbstraction.cs b/src/Renci.SshNet/Abstractions/SocketAbstraction.cs index f57ea8482..1be2b46d7 100644 --- a/src/Renci.SshNet/Abstractions/SocketAbstraction.cs +++ b/src/Renci.SshNet/Abstractions/SocketAbstraction.cs @@ -142,7 +142,6 @@ public static void ClearReadBuffer(Socket socket) public static int ReadPartial(Socket socket, byte[] buffer, int offset, int size, TimeSpan timeout) { -#if FEATURE_SOCKET_SYNC socket.ReceiveTimeout = (int) timeout.TotalMilliseconds; try @@ -156,53 +155,10 @@ public static int ReadPartial(Socket socket, byte[] buffer, int offset, int size "Socket read operation has timed out after {0:F0} milliseconds.", timeout.TotalMilliseconds)); throw; } -#elif FEATURE_SOCKET_EAP - var receiveCompleted = new ManualResetEvent(false); - var sendReceiveToken = new PartialSendReceiveToken(socket, receiveCompleted); - var args = new SocketAsyncEventArgs - { - RemoteEndPoint = socket.RemoteEndPoint, - UserToken = sendReceiveToken - }; - args.Completed += ReceiveCompleted; - args.SetBuffer(buffer, offset, size); - - try - { - if (socket.ReceiveAsync(args)) - { - if (!receiveCompleted.WaitOne(timeout)) - throw new SshOperationTimeoutException( - string.Format( - CultureInfo.InvariantCulture, - "Socket read operation has timed out after {0:F0} milliseconds.", - timeout.TotalMilliseconds)); - } - else - { - sendReceiveToken.Process(args); - } - - if (args.SocketError != SocketError.Success) - throw new SocketException((int) args.SocketError); - - return args.BytesTransferred; - } - finally - { - // initialize token to avoid the waithandle getting used after it's disposed - args.UserToken = null; - args.Dispose(); - receiveCompleted.Dispose(); - } -#else - #error Receiving data from a Socket is not implemented. -#endif } public static void ReadContinuous(Socket socket, byte[] buffer, int offset, int size, Action processReceivedBytesAction) { -#if FEATURE_SOCKET_SYNC // do not time-out receive socket.ReceiveTimeout = 0; @@ -236,30 +192,6 @@ public static void ReadContinuous(Socket socket, byte[] buffer, int offset, int } } } -#elif FEATURE_SOCKET_EAP - var completionWaitHandle = new ManualResetEvent(false); - var readToken = new ContinuousReceiveToken(socket, processReceivedBytesAction, completionWaitHandle); - var args = new SocketAsyncEventArgs - { - RemoteEndPoint = socket.RemoteEndPoint, - UserToken = readToken - }; - args.Completed += ReceiveCompleted; - args.SetBuffer(buffer, offset, size); - - if (!socket.ReceiveAsync(args)) - { - ReceiveCompleted(null, args); - } - - completionWaitHandle.WaitOne(); - completionWaitHandle.Dispose(); - - if (readToken.Exception != null) - throw readToken.Exception; -#else - #error Receiving data from a Socket is not implemented. -#endif } /// @@ -345,7 +277,6 @@ public static Task ReadAsync(Socket socket, byte[] buffer, int offset, int /// public static int Read(Socket socket, byte[] buffer, int offset, int size, TimeSpan readTimeout) { -#if FEATURE_SOCKET_SYNC var totalBytesRead = 0; var totalBytesToRead = size; @@ -373,52 +304,12 @@ public static int Read(Socket socket, byte[] buffer, int offset, int size, TimeS throw new SshOperationTimeoutException(string.Format(CultureInfo.InvariantCulture, "Socket read operation has timed out after {0:F0} milliseconds.", readTimeout.TotalMilliseconds)); - throw; + throw; } } while (totalBytesRead < totalBytesToRead); return totalBytesRead; -#elif FEATURE_SOCKET_EAP - var receiveCompleted = new ManualResetEvent(false); - var sendReceiveToken = new BlockingSendReceiveToken(socket, buffer, offset, size, receiveCompleted); - - var args = new SocketAsyncEventArgs - { - UserToken = sendReceiveToken, - RemoteEndPoint = socket.RemoteEndPoint - }; - args.Completed += ReceiveCompleted; - args.SetBuffer(buffer, offset, size); - - try - { - if (socket.ReceiveAsync(args)) - { - if (!receiveCompleted.WaitOne(readTimeout)) - throw new SshOperationTimeoutException(string.Format(CultureInfo.InvariantCulture, - "Socket read operation has timed out after {0:F0} milliseconds.", readTimeout.TotalMilliseconds)); - } - else - { - sendReceiveToken.Process(args); - } - - if (args.SocketError != SocketError.Success) - throw new SocketException((int) args.SocketError); - - return sendReceiveToken.TotalBytesTransferred; - } - finally - { - // initialize token to avoid the waithandle getting used after it's disposed - args.UserToken = null; - args.Dispose(); - receiveCompleted.Dispose(); - } -#else -#error Receiving data from a Socket is not implemented. -#endif } public static void Send(Socket socket, byte[] data) @@ -428,7 +319,6 @@ public static void Send(Socket socket, byte[] data) public static void Send(Socket socket, byte[] data, int offset, int size) { -#if FEATURE_SOCKET_SYNC var totalBytesSent = 0; // how many bytes are already sent var totalBytesToSend = size; @@ -454,46 +344,6 @@ public static void Send(Socket socket, byte[] data, int offset, int size) throw; // any serious error occurr } } while (totalBytesSent < totalBytesToSend); -#elif FEATURE_SOCKET_EAP - var sendCompleted = new ManualResetEvent(false); - var sendReceiveToken = new BlockingSendReceiveToken(socket, data, offset, size, sendCompleted); - var socketAsyncSendArgs = new SocketAsyncEventArgs - { - RemoteEndPoint = socket.RemoteEndPoint, - UserToken = sendReceiveToken - }; - socketAsyncSendArgs.SetBuffer(data, offset, size); - socketAsyncSendArgs.Completed += SendCompleted; - - try - { - if (socket.SendAsync(socketAsyncSendArgs)) - { - if (!sendCompleted.WaitOne()) - throw new SocketException((int) SocketError.TimedOut); - } - else - { - sendReceiveToken.Process(socketAsyncSendArgs); - } - - if (socketAsyncSendArgs.SocketError != SocketError.Success) - throw new SocketException((int) socketAsyncSendArgs.SocketError); - - if (sendReceiveToken.TotalBytesTransferred == 0) - throw new SshConnectionException("An established connection was aborted by the server.", - DisconnectReason.ConnectionLost); - } - finally - { - // initialize token to avoid the completion waithandle getting used after it's disposed - socketAsyncSendArgs.UserToken = null; - socketAsyncSendArgs.Dispose(); - sendCompleted.Dispose(); - } -#else - #error Sending data to a Socket is not implemented. -#endif } public static bool IsErrorResumable(SocketError socketError) @@ -517,200 +367,5 @@ private static void ConnectCompleted(object sender, SocketAsyncEventArgs e) eventWaitHandle.Set(); } #endif // FEATURE_SOCKET_EAP - -#if FEATURE_SOCKET_EAP && !FEATURE_SOCKET_SYNC - private static void ReceiveCompleted(object sender, SocketAsyncEventArgs e) - { - var sendReceiveToken = (Token) e.UserToken; - if (sendReceiveToken != null) - sendReceiveToken.Process(e); - } - - private static void SendCompleted(object sender, SocketAsyncEventArgs e) - { - var sendReceiveToken = (Token) e.UserToken; - if (sendReceiveToken != null) - sendReceiveToken.Process(e); - } - - private interface Token - { - void Process(SocketAsyncEventArgs args); - } - - private class BlockingSendReceiveToken : Token - { - public BlockingSendReceiveToken(Socket socket, byte[] buffer, int offset, int size, EventWaitHandle completionWaitHandle) - { - _socket = socket; - _buffer = buffer; - _offset = offset; - _bytesToTransfer = size; - _completionWaitHandle = completionWaitHandle; - } - - public void Process(SocketAsyncEventArgs args) - { - if (args.SocketError == SocketError.Success) - { - TotalBytesTransferred += args.BytesTransferred; - - if (TotalBytesTransferred == _bytesToTransfer) - { - // finished transferring specified bytes - _completionWaitHandle.Set(); - return; - } - - if (args.BytesTransferred == 0) - { - // remote server closed the connection - _completionWaitHandle.Set(); - return; - } - - _offset += args.BytesTransferred; - args.SetBuffer(_buffer, _offset, _bytesToTransfer - TotalBytesTransferred); - ResumeOperation(args); - return; - } - - if (IsErrorResumable(args.SocketError)) - { - ThreadAbstraction.Sleep(30); - ResumeOperation(args); - return; - } - - // we're dealing with a (fatal) error - _completionWaitHandle.Set(); - } - - private void ResumeOperation(SocketAsyncEventArgs args) - { - switch (args.LastOperation) - { - case SocketAsyncOperation.Receive: - _socket.ReceiveAsync(args); - break; - case SocketAsyncOperation.Send: - _socket.SendAsync(args); - break; - } - } - - private readonly int _bytesToTransfer; - public int TotalBytesTransferred { get; private set; } - private readonly EventWaitHandle _completionWaitHandle; - private readonly Socket _socket; - private readonly byte[] _buffer; - private int _offset; - } - - private class PartialSendReceiveToken : Token - { - public PartialSendReceiveToken(Socket socket, EventWaitHandle completionWaitHandle) - { - _socket = socket; - _completionWaitHandle = completionWaitHandle; - } - - public void Process(SocketAsyncEventArgs args) - { - if (args.SocketError == SocketError.Success) - { - _completionWaitHandle.Set(); - return; - } - - if (IsErrorResumable(args.SocketError)) - { - ThreadAbstraction.Sleep(30); - ResumeOperation(args); - return; - } - - // we're dealing with a (fatal) error - _completionWaitHandle.Set(); - } - - private void ResumeOperation(SocketAsyncEventArgs args) - { - switch (args.LastOperation) - { - case SocketAsyncOperation.Receive: - _socket.ReceiveAsync(args); - break; - case SocketAsyncOperation.Send: - _socket.SendAsync(args); - break; - } - } - - private readonly EventWaitHandle _completionWaitHandle; - private readonly Socket _socket; - } - - private class ContinuousReceiveToken : Token - { - public ContinuousReceiveToken(Socket socket, Action processReceivedBytesAction, EventWaitHandle completionWaitHandle) - { - _socket = socket; - _processReceivedBytesAction = processReceivedBytesAction; - _completionWaitHandle = completionWaitHandle; - } - - public Exception Exception { get; private set; } - - public void Process(SocketAsyncEventArgs args) - { - if (args.SocketError == SocketError.Success) - { - if (args.BytesTransferred == 0) - { - // remote socket was closed - _completionWaitHandle.Set(); - return; - } - - _processReceivedBytesAction(args.Buffer, args.Offset, args.BytesTransferred); - ResumeOperation(args); - return; - } - - if (IsErrorResumable(args.SocketError)) - { - ThreadAbstraction.Sleep(30); - ResumeOperation(args); - return; - } - - if (args.SocketError != SocketError.OperationAborted) - { - Exception = new SocketException((int) args.SocketError); - } - - // we're dealing with a (fatal) error - _completionWaitHandle.Set(); - } - - private void ResumeOperation(SocketAsyncEventArgs args) - { - switch (args.LastOperation) - { - case SocketAsyncOperation.Receive: - _socket.ReceiveAsync(args); - break; - case SocketAsyncOperation.Send: - _socket.SendAsync(args); - break; - } - } - - private readonly EventWaitHandle _completionWaitHandle; - private readonly Socket _socket; - private readonly Action _processReceivedBytesAction; - } -#endif // FEATURE_SOCKET_EAP && !FEATURE_SOCKET_SYNC } } diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj index ee071bb8b..2f39c80ec 100644 --- a/src/Renci.SshNet/Renci.SshNet.csproj +++ b/src/Renci.SshNet/Renci.SshNet.csproj @@ -11,7 +11,7 @@ - FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_DNS_SYNC;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_RIPEMD160 + FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_DNS_SYNC;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_RIPEMD160 @@ -19,6 +19,6 @@ - FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP + FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP From b89644e7168ad72e11e05759d7394057fc90c0b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Nag=C3=B3rski?= Date: Mon, 8 May 2023 13:29:16 +0200 Subject: [PATCH 23/23] Remove FEATURE_REFLECTION_TYPEINFO --- src/Renci.SshNet/Abstractions/ReflectionAbstraction.cs | 8 -------- src/Renci.SshNet/Abstractions/SocketAbstraction.cs | 1 + 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Renci.SshNet/Abstractions/ReflectionAbstraction.cs b/src/Renci.SshNet/Abstractions/ReflectionAbstraction.cs index 0c7abf5c6..1140c9a60 100644 --- a/src/Renci.SshNet/Abstractions/ReflectionAbstraction.cs +++ b/src/Renci.SshNet/Abstractions/ReflectionAbstraction.cs @@ -1,10 +1,6 @@ using System; using System.Collections.Generic; -#if FEATURE_REFLECTION_TYPEINFO -using System.Reflection; -#else using System.Linq; -#endif // FEATURE_REFLECTION_TYPEINFO namespace Renci.SshNet.Abstractions { @@ -13,12 +9,8 @@ internal static class ReflectionAbstraction public static IEnumerable GetCustomAttributes(this Type type, bool inherit) where T:Attribute { -#if FEATURE_REFLECTION_TYPEINFO - return type.GetTypeInfo().GetCustomAttributes(inherit); -#else var attributes = type.GetCustomAttributes(typeof(T), inherit); return attributes.Cast(); -#endif } } } diff --git a/src/Renci.SshNet/Abstractions/SocketAbstraction.cs b/src/Renci.SshNet/Abstractions/SocketAbstraction.cs index 1be2b46d7..e7740d574 100644 --- a/src/Renci.SshNet/Abstractions/SocketAbstraction.cs +++ b/src/Renci.SshNet/Abstractions/SocketAbstraction.cs @@ -367,5 +367,6 @@ private static void ConnectCompleted(object sender, SocketAsyncEventArgs e) eventWaitHandle.Set(); } #endif // FEATURE_SOCKET_EAP + } }