diff --git a/src/Renci.SshNet.NET35/Common/Extensions.NET35.cs b/src/Renci.SshNet.NET35/Common/Extensions.NET35.cs
index 98900f67..ed198c00 100644
--- a/src/Renci.SshNet.NET35/Common/Extensions.NET35.cs
+++ b/src/Renci.SshNet.NET35/Common/Extensions.NET35.cs
@@ -1,43 +1,15 @@
using System;
using System.Diagnostics;
-using System.Net.Sockets;
using System.Security.Cryptography;
using System.Text;
-using System.Threading;
-namespace Renci.SshNet
+namespace Renci.SshNet.Common
{
///
/// Collection of different extension method specific for .NET 3.5
///
internal static partial class Extensions
{
- ///
- /// Disposes the specified socket.
- ///
- /// The socket.
- [DebuggerNonUserCode]
- internal static void Dispose(this Socket socket)
- {
- if (socket == null)
- throw new NullReferenceException();
-
- socket.Close();
- }
-
- ///
- /// Disposes the specified handle.
- ///
- /// The handle.
- [DebuggerNonUserCode]
- internal static void Dispose(this WaitHandle handle)
- {
- if (handle == null)
- throw new NullReferenceException();
-
- handle.Close();
- }
-
///
/// Disposes the specified algorithm.
///
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 06a7d9c9..a99adce1 100644
--- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs
+++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs
@@ -5,6 +5,9 @@ using System.Net.Sockets;
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/Classes/Common/ExtensionsTest_IsEqualTo_ByteArray.cs b/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_IsEqualTo_ByteArray.cs
index c22696c8..42fe8fd5 100644
--- a/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_IsEqualTo_ByteArray.cs
+++ b/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_IsEqualTo_ByteArray.cs
@@ -1,8 +1,8 @@
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
-using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Renci.SshNet.Common;
namespace Renci.SshNet.Tests.Classes.Common
{
@@ -76,7 +76,7 @@ namespace Renci.SshNet.Tests.Classes.Common
public void ShouldReturnFalseWhenLeftIsNotEqualToRight()
{
Assert.IsFalse(Extensions.IsEqualTo(new byte[] {0x0a}, new byte[] {0x0a, 0x0d}));
- Assert.IsFalse(Extensions.IsEqualTo(new byte[] { 0x0a, 0x0d }, new byte[] { 0x0a }));
+ Assert.IsFalse(Extensions.IsEqualTo(new byte[] {0x0a, 0x0d}, new byte[] {0x0a}));
Assert.IsFalse(Extensions.IsEqualTo(new byte[0], new byte[] { 0x0a }));
Assert.IsFalse(Extensions.IsEqualTo(new byte[] { 0x0a, 0x0d }, new byte[0]));
}
@@ -103,7 +103,7 @@ namespace Renci.SshNet.Tests.Classes.Common
{
var buffer = CreateBuffer(50000);
var left = buffer.Concat(new byte[] {0x0a});
- var right = buffer.Concat(new byte[] { 0x0a });
+ var right = buffer.Concat(new byte[] {0x0a});
const int runs = 10000;
Performance(left, right, runs);
@@ -126,8 +126,8 @@ namespace Renci.SshNet.Tests.Classes.Common
public void Performance_LargeArray_NotEqual_SameLength()
{
var buffer = CreateBuffer(50000);
- var left = buffer.Concat(new byte[] { 0x0a });
- var right = buffer.Concat(new byte[] { 0x0b });
+ var left = buffer.Concat(new byte[] {0x0a});
+ var right = buffer.Concat(new byte[] {0x0b});
const int runs = 10000;
Performance(left, right, runs);
@@ -139,7 +139,7 @@ namespace Renci.SshNet.Tests.Classes.Common
public void Performance_LargeArray_Same()
{
var left = CreateBuffer(50000);
- var right = left.Concat(new byte[] { 0x0a });
+ var right = left.Concat(new byte[] {0x0a});
const int runs = 10000;
Performance(left, right, runs);
@@ -173,7 +173,7 @@ namespace Renci.SshNet.Tests.Classes.Common
for (var i = 0; i < runs; i++)
{
- var result = Enumerable.SequenceEqual(left, right);
+ var result = System.Linq.Enumerable.SequenceEqual(left, right);
}
GC.Collect();
diff --git a/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_Reverse.cs b/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_Reverse.cs
index 040f8283..3088d254 100644
--- a/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_Reverse.cs
+++ b/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_Reverse.cs
@@ -2,6 +2,7 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Renci.SshNet.Common;
namespace Renci.SshNet.Tests.Classes.Common
{
diff --git a/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_Take_Count.cs b/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_Take_Count.cs
index d3526e9f..3d734da1 100644
--- a/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_Take_Count.cs
+++ b/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_Take_Count.cs
@@ -3,6 +3,7 @@ using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Renci.SshNet.Common;
namespace Renci.SshNet.Tests.Classes.Common
{
diff --git a/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_Take_OffsetAndCount.cs b/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_Take_OffsetAndCount.cs
index fd894051..137a3c48 100644
--- a/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_Take_OffsetAndCount.cs
+++ b/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_Take_OffsetAndCount.cs
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Renci.SshNet.Common;
namespace Renci.SshNet.Tests.Classes.Common
{
diff --git a/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_TrimLeadingZeros.cs b/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_TrimLeadingZeros.cs
index 1d53a898..0aecfbe0 100644
--- a/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_TrimLeadingZeros.cs
+++ b/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_TrimLeadingZeros.cs
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Renci.SshNet.Common;
namespace Renci.SshNet.Tests.Classes.Common
{
diff --git a/src/Renci.SshNet.Tests/Classes/ScpClientTest.cs b/src/Renci.SshNet.Tests/Classes/ScpClientTest.cs
index c8e6b332..a7f7da14 100644
--- a/src/Renci.SshNet.Tests/Classes/ScpClientTest.cs
+++ b/src/Renci.SshNet.Tests/Classes/ScpClientTest.cs
@@ -1,4 +1,5 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Renci.SshNet.Common;
using Renci.SshNet.Tests.Common;
using Renci.SshNet.Tests.Properties;
using System;
diff --git a/src/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_SendExecRequestReturnsFalse.cs b/src/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_SendExecRequestReturnsFalse.cs
index 5b1b00b5..a3d1ca09 100644
--- a/src/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_SendExecRequestReturnsFalse.cs
+++ b/src/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_SendExecRequestReturnsFalse.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using System.Globalization;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/AesCipherTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/AesCipherTest.cs
index 61a2c371..ef6b6919 100644
--- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/AesCipherTest.cs
+++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/AesCipherTest.cs
@@ -1,4 +1,5 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Renci.SshNet.Common;
using Renci.SshNet.Security.Cryptography.Ciphers;
using Renci.SshNet.Security.Cryptography.Ciphers.Modes;
using Renci.SshNet.Tests.Common;
diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Arc4CipherTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Arc4CipherTest.cs
index bc9cba60..f83aa7aa 100644
--- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Arc4CipherTest.cs
+++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Arc4CipherTest.cs
@@ -1,5 +1,6 @@
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Renci.SshNet.Common;
using Renci.SshNet.Security.Cryptography.Ciphers;
using Renci.SshNet.Tests.Common;
using Renci.SshNet.Tests.Properties;
diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/DesCipherTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/DesCipherTest.cs
index 4851f38f..1c7bd3a2 100644
--- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/DesCipherTest.cs
+++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/DesCipherTest.cs
@@ -1,5 +1,6 @@
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Renci.SshNet.Common;
using Renci.SshNet.Security.Cryptography.Ciphers;
using Renci.SshNet.Security.Cryptography.Ciphers.Modes;
using Renci.SshNet.Security.Cryptography.Ciphers.Paddings;
diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS5PaddingTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS5PaddingTest.cs
index 814062ad..dd7c2022 100644
--- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS5PaddingTest.cs
+++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS5PaddingTest.cs
@@ -1,4 +1,5 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Renci.SshNet.Common;
using Renci.SshNet.Security.Cryptography.Ciphers.Paddings;
namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Paddings
diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS7PaddingTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS7PaddingTest.cs
index a04efc16..80e5d47f 100644
--- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS7PaddingTest.cs
+++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS7PaddingTest.cs
@@ -1,4 +1,5 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Renci.SshNet.Common;
using Renci.SshNet.Security.Cryptography.Ciphers.Paddings;
namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Paddings
diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileReaderTest_DisposeShouldUnblockReadAndReadAhead.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileReaderTest_DisposeShouldUnblockReadAndReadAhead.cs
index 9ce2eccc..3c6ec9e2 100644
--- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileReaderTest_DisposeShouldUnblockReadAndReadAhead.cs
+++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileReaderTest_DisposeShouldUnblockReadAndReadAhead.cs
@@ -1,5 +1,8 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
+#if !FEATURE_EVENTWAITHANDLE_DISPOSE
+using Renci.SshNet.Common;
+#endif // !FEATURE_EVENTWAITHANDLE_DISPOSE
using Renci.SshNet.Abstractions;
using Renci.SshNet.Sftp;
using System;
@@ -22,7 +25,7 @@ namespace Renci.SshNet.Tests.Classes.Sftp
private SftpCloseAsyncResult _closeAsyncResult;
private SftpFileReader _reader;
private ObjectDisposedException _actualException;
- private ManualResetEvent _disposeCompleted;
+ private EventWaitHandle _disposeCompleted;
[TestCleanup]
public void TearDown()
diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreateNew_FileAccessReadWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreateNew_FileAccessReadWrite.cs
index f6aaa13d..c6a87ce1 100644
--- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreateNew_FileAccessReadWrite.cs
+++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreateNew_FileAccessReadWrite.cs
@@ -3,6 +3,7 @@ using System.IO;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
+using Renci.SshNet.Common;
using Renci.SshNet.Sftp;
namespace Renci.SshNet.Tests.Classes.Sftp
diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreate_FileAccessReadWrite_FileDoesNotExist.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreate_FileAccessReadWrite_FileDoesNotExist.cs
index c7800b95..8b8f50fb 100644
--- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreate_FileAccessReadWrite_FileDoesNotExist.cs
+++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreate_FileAccessReadWrite_FileDoesNotExist.cs
@@ -3,6 +3,7 @@ using System.IO;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
+using Renci.SshNet.Common;
using Renci.SshNet.Sftp;
namespace Renci.SshNet.Tests.Classes.Sftp
diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreate_FileAccessReadWrite_FileExists.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreate_FileAccessReadWrite_FileExists.cs
index d4354d84..235d6d9e 100644
--- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreate_FileAccessReadWrite_FileExists.cs
+++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreate_FileAccessReadWrite_FileExists.cs
@@ -3,6 +3,7 @@ using System.IO;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
+using Renci.SshNet.Common;
using Renci.SshNet.Sftp;
namespace Renci.SshNet.Tests.Classes.Sftp
diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpenOrCreate_FileAccessRead.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpenOrCreate_FileAccessRead.cs
index b69a11df..2f186a41 100644
--- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpenOrCreate_FileAccessRead.cs
+++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpenOrCreate_FileAccessRead.cs
@@ -2,6 +2,7 @@
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
+using Renci.SshNet.Common;
using Renci.SshNet.Sftp;
namespace Renci.SshNet.Tests.Classes.Sftp
diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpenOrCreate_FileAccessReadWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpenOrCreate_FileAccessReadWrite.cs
index 033be06a..834ef790 100644
--- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpenOrCreate_FileAccessReadWrite.cs
+++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpenOrCreate_FileAccessReadWrite.cs
@@ -3,6 +3,7 @@ using System.IO;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
+using Renci.SshNet.Common;
using Renci.SshNet.Sftp;
namespace Renci.SshNet.Tests.Classes.Sftp
diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpen_FileAccessRead.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpen_FileAccessRead.cs
index f9445ea8..65232baf 100644
--- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpen_FileAccessRead.cs
+++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpen_FileAccessRead.cs
@@ -2,6 +2,7 @@
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
+using Renci.SshNet.Common;
using Renci.SshNet.Sftp;
namespace Renci.SshNet.Tests.Classes.Sftp
diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpen_FileAccessReadWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpen_FileAccessReadWrite.cs
index 1ad153c9..63757f08 100644
--- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpen_FileAccessReadWrite.cs
+++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpen_FileAccessReadWrite.cs
@@ -3,6 +3,7 @@ using System.IO;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
+using Renci.SshNet.Common;
using Renci.SshNet.Sftp;
namespace Renci.SshNet.Tests.Classes.Sftp
diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeTruncate_FileAccessReadWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeTruncate_FileAccessReadWrite.cs
index d7fafaf9..db3d9b99 100644
--- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeTruncate_FileAccessReadWrite.cs
+++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeTruncate_FileAccessReadWrite.cs
@@ -3,6 +3,7 @@ using System.IO;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
+using Renci.SshNet.Common;
using Renci.SshNet.Sftp;
namespace Renci.SshNet.Tests.Classes.Sftp
diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_ReadMode_DataInBuffer_NotReadFromBuffer.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_ReadMode_DataInBuffer_NotReadFromBuffer.cs
index f743eb6f..ee44c62f 100644
--- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_ReadMode_DataInBuffer_NotReadFromBuffer.cs
+++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_ReadMode_DataInBuffer_NotReadFromBuffer.cs
@@ -1,5 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
+using Renci.SshNet.Common;
using Renci.SshNet.Sftp;
using Renci.SshNet.Tests.Common;
using System;
diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_ReadMode_DataInBuffer_ReadFromBuffer.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_ReadMode_DataInBuffer_ReadFromBuffer.cs
index cd4c223f..f5b25be4 100644
--- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_ReadMode_DataInBuffer_ReadFromBuffer.cs
+++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_ReadMode_DataInBuffer_ReadFromBuffer.cs
@@ -1,5 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
+using Renci.SshNet.Common;
using Renci.SshNet.Sftp;
using Renci.SshNet.Tests.Common;
using System;
diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_ReadMode_NoDataInBuffer.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_ReadMode_NoDataInBuffer.cs
index 4e5dea47..41ba6f43 100644
--- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_ReadMode_NoDataInBuffer.cs
+++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_ReadMode_NoDataInBuffer.cs
@@ -1,5 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
+using Renci.SshNet.Common;
using Renci.SshNet.Sftp;
using Renci.SshNet.Tests.Common;
using System;
diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_WriteMode_DataInBuffer.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_WriteMode_DataInBuffer.cs
index 3c901133..8dbc7066 100644
--- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_WriteMode_DataInBuffer.cs
+++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_WriteMode_DataInBuffer.cs
@@ -1,5 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
+using Renci.SshNet.Common;
using Renci.SshNet.Sftp;
using Renci.SshNet.Sftp.Responses;
using Renci.SshNet.Tests.Common;
diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_WriteMode_NoDataInBuffer.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_WriteMode_NoDataInBuffer.cs
index 405261a6..32d0b833 100644
--- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_WriteMode_NoDataInBuffer.cs
+++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_WriteMode_NoDataInBuffer.cs
@@ -1,5 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
+using Renci.SshNet.Common;
using Renci.SshNet.Sftp;
using Renci.SshNet.Sftp.Responses;
using Renci.SshNet.Tests.Common;
diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Seek_PositionedAtMiddleOfStream_OriginBeginAndOffsetZero_ReadBuffer.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Seek_PositionedAtMiddleOfStream_OriginBeginAndOffsetZero_ReadBuffer.cs
index 624a9759..c5efd3ad 100644
--- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Seek_PositionedAtMiddleOfStream_OriginBeginAndOffsetZero_ReadBuffer.cs
+++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Seek_PositionedAtMiddleOfStream_OriginBeginAndOffsetZero_ReadBuffer.cs
@@ -2,6 +2,7 @@
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
+using Renci.SshNet.Common;
using Renci.SshNet.Sftp;
namespace Renci.SshNet.Tests.Classes.Sftp
diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_DataInReadBuffer_NewLengthGreatherThanPosition.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_DataInReadBuffer_NewLengthGreatherThanPosition.cs
index 3975fcf9..dd6cefa7 100644
--- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_DataInReadBuffer_NewLengthGreatherThanPosition.cs
+++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_DataInReadBuffer_NewLengthGreatherThanPosition.cs
@@ -3,10 +3,12 @@ using System.Globalization;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
+using Renci.SshNet.Common;
using Renci.SshNet.Sftp;
using Renci.SshNet.Tests.Common;
-using System.Threading;
using Renci.SshNet.Sftp.Responses;
+using System.Threading;
+
namespace Renci.SshNet.Tests.Classes.Sftp
{
diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_DataInWriteBuffer_NewLengthGreatherThanPosition.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_DataInWriteBuffer_NewLengthGreatherThanPosition.cs
index ed5bef9c..5a19aa3e 100644
--- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_DataInWriteBuffer_NewLengthGreatherThanPosition.cs
+++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_DataInWriteBuffer_NewLengthGreatherThanPosition.cs
@@ -7,6 +7,7 @@ using Renci.SshNet.Sftp;
using Renci.SshNet.Tests.Common;
using System.Threading;
using Renci.SshNet.Sftp.Responses;
+using Renci.SshNet.Common;
namespace Renci.SshNet.Tests.Classes.Sftp
{
diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Write_SessionOpen_CountGreatherThanTwoTimesTheWriteBufferSize.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Write_SessionOpen_CountGreatherThanTwoTimesTheWriteBufferSize.cs
index ce428849..68020d55 100644
--- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Write_SessionOpen_CountGreatherThanTwoTimesTheWriteBufferSize.cs
+++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Write_SessionOpen_CountGreatherThanTwoTimesTheWriteBufferSize.cs
@@ -4,6 +4,7 @@ using System.IO;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
+using Renci.SshNet.Common;
using Renci.SshNet.Sftp;
using Renci.SshNet.Sftp.Responses;
diff --git a/src/Renci.SshNet.Tests/Common/AsyncSocketListener.cs b/src/Renci.SshNet.Tests/Common/AsyncSocketListener.cs
index daf062a0..41c04806 100644
--- a/src/Renci.SshNet.Tests/Common/AsyncSocketListener.cs
+++ b/src/Renci.SshNet.Tests/Common/AsyncSocketListener.cs
@@ -2,6 +2,9 @@
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/CipherInfo.cs b/src/Renci.SshNet/CipherInfo.cs
index e68497cd..2641437b 100644
--- a/src/Renci.SshNet/CipherInfo.cs
+++ b/src/Renci.SshNet/CipherInfo.cs
@@ -1,4 +1,5 @@
using System;
+using Renci.SshNet.Common;
using Renci.SshNet.Security.Cryptography;
namespace Renci.SshNet
diff --git a/src/Renci.SshNet/Common/Extensions.cs b/src/Renci.SshNet/Common/Extensions.cs
index 21980f86..9d163bc9 100644
--- a/src/Renci.SshNet/Common/Extensions.cs
+++ b/src/Renci.SshNet/Common/Extensions.cs
@@ -5,163 +5,19 @@ using System.Globalization;
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.Common;
using Renci.SshNet.Messages;
-namespace Renci.SshNet
+namespace Renci.SshNet.Common
{
///
/// Collection of different extension method
///
internal static partial class Extensions
{
- private enum ShellQuoteState
- {
- Unquoted = 1,
- SingleQuoted = 2,
- Quoted = 3
- }
-
- ///
- /// Quotes a in a way to be suitable to be used with a shell.
- ///
- /// The to quote.
- ///
- /// A quoted .
- ///
- /// is null.
- ///
- ///
- /// If contains a single-quote, that character is embedded
- /// in quotation marks (eg. "'"). Sequences of single-quotes are grouped in a one
- /// pair of quotation marks.
- ///
- ///
- /// If the contains an exclamation mark (!), the C-Shell interprets
- /// it as a meta-character for history substitution. This even works inside single-quotes
- /// or quotation marks, unless escaped with a backslash (\).
- ///
- ///
- /// References:
- ///
- /// -
- /// Shell Command Language
- ///
- /// -
- /// Unix C-Shell special characters and their uses
- ///
- /// -
- /// Differences Between Bourne and C Shell Quoting
- ///
- ///
- ///
- ///
- public static string ShellQuote(this string value)
- {
- if (value == null)
- {
- throw new ArgumentNullException("value");
- }
-
- // result is at least value and leading/trailing single-quote
- var sb = new StringBuilder(value.Length + 2);
- var state = ShellQuoteState.Unquoted;
-
- foreach (var c in value)
- {
- switch (c)
- {
- case '\'':
- // embed a single-quote in quotes
- switch (state)
- {
- case ShellQuoteState.Unquoted:
- // Start quoted string
- sb.Append('"');
- break;
- case ShellQuoteState.Quoted:
- // Continue quoted string
- break;
- case ShellQuoteState.SingleQuoted:
- // Close single quoted string
- sb.Append('\'');
- // Start quoted string
- sb.Append('"');
- break;
- }
- state = ShellQuoteState.Quoted;
- break;
- case '!':
- // In C-Shell, an exclamatation point can only be protected from shell interpretation
- // when escaped by a backslash
- // Source:
- // https://earthsci.stanford.edu/computing/unix/shell/specialchars.php
-
- switch (state)
- {
- case ShellQuoteState.Unquoted:
- sb.Append('\\');
- break;
- case ShellQuoteState.Quoted:
- // Close quoted string
- sb.Append('"');
- sb.Append('\\');
- break;
- case ShellQuoteState.SingleQuoted:
- // Close single quoted string
- sb.Append('\'');
- sb.Append('\\');
- break;
- }
- state = ShellQuoteState.Unquoted;
- break;
- default:
- switch (state)
- {
- case ShellQuoteState.Unquoted:
- // Start single-quoted string
- sb.Append('\'');
- break;
- case ShellQuoteState.Quoted:
- // Close quoted string
- sb.Append('"');
- // Start single quoted string
- sb.Append('\'');
- break;
- case ShellQuoteState.SingleQuoted:
- // Continue single quoted string
- break;
- }
- state = ShellQuoteState.SingleQuoted;
- break;
- }
-
- sb.Append(c);
- }
-
- switch (state)
- {
- case ShellQuoteState.Unquoted:
- break;
- case ShellQuoteState.Quoted:
- // Close quoted string
- sb.Append('"');
- break;
- case ShellQuoteState.SingleQuoted:
- /* Close single quoted string */
- sb.Append('\'');
- break;
- }
-
- if (sb.Length == 0)
- {
- sb.Append("''");
- }
-
- return sb.ToString();
- }
-
///
/// Determines whether the specified value is null or white space.
///
@@ -421,5 +277,35 @@ namespace Renci.SshNet
return false;
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.
+ ///
+ /// 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/ForwardedPortLocal.cs b/src/Renci.SshNet/ForwardedPortLocal.cs
index 3f2f51bc..79246bd7 100644
--- a/src/Renci.SshNet/ForwardedPortLocal.cs
+++ b/src/Renci.SshNet/ForwardedPortLocal.cs
@@ -1,4 +1,5 @@
using System;
+using Renci.SshNet.Common;
namespace Renci.SshNet
{
diff --git a/src/Renci.SshNet/HashInfo.cs b/src/Renci.SshNet/HashInfo.cs
index 5e489abc..156c8456 100644
--- a/src/Renci.SshNet/HashInfo.cs
+++ b/src/Renci.SshNet/HashInfo.cs
@@ -1,5 +1,6 @@
using System;
using System.Security.Cryptography;
+using Renci.SshNet.Common;
namespace Renci.SshNet
{
diff --git a/src/Renci.SshNet/KeyboardInteractiveConnectionInfo.cs b/src/Renci.SshNet/KeyboardInteractiveConnectionInfo.cs
index fa14fc4a..d8780caa 100644
--- a/src/Renci.SshNet/KeyboardInteractiveConnectionInfo.cs
+++ b/src/Renci.SshNet/KeyboardInteractiveConnectionInfo.cs
@@ -1,5 +1,4 @@
using System;
-using System.Linq;
using Renci.SshNet.Common;
namespace Renci.SshNet
@@ -130,9 +129,13 @@ namespace Renci.SshNet
public KeyboardInteractiveConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword)
: base(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, new KeyboardInteractiveAuthenticationMethod(username))
{
- foreach (var authenticationMethod in AuthenticationMethods.OfType())
+ foreach (var authenticationMethod in AuthenticationMethods)
{
- authenticationMethod.AuthenticationPrompt += AuthenticationMethod_AuthenticationPrompt;
+ var kbdInteractive = authenticationMethod as KeyboardInteractiveAuthenticationMethod;
+ if (kbdInteractive != null)
+ {
+ kbdInteractive.AuthenticationPrompt += AuthenticationMethod_AuthenticationPrompt;
+ }
}
}
@@ -172,9 +175,13 @@ namespace Renci.SshNet
{
if (AuthenticationMethods != null)
{
- foreach (var authenticationMethods in AuthenticationMethods.OfType())
+ foreach (var authenticationMethods in AuthenticationMethods)
{
- authenticationMethods.Dispose();
+ var disposable = authenticationMethods as IDisposable;
+ if (disposable != null)
+ {
+ disposable.Dispose();
+ }
}
}
diff --git a/src/Renci.SshNet/Messages/Authentication/RequestMessage.cs b/src/Renci.SshNet/Messages/Authentication/RequestMessage.cs
index 9df33293..b535da22 100644
--- a/src/Renci.SshNet/Messages/Authentication/RequestMessage.cs
+++ b/src/Renci.SshNet/Messages/Authentication/RequestMessage.cs
@@ -1,4 +1,5 @@
using System;
+using Renci.SshNet.Common;
namespace Renci.SshNet.Messages.Authentication
{
diff --git a/src/Renci.SshNet/Messages/Transport/ServiceAcceptMessage.cs b/src/Renci.SshNet/Messages/Transport/ServiceAcceptMessage.cs
index ad2ebca4..a7c2a8c6 100644
--- a/src/Renci.SshNet/Messages/Transport/ServiceAcceptMessage.cs
+++ b/src/Renci.SshNet/Messages/Transport/ServiceAcceptMessage.cs
@@ -1,4 +1,5 @@
using System;
+using Renci.SshNet.Common;
namespace Renci.SshNet.Messages.Transport
{
diff --git a/src/Renci.SshNet/Messages/Transport/ServiceRequestMessage.cs b/src/Renci.SshNet/Messages/Transport/ServiceRequestMessage.cs
index 313c9d3a..c41a4f90 100644
--- a/src/Renci.SshNet/Messages/Transport/ServiceRequestMessage.cs
+++ b/src/Renci.SshNet/Messages/Transport/ServiceRequestMessage.cs
@@ -1,4 +1,5 @@
using System;
+using Renci.SshNet.Common;
namespace Renci.SshNet.Messages.Transport
{
diff --git a/src/Renci.SshNet/NoneAuthenticationMethod.cs b/src/Renci.SshNet/NoneAuthenticationMethod.cs
index 93586ade..a5d842fd 100644
--- a/src/Renci.SshNet/NoneAuthenticationMethod.cs
+++ b/src/Renci.SshNet/NoneAuthenticationMethod.cs
@@ -1,5 +1,8 @@
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/Security/Cryptography/Ciphers/CipherMode.cs b/src/Renci.SshNet/Security/Cryptography/Ciphers/CipherMode.cs
index 04eb2628..7352a12f 100644
--- a/src/Renci.SshNet/Security/Cryptography/Ciphers/CipherMode.cs
+++ b/src/Renci.SshNet/Security/Cryptography/Ciphers/CipherMode.cs
@@ -1,4 +1,6 @@
-namespace Renci.SshNet.Security.Cryptography.Ciphers
+using Renci.SshNet.Common;
+
+namespace Renci.SshNet.Security.Cryptography.Ciphers
{
///
/// Base class for cipher mode implementations
diff --git a/src/Renci.SshNet/Security/Cryptography/HMACMD5.cs b/src/Renci.SshNet/Security/Cryptography/HMACMD5.cs
index dd9a9859..86b24643 100644
--- a/src/Renci.SshNet/Security/Cryptography/HMACMD5.cs
+++ b/src/Renci.SshNet/Security/Cryptography/HMACMD5.cs
@@ -1,6 +1,7 @@
#if FEATURE_HMAC_MD5
using System.Security.Cryptography;
+using Renci.SshNet.Common;
namespace Renci.SshNet.Security.Cryptography
{
diff --git a/src/Renci.SshNet/Security/Cryptography/HMACSHA1.cs b/src/Renci.SshNet/Security/Cryptography/HMACSHA1.cs
index 3f53d3b8..d8f47af1 100644
--- a/src/Renci.SshNet/Security/Cryptography/HMACSHA1.cs
+++ b/src/Renci.SshNet/Security/Cryptography/HMACSHA1.cs
@@ -1,6 +1,7 @@
#if FEATURE_HMAC_SHA1
using System.Security.Cryptography;
+using Renci.SshNet.Common;
namespace Renci.SshNet.Security.Cryptography
{
diff --git a/src/Renci.SshNet/Security/Cryptography/HMACSHA256.cs b/src/Renci.SshNet/Security/Cryptography/HMACSHA256.cs
index f3d88e11..cb1c3185 100644
--- a/src/Renci.SshNet/Security/Cryptography/HMACSHA256.cs
+++ b/src/Renci.SshNet/Security/Cryptography/HMACSHA256.cs
@@ -1,6 +1,7 @@
#if FEATURE_HMAC_SHA256
using System.Security.Cryptography;
+using Renci.SshNet.Common;
namespace Renci.SshNet.Security.Cryptography
{
diff --git a/src/Renci.SshNet/Security/Cryptography/HMACSHA384.cs b/src/Renci.SshNet/Security/Cryptography/HMACSHA384.cs
index 8e377e63..142e51ed 100644
--- a/src/Renci.SshNet/Security/Cryptography/HMACSHA384.cs
+++ b/src/Renci.SshNet/Security/Cryptography/HMACSHA384.cs
@@ -1,6 +1,7 @@
#if FEATURE_HMAC_SHA384
using System.Security.Cryptography;
+using Renci.SshNet.Common;
namespace Renci.SshNet.Security.Cryptography
{
diff --git a/src/Renci.SshNet/Security/Cryptography/HMACSHA512.cs b/src/Renci.SshNet/Security/Cryptography/HMACSHA512.cs
index 9c733832..a297ed08 100644
--- a/src/Renci.SshNet/Security/Cryptography/HMACSHA512.cs
+++ b/src/Renci.SshNet/Security/Cryptography/HMACSHA512.cs
@@ -1,6 +1,7 @@
#if FEATURE_HMAC_SHA512
using System.Security.Cryptography;
+using Renci.SshNet.Common;
namespace Renci.SshNet.Security.Cryptography
{