浏览代码

Move Extensions to Renci.SshNet.Common namespace.
Moved Dispose(this Socket socket) and Dispose(this WaitHandle handle) to Extensions.cs.

Gert Driesen 8 年之前
父节点
当前提交
0e083cfe60
共有 48 个文件被更改,包括 110 次插入193 次删除
  1. 1 29
      src/Renci.SshNet.NET35/Common/Extensions.NET35.cs
  2. 3 0
      src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs
  3. 7 7
      src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_IsEqualTo_ByteArray.cs
  4. 1 0
      src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_Reverse.cs
  5. 1 0
      src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_Take_Count.cs
  6. 1 0
      src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_Take_OffsetAndCount.cs
  7. 1 0
      src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_TrimLeadingZeros.cs
  8. 1 0
      src/Renci.SshNet.Tests/Classes/ScpClientTest.cs
  9. 0 1
      src/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_SendExecRequestReturnsFalse.cs
  10. 1 0
      src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/AesCipherTest.cs
  11. 1 0
      src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Arc4CipherTest.cs
  12. 1 0
      src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/DesCipherTest.cs
  13. 1 0
      src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS5PaddingTest.cs
  14. 1 0
      src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS7PaddingTest.cs
  15. 4 1
      src/Renci.SshNet.Tests/Classes/Sftp/SftpFileReaderTest_DisposeShouldUnblockReadAndReadAhead.cs
  16. 1 0
      src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreateNew_FileAccessReadWrite.cs
  17. 1 0
      src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreate_FileAccessReadWrite_FileDoesNotExist.cs
  18. 1 0
      src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreate_FileAccessReadWrite_FileExists.cs
  19. 1 0
      src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpenOrCreate_FileAccessRead.cs
  20. 1 0
      src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpenOrCreate_FileAccessReadWrite.cs
  21. 1 0
      src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpen_FileAccessRead.cs
  22. 1 0
      src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpen_FileAccessReadWrite.cs
  23. 1 0
      src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeTruncate_FileAccessReadWrite.cs
  24. 1 0
      src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_ReadMode_DataInBuffer_NotReadFromBuffer.cs
  25. 1 0
      src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_ReadMode_DataInBuffer_ReadFromBuffer.cs
  26. 1 0
      src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_ReadMode_NoDataInBuffer.cs
  27. 1 0
      src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_WriteMode_DataInBuffer.cs
  28. 1 0
      src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_WriteMode_NoDataInBuffer.cs
  29. 1 0
      src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Seek_PositionedAtMiddleOfStream_OriginBeginAndOffsetZero_ReadBuffer.cs
  30. 3 1
      src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_DataInReadBuffer_NewLengthGreatherThanPosition.cs
  31. 1 0
      src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_DataInWriteBuffer_NewLengthGreatherThanPosition.cs
  32. 1 0
      src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Write_SessionOpen_CountGreatherThanTwoTimesTheWriteBufferSize.cs
  33. 3 0
      src/Renci.SshNet.Tests/Common/AsyncSocketListener.cs
  34. 1 0
      src/Renci.SshNet/CipherInfo.cs
  35. 34 148
      src/Renci.SshNet/Common/Extensions.cs
  36. 1 0
      src/Renci.SshNet/ForwardedPortLocal.cs
  37. 1 0
      src/Renci.SshNet/HashInfo.cs
  38. 12 5
      src/Renci.SshNet/KeyboardInteractiveConnectionInfo.cs
  39. 1 0
      src/Renci.SshNet/Messages/Authentication/RequestMessage.cs
  40. 1 0
      src/Renci.SshNet/Messages/Transport/ServiceAcceptMessage.cs
  41. 1 0
      src/Renci.SshNet/Messages/Transport/ServiceRequestMessage.cs
  42. 3 0
      src/Renci.SshNet/NoneAuthenticationMethod.cs
  43. 3 1
      src/Renci.SshNet/Security/Cryptography/Ciphers/CipherMode.cs
  44. 1 0
      src/Renci.SshNet/Security/Cryptography/HMACMD5.cs
  45. 1 0
      src/Renci.SshNet/Security/Cryptography/HMACSHA1.cs
  46. 1 0
      src/Renci.SshNet/Security/Cryptography/HMACSHA256.cs
  47. 1 0
      src/Renci.SshNet/Security/Cryptography/HMACSHA384.cs
  48. 1 0
      src/Renci.SshNet/Security/Cryptography/HMACSHA512.cs

+ 1 - 29
src/Renci.SshNet.NET35/Common/Extensions.NET35.cs

@@ -1,43 +1,15 @@
 using System;
 using System;
 using System.Diagnostics;
 using System.Diagnostics;
-using System.Net.Sockets;
 using System.Security.Cryptography;
 using System.Security.Cryptography;
 using System.Text;
 using System.Text;
-using System.Threading;
 
 
-namespace Renci.SshNet
+namespace Renci.SshNet.Common
 {
 {
     /// <summary>
     /// <summary>
     /// Collection of different extension method specific for .NET 3.5
     /// Collection of different extension method specific for .NET 3.5
     /// </summary>
     /// </summary>
     internal static partial class Extensions
     internal static partial class Extensions
     {
     {
-        /// <summary>
-        /// Disposes the specified socket.
-        /// </summary>
-        /// <param name="socket">The socket.</param>
-        [DebuggerNonUserCode]
-        internal static void Dispose(this Socket socket)
-        {
-            if (socket == null)
-                throw new NullReferenceException();
-
-            socket.Close();
-        }
-
-        /// <summary>
-        /// Disposes the specified handle.
-        /// </summary>
-        /// <param name="handle">The handle.</param>
-        [DebuggerNonUserCode]
-        internal static void Dispose(this WaitHandle handle)
-        {
-            if (handle == null)
-                throw new NullReferenceException();
-
-            handle.Close();
-        }
-
         /// <summary>
         /// <summary>
         /// Disposes the specified algorithm.
         /// Disposes the specified algorithm.
         /// </summary>
         /// </summary>

+ 3 - 0
src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs

@@ -5,6 +5,9 @@ using System.Net.Sockets;
 using System.Threading;
 using System.Threading;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Moq;
 using Moq;
+#if !FEATURE_SOCKET_DISPOSE
+using Renci.SshNet.Common;
+#endif // !FEATURE_SOCKET_DISPOSE
 using Renci.SshNet.Channels;
 using Renci.SshNet.Channels;
 using Renci.SshNet.Messages.Connection;
 using Renci.SshNet.Messages.Connection;
 using Renci.SshNet.Tests.Common;
 using Renci.SshNet.Tests.Common;

+ 7 - 7
src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_IsEqualTo_ByteArray.cs

@@ -1,8 +1,8 @@
 using System;
 using System;
 using System.Diagnostics;
 using System.Diagnostics;
 using System.Diagnostics.CodeAnalysis;
 using System.Diagnostics.CodeAnalysis;
-using System.Linq;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Renci.SshNet.Common;
 
 
 namespace Renci.SshNet.Tests.Classes.Common
 namespace Renci.SshNet.Tests.Classes.Common
 {
 {
@@ -76,7 +76,7 @@ namespace Renci.SshNet.Tests.Classes.Common
         public void ShouldReturnFalseWhenLeftIsNotEqualToRight()
         public void ShouldReturnFalseWhenLeftIsNotEqualToRight()
         {
         {
             Assert.IsFalse(Extensions.IsEqualTo(new byte[] {0x0a}, new byte[] {0x0a, 0x0d}));
             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[0], new byte[] { 0x0a }));
             Assert.IsFalse(Extensions.IsEqualTo(new byte[] { 0x0a, 0x0d }, new byte[0]));
             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 buffer = CreateBuffer(50000);
             var left = buffer.Concat(new byte[] {0x0a});
             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;
             const int runs = 10000;
 
 
             Performance(left, right, runs);
             Performance(left, right, runs);
@@ -126,8 +126,8 @@ namespace Renci.SshNet.Tests.Classes.Common
         public void Performance_LargeArray_NotEqual_SameLength()
         public void Performance_LargeArray_NotEqual_SameLength()
         {
         {
             var buffer = CreateBuffer(50000);
             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;
             const int runs = 10000;
 
 
             Performance(left, right, runs);
             Performance(left, right, runs);
@@ -139,7 +139,7 @@ namespace Renci.SshNet.Tests.Classes.Common
         public void Performance_LargeArray_Same()
         public void Performance_LargeArray_Same()
         {
         {
             var left = CreateBuffer(50000);
             var left = CreateBuffer(50000);
-            var right = left.Concat(new byte[] { 0x0a });
+            var right = left.Concat(new byte[] {0x0a});
             const int runs = 10000;
             const int runs = 10000;
 
 
             Performance(left, right, runs);
             Performance(left, right, runs);
@@ -173,7 +173,7 @@ namespace Renci.SshNet.Tests.Classes.Common
 
 
             for (var i = 0; i < runs; i++)
             for (var i = 0; i < runs; i++)
             {
             {
-                var result = Enumerable.SequenceEqual(left, right);
+                var result = System.Linq.Enumerable.SequenceEqual(left, right);
             }
             }
 
 
             GC.Collect();
             GC.Collect();

+ 1 - 0
src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_Reverse.cs

@@ -2,6 +2,7 @@
 using System.Diagnostics;
 using System.Diagnostics;
 using System.Diagnostics.CodeAnalysis;
 using System.Diagnostics.CodeAnalysis;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Renci.SshNet.Common;
 
 
 namespace Renci.SshNet.Tests.Classes.Common
 namespace Renci.SshNet.Tests.Classes.Common
 {
 {

+ 1 - 0
src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_Take_Count.cs

@@ -3,6 +3,7 @@ using System.Diagnostics;
 using System.Diagnostics.CodeAnalysis;
 using System.Diagnostics.CodeAnalysis;
 using System.Linq;
 using System.Linq;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Renci.SshNet.Common;
 
 
 namespace Renci.SshNet.Tests.Classes.Common
 namespace Renci.SshNet.Tests.Classes.Common
 {
 {

+ 1 - 0
src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_Take_OffsetAndCount.cs

@@ -1,6 +1,7 @@
 using System;
 using System;
 using System.Diagnostics.CodeAnalysis;
 using System.Diagnostics.CodeAnalysis;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Renci.SshNet.Common;
 
 
 namespace Renci.SshNet.Tests.Classes.Common
 namespace Renci.SshNet.Tests.Classes.Common
 {
 {

+ 1 - 0
src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_TrimLeadingZeros.cs

@@ -1,6 +1,7 @@
 using System;
 using System;
 using System.Diagnostics.CodeAnalysis;
 using System.Diagnostics.CodeAnalysis;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Renci.SshNet.Common;
 
 
 namespace Renci.SshNet.Tests.Classes.Common
 namespace Renci.SshNet.Tests.Classes.Common
 {
 {

+ 1 - 0
src/Renci.SshNet.Tests/Classes/ScpClientTest.cs

@@ -1,4 +1,5 @@
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Renci.SshNet.Common;
 using Renci.SshNet.Tests.Common;
 using Renci.SshNet.Tests.Common;
 using Renci.SshNet.Tests.Properties;
 using Renci.SshNet.Tests.Properties;
 using System;
 using System;

+ 0 - 1
src/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_SendExecRequestReturnsFalse.cs

@@ -1,6 +1,5 @@
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
-using System.Globalization;
 using System.IO;
 using System.IO;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Moq;
 using Moq;

+ 1 - 0
src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/AesCipherTest.cs

@@ -1,4 +1,5 @@
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Renci.SshNet.Common;
 using Renci.SshNet.Security.Cryptography.Ciphers;
 using Renci.SshNet.Security.Cryptography.Ciphers;
 using Renci.SshNet.Security.Cryptography.Ciphers.Modes;
 using Renci.SshNet.Security.Cryptography.Ciphers.Modes;
 using Renci.SshNet.Tests.Common;
 using Renci.SshNet.Tests.Common;

+ 1 - 0
src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Arc4CipherTest.cs

@@ -1,5 +1,6 @@
 using System.Text;
 using System.Text;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Renci.SshNet.Common;
 using Renci.SshNet.Security.Cryptography.Ciphers;
 using Renci.SshNet.Security.Cryptography.Ciphers;
 using Renci.SshNet.Tests.Common;
 using Renci.SshNet.Tests.Common;
 using Renci.SshNet.Tests.Properties;
 using Renci.SshNet.Tests.Properties;

+ 1 - 0
src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/DesCipherTest.cs

@@ -1,5 +1,6 @@
 using System.Text;
 using System.Text;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Renci.SshNet.Common;
 using Renci.SshNet.Security.Cryptography.Ciphers;
 using Renci.SshNet.Security.Cryptography.Ciphers;
 using Renci.SshNet.Security.Cryptography.Ciphers.Modes;
 using Renci.SshNet.Security.Cryptography.Ciphers.Modes;
 using Renci.SshNet.Security.Cryptography.Ciphers.Paddings;
 using Renci.SshNet.Security.Cryptography.Ciphers.Paddings;

+ 1 - 0
src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS5PaddingTest.cs

@@ -1,4 +1,5 @@
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Renci.SshNet.Common;
 using Renci.SshNet.Security.Cryptography.Ciphers.Paddings;
 using Renci.SshNet.Security.Cryptography.Ciphers.Paddings;
 
 
 namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Paddings
 namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Paddings

+ 1 - 0
src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS7PaddingTest.cs

@@ -1,4 +1,5 @@
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Renci.SshNet.Common;
 using Renci.SshNet.Security.Cryptography.Ciphers.Paddings;
 using Renci.SshNet.Security.Cryptography.Ciphers.Paddings;
 
 
 namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Paddings
 namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Paddings

+ 4 - 1
src/Renci.SshNet.Tests/Classes/Sftp/SftpFileReaderTest_DisposeShouldUnblockReadAndReadAhead.cs

@@ -1,5 +1,8 @@
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Moq;
 using Moq;
+#if !FEATURE_EVENTWAITHANDLE_DISPOSE
+using Renci.SshNet.Common;
+#endif // !FEATURE_EVENTWAITHANDLE_DISPOSE
 using Renci.SshNet.Abstractions;
 using Renci.SshNet.Abstractions;
 using Renci.SshNet.Sftp;
 using Renci.SshNet.Sftp;
 using System;
 using System;
@@ -22,7 +25,7 @@ namespace Renci.SshNet.Tests.Classes.Sftp
         private SftpCloseAsyncResult _closeAsyncResult;
         private SftpCloseAsyncResult _closeAsyncResult;
         private SftpFileReader _reader;
         private SftpFileReader _reader;
         private ObjectDisposedException _actualException;
         private ObjectDisposedException _actualException;
-        private ManualResetEvent _disposeCompleted;
+        private EventWaitHandle _disposeCompleted;
 
 
         [TestCleanup]
         [TestCleanup]
         public void TearDown()
         public void TearDown()

+ 1 - 0
src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreateNew_FileAccessReadWrite.cs

@@ -3,6 +3,7 @@ using System.IO;
 using System.Threading;
 using System.Threading;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Moq;
 using Moq;
+using Renci.SshNet.Common;
 using Renci.SshNet.Sftp;
 using Renci.SshNet.Sftp;
 
 
 namespace Renci.SshNet.Tests.Classes.Sftp
 namespace Renci.SshNet.Tests.Classes.Sftp

+ 1 - 0
src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreate_FileAccessReadWrite_FileDoesNotExist.cs

@@ -3,6 +3,7 @@ using System.IO;
 using System.Threading;
 using System.Threading;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Moq;
 using Moq;
+using Renci.SshNet.Common;
 using Renci.SshNet.Sftp;
 using Renci.SshNet.Sftp;
 
 
 namespace Renci.SshNet.Tests.Classes.Sftp
 namespace Renci.SshNet.Tests.Classes.Sftp

+ 1 - 0
src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreate_FileAccessReadWrite_FileExists.cs

@@ -3,6 +3,7 @@ using System.IO;
 using System.Threading;
 using System.Threading;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Moq;
 using Moq;
+using Renci.SshNet.Common;
 using Renci.SshNet.Sftp;
 using Renci.SshNet.Sftp;
 
 
 namespace Renci.SshNet.Tests.Classes.Sftp
 namespace Renci.SshNet.Tests.Classes.Sftp

+ 1 - 0
src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpenOrCreate_FileAccessRead.cs

@@ -2,6 +2,7 @@
 using System.IO;
 using System.IO;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Moq;
 using Moq;
+using Renci.SshNet.Common;
 using Renci.SshNet.Sftp;
 using Renci.SshNet.Sftp;
 
 
 namespace Renci.SshNet.Tests.Classes.Sftp
 namespace Renci.SshNet.Tests.Classes.Sftp

+ 1 - 0
src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpenOrCreate_FileAccessReadWrite.cs

@@ -3,6 +3,7 @@ using System.IO;
 using System.Threading;
 using System.Threading;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Moq;
 using Moq;
+using Renci.SshNet.Common;
 using Renci.SshNet.Sftp;
 using Renci.SshNet.Sftp;
 
 
 namespace Renci.SshNet.Tests.Classes.Sftp
 namespace Renci.SshNet.Tests.Classes.Sftp

+ 1 - 0
src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpen_FileAccessRead.cs

@@ -2,6 +2,7 @@
 using System.IO;
 using System.IO;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Moq;
 using Moq;
+using Renci.SshNet.Common;
 using Renci.SshNet.Sftp;
 using Renci.SshNet.Sftp;
 
 
 namespace Renci.SshNet.Tests.Classes.Sftp
 namespace Renci.SshNet.Tests.Classes.Sftp

+ 1 - 0
src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpen_FileAccessReadWrite.cs

@@ -3,6 +3,7 @@ using System.IO;
 using System.Threading;
 using System.Threading;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Moq;
 using Moq;
+using Renci.SshNet.Common;
 using Renci.SshNet.Sftp;
 using Renci.SshNet.Sftp;
 
 
 namespace Renci.SshNet.Tests.Classes.Sftp
 namespace Renci.SshNet.Tests.Classes.Sftp

+ 1 - 0
src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeTruncate_FileAccessReadWrite.cs

@@ -3,6 +3,7 @@ using System.IO;
 using System.Threading;
 using System.Threading;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Moq;
 using Moq;
+using Renci.SshNet.Common;
 using Renci.SshNet.Sftp;
 using Renci.SshNet.Sftp;
 
 
 namespace Renci.SshNet.Tests.Classes.Sftp
 namespace Renci.SshNet.Tests.Classes.Sftp

+ 1 - 0
src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_ReadMode_DataInBuffer_NotReadFromBuffer.cs

@@ -1,5 +1,6 @@
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Moq;
 using Moq;
+using Renci.SshNet.Common;
 using Renci.SshNet.Sftp;
 using Renci.SshNet.Sftp;
 using Renci.SshNet.Tests.Common;
 using Renci.SshNet.Tests.Common;
 using System;
 using System;

+ 1 - 0
src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_ReadMode_DataInBuffer_ReadFromBuffer.cs

@@ -1,5 +1,6 @@
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Moq;
 using Moq;
+using Renci.SshNet.Common;
 using Renci.SshNet.Sftp;
 using Renci.SshNet.Sftp;
 using Renci.SshNet.Tests.Common;
 using Renci.SshNet.Tests.Common;
 using System;
 using System;

+ 1 - 0
src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_ReadMode_NoDataInBuffer.cs

@@ -1,5 +1,6 @@
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Moq;
 using Moq;
+using Renci.SshNet.Common;
 using Renci.SshNet.Sftp;
 using Renci.SshNet.Sftp;
 using Renci.SshNet.Tests.Common;
 using Renci.SshNet.Tests.Common;
 using System;
 using System;

+ 1 - 0
src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_WriteMode_DataInBuffer.cs

@@ -1,5 +1,6 @@
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Moq;
 using Moq;
+using Renci.SshNet.Common;
 using Renci.SshNet.Sftp;
 using Renci.SshNet.Sftp;
 using Renci.SshNet.Sftp.Responses;
 using Renci.SshNet.Sftp.Responses;
 using Renci.SshNet.Tests.Common;
 using Renci.SshNet.Tests.Common;

+ 1 - 0
src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_WriteMode_NoDataInBuffer.cs

@@ -1,5 +1,6 @@
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Moq;
 using Moq;
+using Renci.SshNet.Common;
 using Renci.SshNet.Sftp;
 using Renci.SshNet.Sftp;
 using Renci.SshNet.Sftp.Responses;
 using Renci.SshNet.Sftp.Responses;
 using Renci.SshNet.Tests.Common;
 using Renci.SshNet.Tests.Common;

+ 1 - 0
src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Seek_PositionedAtMiddleOfStream_OriginBeginAndOffsetZero_ReadBuffer.cs

@@ -2,6 +2,7 @@
 using System.IO;
 using System.IO;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Moq;
 using Moq;
+using Renci.SshNet.Common;
 using Renci.SshNet.Sftp;
 using Renci.SshNet.Sftp;
 
 
 namespace Renci.SshNet.Tests.Classes.Sftp
 namespace Renci.SshNet.Tests.Classes.Sftp

+ 3 - 1
src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_DataInReadBuffer_NewLengthGreatherThanPosition.cs

@@ -3,10 +3,12 @@ using System.Globalization;
 using System.IO;
 using System.IO;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Moq;
 using Moq;
+using Renci.SshNet.Common;
 using Renci.SshNet.Sftp;
 using Renci.SshNet.Sftp;
 using Renci.SshNet.Tests.Common;
 using Renci.SshNet.Tests.Common;
-using System.Threading;
 using Renci.SshNet.Sftp.Responses;
 using Renci.SshNet.Sftp.Responses;
+using System.Threading;
+
 
 
 namespace Renci.SshNet.Tests.Classes.Sftp
 namespace Renci.SshNet.Tests.Classes.Sftp
 {
 {

+ 1 - 0
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 Renci.SshNet.Tests.Common;
 using System.Threading;
 using System.Threading;
 using Renci.SshNet.Sftp.Responses;
 using Renci.SshNet.Sftp.Responses;
+using Renci.SshNet.Common;
 
 
 namespace Renci.SshNet.Tests.Classes.Sftp
 namespace Renci.SshNet.Tests.Classes.Sftp
 {
 {

+ 1 - 0
src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Write_SessionOpen_CountGreatherThanTwoTimesTheWriteBufferSize.cs

@@ -4,6 +4,7 @@ using System.IO;
 using System.Threading;
 using System.Threading;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Moq;
 using Moq;
+using Renci.SshNet.Common;
 using Renci.SshNet.Sftp;
 using Renci.SshNet.Sftp;
 using Renci.SshNet.Sftp.Responses;
 using Renci.SshNet.Sftp.Responses;
 
 

+ 3 - 0
src/Renci.SshNet.Tests/Common/AsyncSocketListener.cs

@@ -2,6 +2,9 @@
 using System.Net;
 using System.Net;
 using System.Net.Sockets;
 using System.Net.Sockets;
 using System.Threading;
 using System.Threading;
+#if !FEATURE_SOCKET_DISPOSE
+using Renci.SshNet.Common;
+#endif // !FEATURE_SOCKET_DISPOSE
 
 
 namespace Renci.SshNet.Tests.Common
 namespace Renci.SshNet.Tests.Common
 {
 {

+ 1 - 0
src/Renci.SshNet/CipherInfo.cs

@@ -1,4 +1,5 @@
 using System;
 using System;
+using Renci.SshNet.Common;
 using Renci.SshNet.Security.Cryptography;
 using Renci.SshNet.Security.Cryptography;
 
 
 namespace Renci.SshNet
 namespace Renci.SshNet

+ 34 - 148
src/Renci.SshNet/Common/Extensions.cs

@@ -5,163 +5,19 @@ using System.Globalization;
 using System.Net;
 using System.Net;
 using System.Net.Sockets;
 using System.Net.Sockets;
 using System.Text;
 using System.Text;
+#if !FEATURE_WAITHANDLE_DISPOSE
+using System.Threading;
+#endif // !FEATURE_WAITHANDLE_DISPOSE
 using Renci.SshNet.Abstractions;
 using Renci.SshNet.Abstractions;
-using Renci.SshNet.Common;
 using Renci.SshNet.Messages;
 using Renci.SshNet.Messages;
 
 
-namespace Renci.SshNet
+namespace Renci.SshNet.Common
 {
 {
     /// <summary>
     /// <summary>
     /// Collection of different extension method
     /// Collection of different extension method
     /// </summary>
     /// </summary>
     internal static partial class Extensions
     internal static partial class Extensions
     {
     {
-        private enum ShellQuoteState
-        {
-            Unquoted = 1,
-            SingleQuoted = 2,
-            Quoted = 3
-        }
-
-        /// <summary>
-        /// Quotes a <see cref="string"/> in a way to be suitable to be used with a shell.
-        /// </summary>
-        /// <param name="value">The <see cref="string"/> to quote.</param>
-        /// <returns>
-        /// A quoted <see cref="string"/>.
-        /// </returns>
-        /// <exception cref="ArgumentNullException"><paramref name="value"/> is <c>null</c>.</exception>
-        /// <remarks>
-        /// <para>
-        /// If <paramref name="value"/> 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.
-        /// </para>
-        /// <para>
-        /// If the <see cref="string"/> 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 (\).
-        /// </para>
-        /// <para>
-        /// References:
-        /// <list type="bullet">
-        ///   <item>
-        ///     <description><a href="http://pubs.opengroup.org/onlinepubs/7908799/xcu/chap2.html">Shell Command Language</a></description>
-        ///   </item>
-        ///   <item>
-        ///     <description><a href="https://earthsci.stanford.edu/computing/unix/shell/specialchars.php">Unix C-Shell special characters and their uses</a></description>
-        ///   </item>
-        ///   <item>
-        ///     <description><a href="https://docstore.mik.ua/orelly/unix3/upt/ch27_13.htm">Differences Between Bourne and C Shell Quoting</a></description>
-        ///   </item>
-        /// </list>
-        /// </para>
-        /// </remarks>
-        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();
-        }
-
         /// <summary>
         /// <summary>
         /// Determines whether the specified value is null or white space.
         /// Determines whether the specified value is null or white space.
         /// </summary>
         /// </summary>
@@ -421,5 +277,35 @@ namespace Renci.SshNet
                 return false;
                 return false;
             return socket.Connected;
             return socket.Connected;
         }
         }
+
+#if !FEATURE_SOCKET_DISPOSE
+        /// <summary>
+        /// Disposes the specified socket.
+        /// </summary>
+        /// <param name="socket">The socket.</param>
+        [DebuggerNonUserCode]
+        internal static void Dispose(this Socket socket)
+        {
+            if (socket == null)
+                throw new NullReferenceException();
+
+            socket.Close();
+        }
+#endif // !FEATURE_SOCKET_DISPOSE
+
+#if !FEATURE_WAITHANDLE_DISPOSE
+        /// <summary>
+        /// Disposes the specified handle.
+        /// </summary>
+        /// <param name="handle">The handle.</param>
+        [DebuggerNonUserCode]
+        internal static void Dispose(this WaitHandle handle)
+        {
+            if (handle == null)
+                throw new NullReferenceException();
+
+            handle.Close();
+        }
+#endif // !FEATURE_WAITHANDLE_DISPOSE
     }
     }
 }
 }

+ 1 - 0
src/Renci.SshNet/ForwardedPortLocal.cs

@@ -1,4 +1,5 @@
 using System;
 using System;
+using Renci.SshNet.Common;
 
 
 namespace Renci.SshNet
 namespace Renci.SshNet
 {
 {

+ 1 - 0
src/Renci.SshNet/HashInfo.cs

@@ -1,5 +1,6 @@
 using System;
 using System;
 using System.Security.Cryptography;
 using System.Security.Cryptography;
+using Renci.SshNet.Common;
 
 
 namespace Renci.SshNet
 namespace Renci.SshNet
 {
 {

+ 12 - 5
src/Renci.SshNet/KeyboardInteractiveConnectionInfo.cs

@@ -1,5 +1,4 @@
 using System;
 using System;
-using System.Linq;
 using Renci.SshNet.Common;
 using Renci.SshNet.Common;
 
 
 namespace Renci.SshNet
 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)
         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))
             : base(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, new KeyboardInteractiveAuthenticationMethod(username))
         {
         {
-            foreach (var authenticationMethod in AuthenticationMethods.OfType<KeyboardInteractiveAuthenticationMethod>())
+            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)
                 if (AuthenticationMethods != null)
                 {
                 {
-                    foreach (var authenticationMethods in AuthenticationMethods.OfType<IDisposable>())
+                    foreach (var authenticationMethods in AuthenticationMethods)
                     {
                     {
-                        authenticationMethods.Dispose();
+                        var disposable = authenticationMethods as IDisposable;
+                        if (disposable != null)
+                        {
+                            disposable.Dispose();
+                        }
                     }
                     }
                 }
                 }
 
 

+ 1 - 0
src/Renci.SshNet/Messages/Authentication/RequestMessage.cs

@@ -1,4 +1,5 @@
 using System;
 using System;
+using Renci.SshNet.Common;
 
 
 namespace Renci.SshNet.Messages.Authentication
 namespace Renci.SshNet.Messages.Authentication
 {
 {

+ 1 - 0
src/Renci.SshNet/Messages/Transport/ServiceAcceptMessage.cs

@@ -1,4 +1,5 @@
 using System;
 using System;
+using Renci.SshNet.Common;
 
 
 namespace Renci.SshNet.Messages.Transport
 namespace Renci.SshNet.Messages.Transport
 {
 {

+ 1 - 0
src/Renci.SshNet/Messages/Transport/ServiceRequestMessage.cs

@@ -1,4 +1,5 @@
 using System;
 using System;
+using Renci.SshNet.Common;
 
 
 namespace Renci.SshNet.Messages.Transport
 namespace Renci.SshNet.Messages.Transport
 {
 {

+ 3 - 0
src/Renci.SshNet/NoneAuthenticationMethod.cs

@@ -1,5 +1,8 @@
 using System;
 using System;
 using System.Threading;
 using System.Threading;
+#if !FEATURE_WAITHANDLE_DISPOSE
+using Renci.SshNet.Common;
+#endif // !FEATURE_WAITHANDLE_DISPOSE
 using Renci.SshNet.Messages.Authentication;
 using Renci.SshNet.Messages.Authentication;
 using Renci.SshNet.Messages;
 using Renci.SshNet.Messages;
 
 

+ 3 - 1
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
 {
 {
     /// <summary>
     /// <summary>
     /// Base class for cipher mode implementations
     /// Base class for cipher mode implementations

+ 1 - 0
src/Renci.SshNet/Security/Cryptography/HMACMD5.cs

@@ -1,6 +1,7 @@
 #if FEATURE_HMAC_MD5
 #if FEATURE_HMAC_MD5
 
 
 using System.Security.Cryptography;
 using System.Security.Cryptography;
+using Renci.SshNet.Common;
 
 
 namespace Renci.SshNet.Security.Cryptography
 namespace Renci.SshNet.Security.Cryptography
 {
 {

+ 1 - 0
src/Renci.SshNet/Security/Cryptography/HMACSHA1.cs

@@ -1,6 +1,7 @@
 #if FEATURE_HMAC_SHA1
 #if FEATURE_HMAC_SHA1
 
 
 using System.Security.Cryptography;
 using System.Security.Cryptography;
+using Renci.SshNet.Common;
 
 
 namespace Renci.SshNet.Security.Cryptography
 namespace Renci.SshNet.Security.Cryptography
 {
 {

+ 1 - 0
src/Renci.SshNet/Security/Cryptography/HMACSHA256.cs

@@ -1,6 +1,7 @@
 #if FEATURE_HMAC_SHA256
 #if FEATURE_HMAC_SHA256
 
 
 using System.Security.Cryptography;
 using System.Security.Cryptography;
+using Renci.SshNet.Common;
 
 
 namespace Renci.SshNet.Security.Cryptography
 namespace Renci.SshNet.Security.Cryptography
 {
 {

+ 1 - 0
src/Renci.SshNet/Security/Cryptography/HMACSHA384.cs

@@ -1,6 +1,7 @@
 #if FEATURE_HMAC_SHA384
 #if FEATURE_HMAC_SHA384
 
 
 using System.Security.Cryptography;
 using System.Security.Cryptography;
+using Renci.SshNet.Common;
 
 
 namespace Renci.SshNet.Security.Cryptography
 namespace Renci.SshNet.Security.Cryptography
 {
 {

+ 1 - 0
src/Renci.SshNet/Security/Cryptography/HMACSHA512.cs

@@ -1,6 +1,7 @@
 #if FEATURE_HMAC_SHA512
 #if FEATURE_HMAC_SHA512
 
 
 using System.Security.Cryptography;
 using System.Security.Cryptography;
+using Renci.SshNet.Common;
 
 
 namespace Renci.SshNet.Security.Cryptography
 namespace Renci.SshNet.Security.Cryptography
 {
 {