diff --git a/src/Renci.SshNet/Abstractions/ThreadAbstraction.cs b/src/Renci.SshNet/Abstractions/ThreadAbstraction.cs
index 41db8039..5fab1e7b 100644
--- a/src/Renci.SshNet/Abstractions/ThreadAbstraction.cs
+++ b/src/Renci.SshNet/Abstractions/ThreadAbstraction.cs
@@ -2,8 +2,6 @@
using System.Threading;
using System.Threading.Tasks;
-using Renci.SshNet.Common;
-
namespace Renci.SshNet.Abstractions
{
internal static class ThreadAbstraction
@@ -18,7 +16,7 @@ namespace Renci.SshNet.Abstractions
///
public static Task ExecuteThreadLongRunning(Action action)
{
- ThrowHelper.ThrowIfNull(action);
+ ArgumentNullException.ThrowIfNull(action);
return Task.Factory.StartNew(action,
CancellationToken.None,
@@ -32,7 +30,7 @@ namespace Renci.SshNet.Abstractions
/// The action to execute.
public static void ExecuteThread(Action action)
{
- ThrowHelper.ThrowIfNull(action);
+ ArgumentNullException.ThrowIfNull(action);
_ = ThreadPool.QueueUserWorkItem(o => action());
}
diff --git a/src/Renci.SshNet/Abstractions/ThrowExtensions.cs b/src/Renci.SshNet/Abstractions/ThrowExtensions.cs
new file mode 100644
index 00000000..0c4b988f
--- /dev/null
+++ b/src/Renci.SshNet/Abstractions/ThrowExtensions.cs
@@ -0,0 +1,94 @@
+#nullable enable
+#if !NET
+using System.Diagnostics.CodeAnalysis;
+using System.Runtime.CompilerServices;
+
+namespace System
+{
+ internal static class ThrowExtensions
+ {
+ extension(ObjectDisposedException)
+ {
+ public static void ThrowIf(bool condition, object instance)
+ {
+ if (condition)
+ {
+ Throw(instance);
+
+ static void Throw(object? instance)
+ {
+ throw new ObjectDisposedException(instance?.GetType().FullName);
+ }
+ }
+ }
+ }
+
+ extension(ArgumentNullException)
+ {
+ public static void ThrowIfNull([NotNull] object? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
+ {
+ if (argument is null)
+ {
+ ThrowArgumentNullException(paramName);
+ }
+
+ [DoesNotReturn]
+ static void ThrowArgumentNullException(string? paramName)
+ {
+ throw new ArgumentNullException(paramName);
+ }
+ }
+ }
+
+ extension(ArgumentException)
+ {
+ public static void ThrowIfNullOrWhiteSpace([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
+ {
+ if (string.IsNullOrWhiteSpace(argument))
+ {
+ Throw(argument, paramName);
+
+ [DoesNotReturn]
+ static void Throw(string? argument, string? paramName)
+ {
+ ThrowIfNull(argument, paramName);
+ throw new ArgumentException("The value cannot be an empty string or composed entirely of whitespace.", paramName);
+ }
+ }
+ }
+
+ public static void ThrowIfNullOrEmpty([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
+ {
+ if (string.IsNullOrEmpty(argument))
+ {
+ Throw(argument, paramName);
+
+ [DoesNotReturn]
+ static void Throw(string? argument, string? paramName)
+ {
+ ThrowIfNull(argument, paramName);
+ throw new ArgumentException("The value cannot be an empty string.", paramName);
+ }
+ }
+ }
+ }
+
+ extension(ArgumentOutOfRangeException)
+ {
+ public static void ThrowIfNegative(long value, [CallerArgumentExpression(nameof(value))] string? paramName = null)
+ {
+ if (value < 0)
+ {
+ Throw(value, paramName);
+
+ [DoesNotReturn]
+ static void Throw(long value, string? paramName)
+ {
+ throw new ArgumentOutOfRangeException(paramName, value, "Value must be non-negative.");
+ }
+ }
+ }
+ }
+ }
+}
+#endif
diff --git a/src/Renci.SshNet/AuthenticationMethod.cs b/src/Renci.SshNet/AuthenticationMethod.cs
index 3c5f2cfb..fc205b10 100644
--- a/src/Renci.SshNet/AuthenticationMethod.cs
+++ b/src/Renci.SshNet/AuthenticationMethod.cs
@@ -1,7 +1,5 @@
using System;
-using Renci.SshNet.Common;
-
namespace Renci.SshNet
{
///
@@ -36,7 +34,7 @@ namespace Renci.SshNet
/// is whitespace or .
protected AuthenticationMethod(string username)
{
- ThrowHelper.ThrowIfNullOrWhiteSpace(username);
+ ArgumentException.ThrowIfNullOrWhiteSpace(username);
Username = username;
}
diff --git a/src/Renci.SshNet/BaseClient.cs b/src/Renci.SshNet/BaseClient.cs
index 4b0850b1..243d83da 100644
--- a/src/Renci.SshNet/BaseClient.cs
+++ b/src/Renci.SshNet/BaseClient.cs
@@ -186,8 +186,8 @@ namespace Renci.SshNet
///
private protected BaseClient(ConnectionInfo connectionInfo, bool ownsConnectionInfo, IServiceFactory serviceFactory)
{
- ThrowHelper.ThrowIfNull(connectionInfo);
- ThrowHelper.ThrowIfNull(serviceFactory);
+ ArgumentNullException.ThrowIfNull(connectionInfo);
+ ArgumentNullException.ThrowIfNull(serviceFactory);
_connectionInfo = connectionInfo;
_ownsConnectionInfo = ownsConnectionInfo;
@@ -467,7 +467,7 @@ namespace Renci.SshNet
/// The current instance is disposed.
protected void CheckDisposed()
{
- ThrowHelper.ThrowObjectDisposedIf(_isDisposed, this);
+ ObjectDisposedException.ThrowIf(_isDisposed, this);
}
///
diff --git a/src/Renci.SshNet/ClientAuthentication.cs b/src/Renci.SshNet/ClientAuthentication.cs
index bd386ed2..7f998caf 100644
--- a/src/Renci.SshNet/ClientAuthentication.cs
+++ b/src/Renci.SshNet/ClientAuthentication.cs
@@ -52,8 +52,8 @@ namespace Renci.SshNet
/// Failed to authenticate the client.
public void Authenticate(IConnectionInfoInternal connectionInfo, ISession session)
{
- ThrowHelper.ThrowIfNull(connectionInfo);
- ThrowHelper.ThrowIfNull(session);
+ ArgumentNullException.ThrowIfNull(connectionInfo);
+ ArgumentNullException.ThrowIfNull(session);
session.RegisterMessage("SSH_MSG_USERAUTH_FAILURE");
session.RegisterMessage("SSH_MSG_USERAUTH_SUCCESS");
diff --git a/src/Renci.SshNet/Common/ChannelDataEventArgs.cs b/src/Renci.SshNet/Common/ChannelDataEventArgs.cs
index 5ded6fe0..1698dd29 100644
--- a/src/Renci.SshNet/Common/ChannelDataEventArgs.cs
+++ b/src/Renci.SshNet/Common/ChannelDataEventArgs.cs
@@ -16,7 +16,7 @@ namespace Renci.SshNet.Common
public ChannelDataEventArgs(uint channelNumber, ArraySegment data)
: base(channelNumber)
{
- ThrowHelper.ThrowIfNull(data.Array);
+ ArgumentNullException.ThrowIfNull(data.Array);
Data = data;
}
diff --git a/src/Renci.SshNet/Common/ChannelInputStream.cs b/src/Renci.SshNet/Common/ChannelInputStream.cs
index a5dd0b41..8be3a662 100644
--- a/src/Renci.SshNet/Common/ChannelInputStream.cs
+++ b/src/Renci.SshNet/Common/ChannelInputStream.cs
@@ -106,7 +106,7 @@ namespace Renci.SshNet.Common
#endif
ValidateBufferArguments(buffer, offset, count);
- ThrowHelper.ThrowObjectDisposedIf(_isDisposed, this);
+ ObjectDisposedException.ThrowIf(_isDisposed, this);
if (count == 0)
{
diff --git a/src/Renci.SshNet/Common/ChannelRequestEventArgs.cs b/src/Renci.SshNet/Common/ChannelRequestEventArgs.cs
index ca82312e..7677f1cb 100644
--- a/src/Renci.SshNet/Common/ChannelRequestEventArgs.cs
+++ b/src/Renci.SshNet/Common/ChannelRequestEventArgs.cs
@@ -16,7 +16,7 @@ namespace Renci.SshNet.Common
/// is .
public ChannelRequestEventArgs(RequestInfo info)
{
- ThrowHelper.ThrowIfNull(info);
+ ArgumentNullException.ThrowIfNull(info);
Info = info;
}
diff --git a/src/Renci.SshNet/Common/Extensions.cs b/src/Renci.SshNet/Common/Extensions.cs
index b7a97d06..89ac0b40 100644
--- a/src/Renci.SshNet/Common/Extensions.cs
+++ b/src/Renci.SshNet/Common/Extensions.cs
@@ -193,7 +193,7 @@ namespace Renci.SshNet.Common
///
public static byte[] Take(this byte[] value, int offset, int count)
{
- ThrowHelper.ThrowIfNull(value);
+ ArgumentNullException.ThrowIfNull(value);
if (count == 0)
{
@@ -225,7 +225,7 @@ namespace Renci.SshNet.Common
///
public static byte[] Take(this byte[] value, int count)
{
- ThrowHelper.ThrowIfNull(value);
+ ArgumentNullException.ThrowIfNull(value);
if (count == 0)
{
@@ -244,8 +244,8 @@ namespace Renci.SshNet.Common
public static bool IsEqualTo(this byte[] left, byte[] right)
{
- ThrowHelper.ThrowIfNull(left);
- ThrowHelper.ThrowIfNull(right);
+ ArgumentNullException.ThrowIfNull(left);
+ ArgumentNullException.ThrowIfNull(right);
return left.AsSpan().SequenceEqual(right);
}
@@ -259,7 +259,7 @@ namespace Renci.SshNet.Common
///
public static byte[] TrimLeadingZeros(this byte[] value)
{
- ThrowHelper.ThrowIfNull(value);
+ ArgumentNullException.ThrowIfNull(value);
for (var i = 0; i < value.Length; i++)
{
diff --git a/src/Renci.SshNet/Common/HostKeyEventArgs.cs b/src/Renci.SshNet/Common/HostKeyEventArgs.cs
index b18d0cb4..37fe829a 100644
--- a/src/Renci.SshNet/Common/HostKeyEventArgs.cs
+++ b/src/Renci.SshNet/Common/HostKeyEventArgs.cs
@@ -97,7 +97,7 @@ namespace Renci.SshNet.Common
/// is .
public HostKeyEventArgs(KeyHostAlgorithm host)
{
- ThrowHelper.ThrowIfNull(host);
+ ArgumentNullException.ThrowIfNull(host);
CanTrust = true;
HostKey = host.KeyData.GetBytes();
diff --git a/src/Renci.SshNet/Common/PacketDump.cs b/src/Renci.SshNet/Common/PacketDump.cs
index ec3b5858..66b2b9bf 100644
--- a/src/Renci.SshNet/Common/PacketDump.cs
+++ b/src/Renci.SshNet/Common/PacketDump.cs
@@ -14,8 +14,8 @@ namespace Renci.SshNet.Common
public static string Create(byte[] data, int indentLevel)
{
- ThrowHelper.ThrowIfNull(data);
- ThrowHelper.ThrowIfNegative(indentLevel);
+ ArgumentNullException.ThrowIfNull(data);
+ ArgumentOutOfRangeException.ThrowIfNegative(indentLevel);
const int lineWidth = 16;
diff --git a/src/Renci.SshNet/Common/PipeStream.cs b/src/Renci.SshNet/Common/PipeStream.cs
index 49e48b6e..2a8d739e 100644
--- a/src/Renci.SshNet/Common/PipeStream.cs
+++ b/src/Renci.SshNet/Common/PipeStream.cs
@@ -123,7 +123,7 @@ namespace Renci.SshNet.Common
{
Debug.Assert(Monitor.IsEntered(_sync));
- ThrowHelper.ThrowObjectDisposedIf(_disposed, this);
+ ObjectDisposedException.ThrowIf(_disposed, this);
_buffer.EnsureAvailableSpace(buffer.Length);
diff --git a/src/Renci.SshNet/Common/PortForwardEventArgs.cs b/src/Renci.SshNet/Common/PortForwardEventArgs.cs
index 89def98c..9d427fe0 100644
--- a/src/Renci.SshNet/Common/PortForwardEventArgs.cs
+++ b/src/Renci.SshNet/Common/PortForwardEventArgs.cs
@@ -17,7 +17,7 @@ namespace Renci.SshNet.Common
/// is not within and .
internal PortForwardEventArgs(string host, uint port)
{
- ThrowHelper.ThrowIfNull(host);
+ ArgumentNullException.ThrowIfNull(host);
port.ValidatePort();
OriginatorHost = host;
diff --git a/src/Renci.SshNet/Common/PosixPath.cs b/src/Renci.SshNet/Common/PosixPath.cs
index 4d89c79f..3a487b1e 100644
--- a/src/Renci.SshNet/Common/PosixPath.cs
+++ b/src/Renci.SshNet/Common/PosixPath.cs
@@ -38,7 +38,7 @@ namespace Renci.SshNet.Common
/// is empty ("").
public static PosixPath CreateAbsoluteOrRelativeFilePath(string path)
{
- ThrowHelper.ThrowIfNull(path);
+ ArgumentNullException.ThrowIfNull(path);
var posixPath = new PosixPath();
@@ -92,7 +92,7 @@ namespace Renci.SshNet.Common
///
public static string GetFileName(string path)
{
- ThrowHelper.ThrowIfNull(path);
+ ArgumentNullException.ThrowIfNull(path);
var pathEnd = path.LastIndexOf('/');
if (pathEnd == -1)
@@ -119,7 +119,7 @@ namespace Renci.SshNet.Common
/// is .
public static string GetDirectoryName(string path)
{
- ThrowHelper.ThrowIfNull(path);
+ ArgumentNullException.ThrowIfNull(path);
var pathEnd = path.LastIndexOf('/');
if (pathEnd == -1)
diff --git a/src/Renci.SshNet/Common/SshData.cs b/src/Renci.SshNet/Common/SshData.cs
index 09840873..ff50a214 100644
--- a/src/Renci.SshNet/Common/SshData.cs
+++ b/src/Renci.SshNet/Common/SshData.cs
@@ -91,7 +91,7 @@ namespace Renci.SshNet.Common
/// is .
public void Load(byte[] data)
{
- ThrowHelper.ThrowIfNull(data);
+ ArgumentNullException.ThrowIfNull(data);
LoadInternal(data, 0, data.Length);
}
@@ -105,7 +105,7 @@ namespace Renci.SshNet.Common
/// is .
public void Load(byte[] data, int offset, int count)
{
- ThrowHelper.ThrowIfNull(data);
+ ArgumentNullException.ThrowIfNull(data);
LoadInternal(data, offset, count);
}
diff --git a/src/Renci.SshNet/Common/SshDataStream.cs b/src/Renci.SshNet/Common/SshDataStream.cs
index a13b635e..de0530bd 100644
--- a/src/Renci.SshNet/Common/SshDataStream.cs
+++ b/src/Renci.SshNet/Common/SshDataStream.cs
@@ -112,7 +112,7 @@ namespace Renci.SshNet.Common
/// is .
public void Write(byte[] data)
{
- ThrowHelper.ThrowIfNull(data);
+ ArgumentNullException.ThrowIfNull(data);
Write(data, 0, data.Length);
}
@@ -126,8 +126,8 @@ namespace Renci.SshNet.Common
/// is .
public void Write(string s, Encoding encoding)
{
- ThrowHelper.ThrowIfNull(s);
- ThrowHelper.ThrowIfNull(encoding);
+ ArgumentNullException.ThrowIfNull(s);
+ ArgumentNullException.ThrowIfNull(encoding);
#if NET
ReadOnlySpan value = s;
@@ -192,7 +192,7 @@ namespace Renci.SshNet.Common
/// is .
public void WriteBinary(byte[] buffer)
{
- ThrowHelper.ThrowIfNull(buffer);
+ ArgumentNullException.ThrowIfNull(buffer);
WriteBinary(buffer, 0, buffer.Length);
}
diff --git a/src/Renci.SshNet/Common/TaskToAsyncResult.cs b/src/Renci.SshNet/Common/TaskToAsyncResult.cs
index febeb658..d863ab55 100644
--- a/src/Renci.SshNet/Common/TaskToAsyncResult.cs
+++ b/src/Renci.SshNet/Common/TaskToAsyncResult.cs
@@ -1,6 +1,6 @@
#pragma warning disable
#if !NET
-// Copied verbatim from https://github.com/dotnet/runtime/blob/261611930d6b436d7c4395450356b624d903d9bf/src/libraries/Common/src/System/Threading/Tasks/TaskToAsyncResult.cs
+// Copied verbatim from https://github.com/dotnet/runtime/blob/7b2de1e5ed6368c536ee646346e6fd81939e6fe6/src/libraries/Common/src/System/Threading/Tasks/TaskToAsyncResult.cs
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
@@ -35,15 +35,7 @@ namespace System.Threading.Tasks
///
public static IAsyncResult Begin(Task task, AsyncCallback? callback, object? state)
{
-#if NET
ArgumentNullException.ThrowIfNull(task);
-#else
- if (task is null)
- {
- throw new ArgumentNullException(nameof(task));
- }
-#endif
-
return new TaskAsyncResult(task, state, callback);
}
@@ -72,14 +64,7 @@ namespace System.Threading.Tasks
/// was not produced by a call to .
public static Task Unwrap(IAsyncResult asyncResult)
{
-#if NET
ArgumentNullException.ThrowIfNull(asyncResult);
-#else
- if (asyncResult is null)
- {
- throw new ArgumentNullException(nameof(asyncResult));
- }
-#endif
if ((asyncResult as TaskAsyncResult)?._task is not Task task)
{
@@ -101,14 +86,7 @@ namespace System.Threading.Tasks
///
public static Task Unwrap(IAsyncResult asyncResult)
{
-#if NET
ArgumentNullException.ThrowIfNull(asyncResult);
-#else
- if (asyncResult is null)
- {
- throw new ArgumentNullException(nameof(asyncResult));
- }
-#endif
if ((asyncResult as TaskAsyncResult)?._task is not Task task)
{
diff --git a/src/Renci.SshNet/Common/ThrowHelper.cs b/src/Renci.SshNet/Common/ThrowHelper.cs
index be6b13b4..ddeb1e5b 100644
--- a/src/Renci.SshNet/Common/ThrowHelper.cs
+++ b/src/Renci.SshNet/Common/ThrowHelper.cs
@@ -1,93 +1,19 @@
#nullable enable
+#if !NET
using System;
using System.Diagnostics.CodeAnalysis;
-using System.Runtime.CompilerServices;
namespace Renci.SshNet.Common
{
internal static class ThrowHelper
{
- public static void ThrowObjectDisposedIf(bool condition, object instance)
- {
-#if NET
- ObjectDisposedException.ThrowIf(condition, instance);
-#else
- if (condition)
- {
- Throw(instance);
-
- static void Throw(object? instance)
- {
- throw new ObjectDisposedException(instance?.GetType().FullName);
- }
- }
-#endif
- }
-
- public static void ThrowIfNull([NotNull] object? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
- {
-#if NET
- ArgumentNullException.ThrowIfNull(argument, paramName);
-#else
- if (argument is null)
- {
- Throw(paramName);
-
- [DoesNotReturn]
- static void Throw(string? paramName)
- {
- throw new ArgumentNullException(paramName);
- }
- }
-#endif
- }
-
- public static void ThrowIfNullOrWhiteSpace([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
- {
-#if NET
- ArgumentException.ThrowIfNullOrWhiteSpace(argument, paramName);
-#else
- if (string.IsNullOrWhiteSpace(argument))
- {
- Throw(argument, paramName);
-
- [DoesNotReturn]
- static void Throw(string? argument, string? paramName)
- {
- ThrowIfNull(argument, paramName);
- throw new ArgumentException("The value cannot be an empty string or composed entirely of whitespace.", paramName);
- }
- }
-#endif
- }
-
- public static void ThrowIfNullOrEmpty([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
- {
-#if NET
- ArgumentException.ThrowIfNullOrEmpty(argument, paramName);
-#else
- if (string.IsNullOrEmpty(argument))
- {
- Throw(argument, paramName);
-
- [DoesNotReturn]
- static void Throw(string? argument, string? paramName)
- {
- ThrowIfNull(argument, paramName);
- throw new ArgumentException("The value cannot be an empty string.", paramName);
- }
- }
-#endif
- }
-
-#if !NET
// A rough copy of
// https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Private.CoreLib/src/System/IO/Stream.cs#L960C13-L974C10
// for lower targets.
public static void ValidateBufferArguments(byte[] buffer, int offset, int count)
{
- ThrowIfNull(buffer);
- ThrowIfNegative(offset);
+ ArgumentNullException.ThrowIfNull(buffer);
+ ArgumentOutOfRangeException.ThrowIfNegative(offset);
if ((uint)count > buffer.Length - offset)
{
@@ -102,24 +28,6 @@ namespace Renci.SshNet.Common
}
}
}
-#endif
-
- public static void ThrowIfNegative(long value, [CallerArgumentExpression(nameof(value))] string? paramName = null)
- {
-#if NET
- ArgumentOutOfRangeException.ThrowIfNegative(value, paramName);
-#else
- if (value < 0)
- {
- Throw(value, paramName);
-
- [DoesNotReturn]
- static void Throw(long value, string? paramName)
- {
- throw new ArgumentOutOfRangeException(paramName, value, "Value must be non-negative.");
- }
- }
-#endif
- }
}
}
+#endif
diff --git a/src/Renci.SshNet/Connection/ConnectorBase.cs b/src/Renci.SshNet/Connection/ConnectorBase.cs
index 0816967b..8dd09f79 100644
--- a/src/Renci.SshNet/Connection/ConnectorBase.cs
+++ b/src/Renci.SshNet/Connection/ConnectorBase.cs
@@ -18,7 +18,7 @@ namespace Renci.SshNet.Connection
protected ConnectorBase(ISocketFactory socketFactory, ILoggerFactory loggerFactory)
{
- ThrowHelper.ThrowIfNull(socketFactory);
+ ArgumentNullException.ThrowIfNull(socketFactory);
SocketFactory = socketFactory;
_logger = loggerFactory.CreateLogger(GetType());
diff --git a/src/Renci.SshNet/Connection/SshIdentification.cs b/src/Renci.SshNet/Connection/SshIdentification.cs
index 41e06e27..25e84d03 100644
--- a/src/Renci.SshNet/Connection/SshIdentification.cs
+++ b/src/Renci.SshNet/Connection/SshIdentification.cs
@@ -1,7 +1,5 @@
using System;
-using Renci.SshNet.Common;
-
namespace Renci.SshNet.Connection
{
///
@@ -33,8 +31,8 @@ namespace Renci.SshNet.Connection
/// is .
public SshIdentification(string protocolVersion, string softwareVersion, string comments)
{
- ThrowHelper.ThrowIfNull(protocolVersion);
- ThrowHelper.ThrowIfNull(softwareVersion);
+ ArgumentNullException.ThrowIfNull(protocolVersion);
+ ArgumentNullException.ThrowIfNull(softwareVersion);
ProtocolVersion = protocolVersion;
SoftwareVersion = softwareVersion;
diff --git a/src/Renci.SshNet/ConnectionInfo.cs b/src/Renci.SshNet/ConnectionInfo.cs
index 18ca1eeb..8b2fc608 100644
--- a/src/Renci.SshNet/ConnectionInfo.cs
+++ b/src/Renci.SshNet/ConnectionInfo.cs
@@ -325,17 +325,17 @@ namespace Renci.SshNet
/// No specified.
public ConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword, params AuthenticationMethod[] authenticationMethods)
{
- ThrowHelper.ThrowIfNull(host);
+ ArgumentNullException.ThrowIfNull(host);
port.ValidatePort();
- ThrowHelper.ThrowIfNullOrWhiteSpace(username);
+ ArgumentException.ThrowIfNullOrWhiteSpace(username);
if (proxyType != ProxyTypes.None)
{
- ThrowHelper.ThrowIfNull(proxyHost);
+ ArgumentNullException.ThrowIfNull(proxyHost);
proxyPort.ValidatePort();
}
- ThrowHelper.ThrowIfNull(authenticationMethods);
+ ArgumentNullException.ThrowIfNull(authenticationMethods);
if (authenticationMethods.Length == 0)
{
@@ -459,7 +459,7 @@ namespace Renci.SshNet
/// No suitable authentication method found to complete authentication, or permission denied.
internal void Authenticate(ISession session, IServiceFactory serviceFactory)
{
- ThrowHelper.ThrowIfNull(serviceFactory);
+ ArgumentNullException.ThrowIfNull(serviceFactory);
IsAuthenticated = false;
var clientAuthentication = serviceFactory.CreateClientAuthentication();
diff --git a/src/Renci.SshNet/ExpectAction.cs b/src/Renci.SshNet/ExpectAction.cs
index 1e06aa75..7b64c5bf 100644
--- a/src/Renci.SshNet/ExpectAction.cs
+++ b/src/Renci.SshNet/ExpectAction.cs
@@ -1,8 +1,6 @@
using System;
using System.Text.RegularExpressions;
-using Renci.SshNet.Common;
-
namespace Renci.SshNet
{
///
@@ -28,8 +26,8 @@ namespace Renci.SshNet
/// or is .
public ExpectAction(Regex expect, Action action)
{
- ThrowHelper.ThrowIfNull(expect);
- ThrowHelper.ThrowIfNull(action);
+ ArgumentNullException.ThrowIfNull(expect);
+ ArgumentNullException.ThrowIfNull(action);
Expect = expect;
Action = action;
@@ -43,8 +41,8 @@ namespace Renci.SshNet
/// or is .
public ExpectAction(string expect, Action action)
{
- ThrowHelper.ThrowIfNull(expect);
- ThrowHelper.ThrowIfNull(action);
+ ArgumentNullException.ThrowIfNull(expect);
+ ArgumentNullException.ThrowIfNull(action);
Expect = new Regex(Regex.Escape(expect));
Action = action;
diff --git a/src/Renci.SshNet/ForwardedPortDynamic.cs b/src/Renci.SshNet/ForwardedPortDynamic.cs
index 72045e4c..45ef5a3b 100644
--- a/src/Renci.SshNet/ForwardedPortDynamic.cs
+++ b/src/Renci.SshNet/ForwardedPortDynamic.cs
@@ -130,7 +130,7 @@ namespace Renci.SshNet
/// The current instance is disposed.
protected override void CheckDisposed()
{
- ThrowHelper.ThrowObjectDisposedIf(_isDisposed, this);
+ ObjectDisposedException.ThrowIf(_isDisposed, this);
}
///
diff --git a/src/Renci.SshNet/ForwardedPortLocal.cs b/src/Renci.SshNet/ForwardedPortLocal.cs
index 6ee313df..953bd8cf 100644
--- a/src/Renci.SshNet/ForwardedPortLocal.cs
+++ b/src/Renci.SshNet/ForwardedPortLocal.cs
@@ -91,8 +91,8 @@ namespace Renci.SshNet
/// is greater than .
public ForwardedPortLocal(string boundHost, uint boundPort, string host, uint port)
{
- ThrowHelper.ThrowIfNull(boundHost);
- ThrowHelper.ThrowIfNull(host);
+ ArgumentNullException.ThrowIfNull(boundHost);
+ ArgumentNullException.ThrowIfNull(host);
boundPort.ValidatePort();
port.ValidatePort();
@@ -158,7 +158,7 @@ namespace Renci.SshNet
/// The current instance is disposed.
protected override void CheckDisposed()
{
- ThrowHelper.ThrowObjectDisposedIf(_isDisposed, this);
+ ObjectDisposedException.ThrowIf(_isDisposed, this);
}
///
diff --git a/src/Renci.SshNet/ForwardedPortRemote.cs b/src/Renci.SshNet/ForwardedPortRemote.cs
index 6186f78c..3d9393dd 100644
--- a/src/Renci.SshNet/ForwardedPortRemote.cs
+++ b/src/Renci.SshNet/ForwardedPortRemote.cs
@@ -88,8 +88,8 @@ namespace Renci.SshNet
/// is greater than .
public ForwardedPortRemote(IPAddress boundHostAddress, uint boundPort, IPAddress hostAddress, uint port)
{
- ThrowHelper.ThrowIfNull(boundHostAddress);
- ThrowHelper.ThrowIfNull(hostAddress);
+ ArgumentNullException.ThrowIfNull(boundHostAddress);
+ ArgumentNullException.ThrowIfNull(hostAddress);
boundPort.ValidatePort();
port.ValidatePort();
@@ -227,7 +227,7 @@ namespace Renci.SshNet
/// The current instance is disposed.
protected override void CheckDisposed()
{
- ThrowHelper.ThrowObjectDisposedIf(_isDisposed, this);
+ ObjectDisposedException.ThrowIf(_isDisposed, this);
}
private void Session_ChannelOpening(object sender, MessageEventArgs e)
diff --git a/src/Renci.SshNet/MessageEventArgs`1.cs b/src/Renci.SshNet/MessageEventArgs`1.cs
index c54afb3d..9037239b 100644
--- a/src/Renci.SshNet/MessageEventArgs`1.cs
+++ b/src/Renci.SshNet/MessageEventArgs`1.cs
@@ -1,7 +1,5 @@
using System;
-using Renci.SshNet.Common;
-
namespace Renci.SshNet
{
///
@@ -22,7 +20,7 @@ namespace Renci.SshNet
/// is .
public MessageEventArgs(T message)
{
- ThrowHelper.ThrowIfNull(message);
+ ArgumentNullException.ThrowIfNull(message);
Message = message;
}
diff --git a/src/Renci.SshNet/Messages/Connection/ChannelDataMessage.cs b/src/Renci.SshNet/Messages/Connection/ChannelDataMessage.cs
index 8416eb68..cc5f0f55 100644
--- a/src/Renci.SshNet/Messages/Connection/ChannelDataMessage.cs
+++ b/src/Renci.SshNet/Messages/Connection/ChannelDataMessage.cs
@@ -1,4 +1,4 @@
-using Renci.SshNet.Common;
+using System;
namespace Renci.SshNet.Messages.Connection
{
@@ -89,7 +89,7 @@ namespace Renci.SshNet.Messages.Connection
public ChannelDataMessage(uint localChannelNumber, byte[] data)
: base(localChannelNumber)
{
- ThrowHelper.ThrowIfNull(data);
+ ArgumentNullException.ThrowIfNull(data);
Data = data;
Offset = 0;
@@ -106,7 +106,7 @@ namespace Renci.SshNet.Messages.Connection
public ChannelDataMessage(uint localChannelNumber, byte[] data, int offset, int size)
: base(localChannelNumber)
{
- ThrowHelper.ThrowIfNull(data);
+ ArgumentNullException.ThrowIfNull(data);
Data = data;
Offset = offset;
diff --git a/src/Renci.SshNet/Messages/Connection/ChannelOpen/ChannelOpenMessage.cs b/src/Renci.SshNet/Messages/Connection/ChannelOpen/ChannelOpenMessage.cs
index bd5c52bf..502c4330 100644
--- a/src/Renci.SshNet/Messages/Connection/ChannelOpen/ChannelOpenMessage.cs
+++ b/src/Renci.SshNet/Messages/Connection/ChannelOpen/ChannelOpenMessage.cs
@@ -1,8 +1,6 @@
using System;
using System.Globalization;
-using Renci.SshNet.Common;
-
namespace Renci.SshNet.Messages.Connection
{
///
@@ -106,7 +104,7 @@ namespace Renci.SshNet.Messages.Connection
/// is .
public ChannelOpenMessage(uint channelNumber, uint initialWindowSize, uint maximumPacketSize, ChannelOpenInfo info)
{
- ThrowHelper.ThrowIfNull(info);
+ ArgumentNullException.ThrowIfNull(info);
ChannelType = Ascii.GetBytes(info.ChannelType);
LocalChannelNumber = channelNumber;
diff --git a/src/Renci.SshNet/Messages/Connection/ChannelRequest/ExecRequestInfo.cs b/src/Renci.SshNet/Messages/Connection/ChannelRequest/ExecRequestInfo.cs
index 4d92d02d..9337d77f 100644
--- a/src/Renci.SshNet/Messages/Connection/ChannelRequest/ExecRequestInfo.cs
+++ b/src/Renci.SshNet/Messages/Connection/ChannelRequest/ExecRequestInfo.cs
@@ -1,8 +1,6 @@
using System;
using System.Text;
-using Renci.SshNet.Common;
-
namespace Renci.SshNet.Messages.Connection
{
///
@@ -81,8 +79,8 @@ namespace Renci.SshNet.Messages.Connection
public ExecRequestInfo(string command, Encoding encoding)
: this()
{
- ThrowHelper.ThrowIfNull(command);
- ThrowHelper.ThrowIfNull(encoding);
+ ArgumentNullException.ThrowIfNull(command);
+ ArgumentNullException.ThrowIfNull(encoding);
_command = encoding.GetBytes(command);
Encoding = encoding;
diff --git a/src/Renci.SshNet/Messages/Transport/IgnoreMessage.cs b/src/Renci.SshNet/Messages/Transport/IgnoreMessage.cs
index 25ebd43b..ce900458 100644
--- a/src/Renci.SshNet/Messages/Transport/IgnoreMessage.cs
+++ b/src/Renci.SshNet/Messages/Transport/IgnoreMessage.cs
@@ -1,7 +1,5 @@
using System;
-using Renci.SshNet.Common;
-
namespace Renci.SshNet.Messages.Transport
{
///
@@ -47,7 +45,7 @@ namespace Renci.SshNet.Messages.Transport
/// The data.
public IgnoreMessage(byte[] data)
{
- ThrowHelper.ThrowIfNull(data);
+ ArgumentNullException.ThrowIfNull(data);
Data = data;
}
diff --git a/src/Renci.SshNet/NoneAuthenticationMethod.cs b/src/Renci.SshNet/NoneAuthenticationMethod.cs
index 093660cc..95e9a183 100644
--- a/src/Renci.SshNet/NoneAuthenticationMethod.cs
+++ b/src/Renci.SshNet/NoneAuthenticationMethod.cs
@@ -1,7 +1,6 @@
using System;
using System.Threading;
-using Renci.SshNet.Common;
using Renci.SshNet.Messages;
using Renci.SshNet.Messages.Authentication;
@@ -44,7 +43,7 @@ namespace Renci.SshNet
/// is .
public override AuthenticationResult Authenticate(Session session)
{
- ThrowHelper.ThrowIfNull(session);
+ ArgumentNullException.ThrowIfNull(session);
session.UserAuthenticationSuccessReceived += Session_UserAuthenticationSuccessReceived;
session.UserAuthenticationFailureReceived += Session_UserAuthenticationFailureReceived;
diff --git a/src/Renci.SshNet/OrderedDictionary.netstandard.cs b/src/Renci.SshNet/OrderedDictionary.netstandard.cs
index a69b3200..365920ae 100644
--- a/src/Renci.SshNet/OrderedDictionary.netstandard.cs
+++ b/src/Renci.SshNet/OrderedDictionary.netstandard.cs
@@ -9,7 +9,9 @@ using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
+#if !NET
using Renci.SshNet.Common;
+#endif
namespace Renci.SshNet
{
@@ -486,8 +488,8 @@ namespace Renci.SshNet
public virtual void CopyTo(T[] array, int arrayIndex)
{
- ThrowHelper.ThrowIfNull(array);
- ThrowHelper.ThrowIfNegative(arrayIndex);
+ ArgumentNullException.ThrowIfNull(array);
+ ArgumentOutOfRangeException.ThrowIfNegative(arrayIndex);
if (array.Length - arrayIndex < Count)
{
diff --git a/src/Renci.SshNet/PasswordAuthenticationMethod.cs b/src/Renci.SshNet/PasswordAuthenticationMethod.cs
index 315eb21d..9abcaf29 100644
--- a/src/Renci.SshNet/PasswordAuthenticationMethod.cs
+++ b/src/Renci.SshNet/PasswordAuthenticationMethod.cs
@@ -69,7 +69,7 @@ namespace Renci.SshNet
public PasswordAuthenticationMethod(string username, byte[] password)
: base(username)
{
- ThrowHelper.ThrowIfNull(password);
+ ArgumentNullException.ThrowIfNull(password);
_password = password;
_requestMessage = new RequestMessagePassword(ServiceName.Connection, Username, _password);
@@ -85,7 +85,7 @@ namespace Renci.SshNet
/// is .
public override AuthenticationResult Authenticate(Session session)
{
- ThrowHelper.ThrowIfNull(session);
+ ArgumentNullException.ThrowIfNull(session);
_session = session;
diff --git a/src/Renci.SshNet/PrivateKeyAuthenticationMethod.cs b/src/Renci.SshNet/PrivateKeyAuthenticationMethod.cs
index 85554ada..cd55829e 100644
--- a/src/Renci.SshNet/PrivateKeyAuthenticationMethod.cs
+++ b/src/Renci.SshNet/PrivateKeyAuthenticationMethod.cs
@@ -42,7 +42,7 @@ namespace Renci.SshNet
public PrivateKeyAuthenticationMethod(string username, params IPrivateKeySource[] keyFiles)
: base(username)
{
- ThrowHelper.ThrowIfNull(keyFiles);
+ ArgumentNullException.ThrowIfNull(keyFiles);
KeyFiles = new Collection(keyFiles);
}
diff --git a/src/Renci.SshNet/PrivateKeyFile.PuTTY.cs b/src/Renci.SshNet/PrivateKeyFile.PuTTY.cs
index 5e5b6311..34c46c90 100644
--- a/src/Renci.SshNet/PrivateKeyFile.PuTTY.cs
+++ b/src/Renci.SshNet/PrivateKeyFile.PuTTY.cs
@@ -72,11 +72,11 @@ namespace Renci.SshNet
switch (_version)
{
case "3":
- ThrowHelper.ThrowIfNullOrEmpty(_argon2Type);
- ThrowHelper.ThrowIfNullOrEmpty(_argon2Iterations);
- ThrowHelper.ThrowIfNullOrEmpty(_argon2Memory);
- ThrowHelper.ThrowIfNullOrEmpty(_argon2Parallelism);
- ThrowHelper.ThrowIfNullOrEmpty(_argon2Salt);
+ ArgumentException.ThrowIfNullOrEmpty(_argon2Type);
+ ArgumentException.ThrowIfNullOrEmpty(_argon2Iterations);
+ ArgumentException.ThrowIfNullOrEmpty(_argon2Memory);
+ ArgumentException.ThrowIfNullOrEmpty(_argon2Parallelism);
+ ArgumentException.ThrowIfNullOrEmpty(_argon2Salt);
var keyData = Argon2(
_argon2Type,
diff --git a/src/Renci.SshNet/PrivateKeyFile.cs b/src/Renci.SshNet/PrivateKeyFile.cs
index a7339a91..24058cd7 100644
--- a/src/Renci.SshNet/PrivateKeyFile.cs
+++ b/src/Renci.SshNet/PrivateKeyFile.cs
@@ -172,7 +172,7 @@ namespace Renci.SshNet
/// The key.
public PrivateKeyFile(Key key)
{
- ThrowHelper.ThrowIfNull(key);
+ ArgumentNullException.ThrowIfNull(key);
_key = key;
_hostAlgorithms.Add(new KeyHostAlgorithm(key.ToString(), key));
@@ -223,7 +223,7 @@ namespace Renci.SshNet
/// is .
public PrivateKeyFile(string fileName, string? passPhrase, string? certificateFileName)
{
- ThrowHelper.ThrowIfNull(fileName);
+ ArgumentNullException.ThrowIfNull(fileName);
using (var keyFile = File.OpenRead(fileName))
{
@@ -263,7 +263,7 @@ namespace Renci.SshNet
/// A certificate which certifies the private key.
public PrivateKeyFile(Stream privateKey, string? passPhrase, Stream? certificate)
{
- ThrowHelper.ThrowIfNull(privateKey);
+ ArgumentNullException.ThrowIfNull(privateKey);
Open(privateKey, passPhrase);
diff --git a/src/Renci.SshNet/RemotePathDoubleQuoteTransformation.cs b/src/Renci.SshNet/RemotePathDoubleQuoteTransformation.cs
index b167e011..3a5f16da 100644
--- a/src/Renci.SshNet/RemotePathDoubleQuoteTransformation.cs
+++ b/src/Renci.SshNet/RemotePathDoubleQuoteTransformation.cs
@@ -1,8 +1,6 @@
using System;
using System.Text;
-using Renci.SshNet.Common;
-
namespace Renci.SshNet
{
///
@@ -52,7 +50,7 @@ namespace Renci.SshNet
///
public string Transform(string path)
{
- ThrowHelper.ThrowIfNull(path);
+ ArgumentNullException.ThrowIfNull(path);
var transformed = new StringBuilder(path.Length);
diff --git a/src/Renci.SshNet/RemotePathNoneTransformation.cs b/src/Renci.SshNet/RemotePathNoneTransformation.cs
index 08cae8cc..c0b39488 100644
--- a/src/Renci.SshNet/RemotePathNoneTransformation.cs
+++ b/src/Renci.SshNet/RemotePathNoneTransformation.cs
@@ -1,7 +1,5 @@
using System;
-using Renci.SshNet.Common;
-
namespace Renci.SshNet
{
///
@@ -23,7 +21,7 @@ namespace Renci.SshNet
///
public string Transform(string path)
{
- ThrowHelper.ThrowIfNull(path);
+ ArgumentNullException.ThrowIfNull(path);
return path;
}
diff --git a/src/Renci.SshNet/RemotePathShellQuoteTransformation.cs b/src/Renci.SshNet/RemotePathShellQuoteTransformation.cs
index d019547b..578ec4dc 100644
--- a/src/Renci.SshNet/RemotePathShellQuoteTransformation.cs
+++ b/src/Renci.SshNet/RemotePathShellQuoteTransformation.cs
@@ -1,8 +1,6 @@
using System;
using System.Text;
-using Renci.SshNet.Common;
-
namespace Renci.SshNet
{
///
@@ -82,7 +80,7 @@ namespace Renci.SshNet
///
public string Transform(string path)
{
- ThrowHelper.ThrowIfNull(path);
+ ArgumentNullException.ThrowIfNull(path);
// result is at least value and (likely) leading/trailing single-quotes
var sb = new StringBuilder(path.Length + 2);
diff --git a/src/Renci.SshNet/ScpClient.cs b/src/Renci.SshNet/ScpClient.cs
index 18fc9759..35ce5f5c 100644
--- a/src/Renci.SshNet/ScpClient.cs
+++ b/src/Renci.SshNet/ScpClient.cs
@@ -116,7 +116,7 @@ namespace Renci.SshNet
}
set
{
- ThrowHelper.ThrowIfNull(value);
+ ArgumentNullException.ThrowIfNull(value);
_remotePathTransformation = value;
}
@@ -288,7 +288,7 @@ namespace Renci.SshNet
/// Client is not connected.
public void Upload(FileInfo fileInfo, string path)
{
- ThrowHelper.ThrowIfNull(fileInfo);
+ ArgumentNullException.ThrowIfNull(fileInfo);
if (Session is null)
{
@@ -335,8 +335,8 @@ namespace Renci.SshNet
/// Client is not connected.
public void Upload(DirectoryInfo directoryInfo, string path)
{
- ThrowHelper.ThrowIfNull(directoryInfo);
- ThrowHelper.ThrowIfNullOrEmpty(path);
+ ArgumentNullException.ThrowIfNull(directoryInfo);
+ ArgumentException.ThrowIfNullOrEmpty(path);
if (Session is null)
{
@@ -378,8 +378,8 @@ namespace Renci.SshNet
/// Client is not connected.
public void Download(string filename, FileInfo fileInfo)
{
- ThrowHelper.ThrowIfNullOrEmpty(filename);
- ThrowHelper.ThrowIfNull(fileInfo);
+ ArgumentException.ThrowIfNullOrEmpty(filename);
+ ArgumentNullException.ThrowIfNull(fileInfo);
if (Session is null)
{
@@ -418,8 +418,8 @@ namespace Renci.SshNet
/// Client is not connected.
public void Download(string directoryName, DirectoryInfo directoryInfo)
{
- ThrowHelper.ThrowIfNullOrEmpty(directoryName);
- ThrowHelper.ThrowIfNull(directoryInfo);
+ ArgumentException.ThrowIfNullOrEmpty(directoryName);
+ ArgumentNullException.ThrowIfNull(directoryInfo);
if (Session is null)
{
@@ -458,8 +458,8 @@ namespace Renci.SshNet
/// Client is not connected.
public void Download(string filename, Stream destination)
{
- ThrowHelper.ThrowIfNullOrWhiteSpace(filename);
- ThrowHelper.ThrowIfNull(destination);
+ ArgumentException.ThrowIfNullOrWhiteSpace(filename);
+ ArgumentNullException.ThrowIfNull(destination);
if (Session is null)
{
diff --git a/src/Renci.SshNet/Security/Cryptography/Ciphers/AesCipher.BclImpl.cs b/src/Renci.SshNet/Security/Cryptography/Ciphers/AesCipher.BclImpl.cs
index 76e43e94..a4dd353c 100644
--- a/src/Renci.SshNet/Security/Cryptography/Ciphers/AesCipher.BclImpl.cs
+++ b/src/Renci.SshNet/Security/Cryptography/Ciphers/AesCipher.BclImpl.cs
@@ -25,7 +25,7 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
if (cipherMode != System.Security.Cryptography.CipherMode.ECB)
{
- ThrowHelper.ThrowIfNull(iv);
+ ArgumentNullException.ThrowIfNull(iv);
aes.IV = iv.Take(16);
}
diff --git a/src/Renci.SshNet/Security/Cryptography/ED25519DigitalSignature.cs b/src/Renci.SshNet/Security/Cryptography/ED25519DigitalSignature.cs
index d828a7c8..cd74d4c1 100644
--- a/src/Renci.SshNet/Security/Cryptography/ED25519DigitalSignature.cs
+++ b/src/Renci.SshNet/Security/Cryptography/ED25519DigitalSignature.cs
@@ -21,7 +21,7 @@ namespace Renci.SshNet.Security.Cryptography
/// is .
public ED25519DigitalSignature(ED25519Key key)
{
- ThrowHelper.ThrowIfNull(key);
+ ArgumentNullException.ThrowIfNull(key);
_key = key;
}
diff --git a/src/Renci.SshNet/Security/Cryptography/ED25519Key.cs b/src/Renci.SshNet/Security/Cryptography/ED25519Key.cs
index af5e928a..1cc43294 100644
--- a/src/Renci.SshNet/Security/Cryptography/ED25519Key.cs
+++ b/src/Renci.SshNet/Security/Cryptography/ED25519Key.cs
@@ -78,7 +78,7 @@ namespace Renci.SshNet.Security
/// The encoded public key data.
public ED25519Key(SshKeyData publicKeyData)
{
- ThrowHelper.ThrowIfNull(publicKeyData);
+ ArgumentNullException.ThrowIfNull(publicKeyData);
if (publicKeyData.Name != "ssh-ed25519" || publicKeyData.Keys.Length != 1)
{
diff --git a/src/Renci.SshNet/Security/Cryptography/EcdsaDigitalSignature.cs b/src/Renci.SshNet/Security/Cryptography/EcdsaDigitalSignature.cs
index 3070c200..5f15fe0d 100644
--- a/src/Renci.SshNet/Security/Cryptography/EcdsaDigitalSignature.cs
+++ b/src/Renci.SshNet/Security/Cryptography/EcdsaDigitalSignature.cs
@@ -18,7 +18,7 @@ namespace Renci.SshNet.Security.Cryptography
/// is .
public EcdsaDigitalSignature(EcdsaKey key)
{
- ThrowHelper.ThrowIfNull(key);
+ ArgumentNullException.ThrowIfNull(key);
_key = key;
}
diff --git a/src/Renci.SshNet/Security/Cryptography/EcdsaKey.cs b/src/Renci.SshNet/Security/Cryptography/EcdsaKey.cs
index f74500d8..aaf9123b 100644
--- a/src/Renci.SshNet/Security/Cryptography/EcdsaKey.cs
+++ b/src/Renci.SshNet/Security/Cryptography/EcdsaKey.cs
@@ -188,7 +188,7 @@ namespace Renci.SshNet.Security
/// The encoded public key data.
public EcdsaKey(SshKeyData publicKeyData)
{
- ThrowHelper.ThrowIfNull(publicKeyData);
+ ArgumentNullException.ThrowIfNull(publicKeyData);
if (!publicKeyData.Name.StartsWith("ecdsa-sha2-", StringComparison.Ordinal) || publicKeyData.Keys.Length != 2)
{
diff --git a/src/Renci.SshNet/Security/Cryptography/RsaKey.cs b/src/Renci.SshNet/Security/Cryptography/RsaKey.cs
index 9dff0ece..78669a99 100644
--- a/src/Renci.SshNet/Security/Cryptography/RsaKey.cs
+++ b/src/Renci.SshNet/Security/Cryptography/RsaKey.cs
@@ -139,7 +139,7 @@ namespace Renci.SshNet.Security
/// The encoded public key data.
public RsaKey(SshKeyData publicKeyData)
{
- ThrowHelper.ThrowIfNull(publicKeyData);
+ ArgumentNullException.ThrowIfNull(publicKeyData);
if (publicKeyData.Name != "ssh-rsa" || publicKeyData.Keys.Length != 2)
{
@@ -159,7 +159,7 @@ namespace Renci.SshNet.Security
/// DER encoded private key data.
public RsaKey(byte[] privateKeyData)
{
- ThrowHelper.ThrowIfNull(privateKeyData);
+ ArgumentNullException.ThrowIfNull(privateKeyData);
var keyReader = new AsnReader(privateKeyData, AsnEncodingRules.DER);
var sequenceReader = keyReader.ReadSequence();
diff --git a/src/Renci.SshNet/Security/Cryptography/SymmetricCipher.cs b/src/Renci.SshNet/Security/Cryptography/SymmetricCipher.cs
index a65ea3d1..87674a9f 100644
--- a/src/Renci.SshNet/Security/Cryptography/SymmetricCipher.cs
+++ b/src/Renci.SshNet/Security/Cryptography/SymmetricCipher.cs
@@ -1,7 +1,5 @@
using System;
-using Renci.SshNet.Common;
-
namespace Renci.SshNet.Security.Cryptography
{
///
@@ -21,7 +19,7 @@ namespace Renci.SshNet.Security.Cryptography
/// is .
protected SymmetricCipher(byte[] key)
{
- ThrowHelper.ThrowIfNull(key);
+ ArgumentNullException.ThrowIfNull(key);
Key = key;
}
diff --git a/src/Renci.SshNet/Security/KeyExchangeDiffieHellman.cs b/src/Renci.SshNet/Security/KeyExchangeDiffieHellman.cs
index c9e31e9a..ad8b77f3 100644
--- a/src/Renci.SshNet/Security/KeyExchangeDiffieHellman.cs
+++ b/src/Renci.SshNet/Security/KeyExchangeDiffieHellman.cs
@@ -7,7 +7,6 @@ using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto.Parameters;
using Renci.SshNet.Abstractions;
-using Renci.SshNet.Common;
using Renci.SshNet.Messages.Transport;
namespace Renci.SshNet.Security
@@ -53,9 +52,9 @@ namespace Renci.SshNet.Security
DHParameters parameters,
HashAlgorithmName hashAlgorithm)
{
- ThrowHelper.ThrowIfNull(name);
- ThrowHelper.ThrowIfNull(parameters);
- ThrowHelper.ThrowIfNullOrEmpty(hashAlgorithm.Name, nameof(hashAlgorithm));
+ ArgumentNullException.ThrowIfNull(name);
+ ArgumentNullException.ThrowIfNull(parameters);
+ ArgumentException.ThrowIfNullOrEmpty(hashAlgorithm.Name, nameof(hashAlgorithm));
Name = name;
_dhParameters = parameters;
diff --git a/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroupExchange.cs b/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroupExchange.cs
index 0a9d4657..d755b564 100644
--- a/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroupExchange.cs
+++ b/src/Renci.SshNet/Security/KeyExchangeDiffieHellmanGroupExchange.cs
@@ -7,7 +7,6 @@ using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto.Parameters;
using Renci.SshNet.Abstractions;
-using Renci.SshNet.Common;
using Renci.SshNet.Messages.Transport;
namespace Renci.SshNet.Security
@@ -83,8 +82,8 @@ namespace Renci.SshNet.Security
uint preferredGroupSize,
uint maximumGroupSize)
{
- ThrowHelper.ThrowIfNull(name);
- ThrowHelper.ThrowIfNullOrEmpty(hashAlgorithm.Name, nameof(hashAlgorithm));
+ ArgumentNullException.ThrowIfNull(name);
+ ArgumentException.ThrowIfNullOrEmpty(hashAlgorithm.Name, nameof(hashAlgorithm));
if (preferredGroupSize < minimumGroupSize || preferredGroupSize > maximumGroupSize)
{
diff --git a/src/Renci.SshNet/ServiceFactory.cs b/src/Renci.SshNet/ServiceFactory.cs
index ab3ae16c..8e8d721c 100644
--- a/src/Renci.SshNet/ServiceFactory.cs
+++ b/src/Renci.SshNet/ServiceFactory.cs
@@ -87,8 +87,8 @@ namespace Renci.SshNet
///
public IKeyExchange CreateKeyExchange(IDictionary> clientAlgorithms, string[] serverAlgorithms)
{
- ThrowHelper.ThrowIfNull(clientAlgorithms);
- ThrowHelper.ThrowIfNull(serverAlgorithms);
+ ArgumentNullException.ThrowIfNull(clientAlgorithms);
+ ArgumentNullException.ThrowIfNull(serverAlgorithms);
// find an algorithm that is supported by both client and server
var keyExchangeAlgorithmFactory = (from c in clientAlgorithms
@@ -215,8 +215,8 @@ namespace Renci.SshNet
/// The value of is not supported.
public IConnector CreateConnector(IConnectionInfo connectionInfo, ISocketFactory socketFactory)
{
- ThrowHelper.ThrowIfNull(connectionInfo);
- ThrowHelper.ThrowIfNull(socketFactory);
+ ArgumentNullException.ThrowIfNull(connectionInfo);
+ ArgumentNullException.ThrowIfNull(socketFactory);
var loggerFactory = connectionInfo.LoggerFactory ?? SshNetLoggingConfiguration.LoggerFactory;
diff --git a/src/Renci.SshNet/Session.cs b/src/Renci.SshNet/Session.cs
index e94ebeb2..06f94a0b 100644
--- a/src/Renci.SshNet/Session.cs
+++ b/src/Renci.SshNet/Session.cs
@@ -557,9 +557,9 @@ namespace Renci.SshNet
/// is .
internal Session(ConnectionInfo connectionInfo, IServiceFactory serviceFactory, ISocketFactory socketFactory)
{
- ThrowHelper.ThrowIfNull(connectionInfo);
- ThrowHelper.ThrowIfNull(serviceFactory);
- ThrowHelper.ThrowIfNull(socketFactory);
+ ArgumentNullException.ThrowIfNull(connectionInfo);
+ ArgumentNullException.ThrowIfNull(serviceFactory);
+ ArgumentNullException.ThrowIfNull(socketFactory);
ConnectionInfo = connectionInfo;
SessionLoggerFactory = connectionInfo.LoggerFactory ?? SshNetLoggingConfiguration.LoggerFactory;
@@ -937,7 +937,7 @@ namespace Renci.SshNet
///
private WaitResult TryWait(WaitHandle waitHandle, TimeSpan timeout, out Exception exception)
{
- ThrowHelper.ThrowIfNull(waitHandle);
+ ArgumentNullException.ThrowIfNull(waitHandle);
var waitHandles = new[]
{
@@ -999,7 +999,7 @@ namespace Renci.SshNet
/// A socket error was signaled while receiving messages from the server.
internal void WaitOnHandle(WaitHandle waitHandle, TimeSpan timeout)
{
- ThrowHelper.ThrowIfNull(waitHandle);
+ ArgumentNullException.ThrowIfNull(waitHandle);
var waitHandles = new[]
{
diff --git a/src/Renci.SshNet/Sftp/Requests/SftpRealPathRequest.cs b/src/Renci.SshNet/Sftp/Requests/SftpRealPathRequest.cs
index c34e907e..dc591baa 100644
--- a/src/Renci.SshNet/Sftp/Requests/SftpRealPathRequest.cs
+++ b/src/Renci.SshNet/Sftp/Requests/SftpRealPathRequest.cs
@@ -1,7 +1,6 @@
using System;
using System.Text;
-using Renci.SshNet.Common;
using Renci.SshNet.Sftp.Responses;
namespace Renci.SshNet.Sftp.Requests
@@ -44,7 +43,7 @@ namespace Renci.SshNet.Sftp.Requests
public SftpRealPathRequest(uint protocolVersion, uint requestId, string path, Encoding encoding, Action nameAction, Action statusAction)
: base(protocolVersion, requestId, statusAction)
{
- ThrowHelper.ThrowIfNull(nameAction);
+ ArgumentNullException.ThrowIfNull(nameAction);
Encoding = encoding;
Path = path;
diff --git a/src/Renci.SshNet/Sftp/SftpFile.cs b/src/Renci.SshNet/Sftp/SftpFile.cs
index 44694b5b..31cb0002 100644
--- a/src/Renci.SshNet/Sftp/SftpFile.cs
+++ b/src/Renci.SshNet/Sftp/SftpFile.cs
@@ -33,8 +33,8 @@ namespace Renci.SshNet.Sftp
throw new SshConnectionException("Client not connected.");
}
- ThrowHelper.ThrowIfNull(attributes);
- ThrowHelper.ThrowIfNull(fullName);
+ ArgumentNullException.ThrowIfNull(attributes);
+ ArgumentNullException.ThrowIfNull(fullName);
_sftpSession = sftpSession;
Attributes = attributes;
@@ -485,7 +485,7 @@ namespace Renci.SshNet.Sftp
/// is .
public void MoveTo(string destFileName)
{
- ThrowHelper.ThrowIfNull(destFileName);
+ ArgumentNullException.ThrowIfNull(destFileName);
_sftpSession.RequestRename(FullName, destFileName);
diff --git a/src/Renci.SshNet/Sftp/SftpFileReader.cs b/src/Renci.SshNet/Sftp/SftpFileReader.cs
index 1f3fe396..b36e8c99 100644
--- a/src/Renci.SshNet/Sftp/SftpFileReader.cs
+++ b/src/Renci.SshNet/Sftp/SftpFileReader.cs
@@ -78,7 +78,7 @@ namespace Renci.SshNet.Sftp
public byte[] Read()
{
- ThrowHelper.ThrowObjectDisposedIf(_disposingOrDisposed, this);
+ ObjectDisposedException.ThrowIf(_disposingOrDisposed, this);
if (_exception is not null)
{
diff --git a/src/Renci.SshNet/Sftp/SftpFileStream.cs b/src/Renci.SshNet/Sftp/SftpFileStream.cs
index 6ac7b486..5495e6f5 100644
--- a/src/Renci.SshNet/Sftp/SftpFileStream.cs
+++ b/src/Renci.SshNet/Sftp/SftpFileStream.cs
@@ -224,7 +224,7 @@ namespace Renci.SshNet.Sftp
{
Debug.Assert(isAsync || cancellationToken == default);
- ThrowHelper.ThrowIfNull(path);
+ ArgumentNullException.ThrowIfNull(path);
if (bufferSize <= 0)
{
@@ -828,7 +828,7 @@ namespace Renci.SshNet.Sftp
///
public override void SetLength(long value)
{
- ThrowHelper.ThrowIfNegative(value);
+ ArgumentOutOfRangeException.ThrowIfNegative(value);
// Lock down the file stream while we do this.
lock (_lock)
@@ -1179,7 +1179,7 @@ namespace Renci.SshNet.Sftp
private void CheckSessionIsOpen()
{
- ThrowHelper.ThrowObjectDisposedIf(_session is null, this);
+ ObjectDisposedException.ThrowIf(_session is null, this);
if (!_session.IsOpen)
{
diff --git a/src/Renci.SshNet/Sftp/SftpSession.cs b/src/Renci.SshNet/Sftp/SftpSession.cs
index 1de63eaf..9a6c401b 100644
--- a/src/Renci.SshNet/Sftp/SftpSession.cs
+++ b/src/Renci.SshNet/Sftp/SftpSession.cs
@@ -542,7 +542,7 @@ namespace Renci.SshNet.Sftp
/// is .
public byte[] EndOpen(SftpOpenAsyncResult asyncResult)
{
- ThrowHelper.ThrowIfNull(asyncResult);
+ ArgumentNullException.ThrowIfNull(asyncResult);
if (asyncResult.EndInvokeCalled)
{
@@ -658,7 +658,7 @@ namespace Renci.SshNet.Sftp
/// is .
public void EndClose(SftpCloseAsyncResult asyncResult)
{
- ThrowHelper.ThrowIfNull(asyncResult);
+ ArgumentNullException.ThrowIfNull(asyncResult);
if (asyncResult.EndInvokeCalled)
{
@@ -733,7 +733,7 @@ namespace Renci.SshNet.Sftp
/// is .
public byte[] EndRead(SftpReadAsyncResult asyncResult)
{
- ThrowHelper.ThrowIfNull(asyncResult);
+ ArgumentNullException.ThrowIfNull(asyncResult);
if (asyncResult.EndInvokeCalled)
{
@@ -1056,7 +1056,7 @@ namespace Renci.SshNet.Sftp
/// is .
public SftpFileAttributes EndLStat(SFtpStatAsyncResult asyncResult)
{
- ThrowHelper.ThrowIfNull(asyncResult);
+ ArgumentNullException.ThrowIfNull(asyncResult);
if (asyncResult.EndInvokeCalled)
{
@@ -1665,7 +1665,7 @@ namespace Renci.SshNet.Sftp
/// is .
public string EndRealPath(SftpRealPathAsyncResult asyncResult)
{
- ThrowHelper.ThrowIfNull(asyncResult);
+ ArgumentNullException.ThrowIfNull(asyncResult);
if (asyncResult.EndInvokeCalled)
{
@@ -1762,7 +1762,7 @@ namespace Renci.SshNet.Sftp
/// is .
public SftpFileAttributes EndStat(SFtpStatAsyncResult asyncResult)
{
- ThrowHelper.ThrowIfNull(asyncResult);
+ ArgumentNullException.ThrowIfNull(asyncResult);
if (asyncResult.EndInvokeCalled)
{
diff --git a/src/Renci.SshNet/SftpClient.cs b/src/Renci.SshNet/SftpClient.cs
index df795671..ad00a2f7 100644
--- a/src/Renci.SshNet/SftpClient.cs
+++ b/src/Renci.SshNet/SftpClient.cs
@@ -298,7 +298,7 @@ namespace Renci.SshNet
public void ChangeDirectory(string path)
{
CheckDisposed();
- ThrowHelper.ThrowIfNull(path);
+ ArgumentNullException.ThrowIfNull(path);
if (_sftpSession is null)
{
@@ -323,7 +323,7 @@ namespace Renci.SshNet
public Task ChangeDirectoryAsync(string path, CancellationToken cancellationToken = default)
{
CheckDisposed();
- ThrowHelper.ThrowIfNull(path);
+ ArgumentNullException.ThrowIfNull(path);
if (_sftpSession is null)
{
@@ -364,7 +364,7 @@ namespace Renci.SshNet
public void CreateDirectory(string path)
{
CheckDisposed();
- ThrowHelper.ThrowIfNullOrWhiteSpace(path);
+ ArgumentException.ThrowIfNullOrWhiteSpace(path);
if (_sftpSession is null)
{
@@ -390,7 +390,7 @@ namespace Renci.SshNet
public async Task CreateDirectoryAsync(string path, CancellationToken cancellationToken = default)
{
CheckDisposed();
- ThrowHelper.ThrowIfNullOrWhiteSpace(path);
+ ArgumentException.ThrowIfNullOrWhiteSpace(path);
if (_sftpSession is null)
{
@@ -415,7 +415,7 @@ namespace Renci.SshNet
public void DeleteDirectory(string path)
{
CheckDisposed();
- ThrowHelper.ThrowIfNullOrWhiteSpace(path);
+ ArgumentException.ThrowIfNullOrWhiteSpace(path);
if (_sftpSession is null)
{
@@ -431,7 +431,7 @@ namespace Renci.SshNet
public async Task DeleteDirectoryAsync(string path, CancellationToken cancellationToken = default)
{
CheckDisposed();
- ThrowHelper.ThrowIfNullOrWhiteSpace(path);
+ ArgumentException.ThrowIfNullOrWhiteSpace(path);
if (_sftpSession is null)
{
@@ -458,7 +458,7 @@ namespace Renci.SshNet
public void DeleteFile(string path)
{
CheckDisposed();
- ThrowHelper.ThrowIfNullOrWhiteSpace(path);
+ ArgumentException.ThrowIfNullOrWhiteSpace(path);
if (_sftpSession is null)
{
@@ -474,7 +474,7 @@ namespace Renci.SshNet
public async Task DeleteFileAsync(string path, CancellationToken cancellationToken)
{
CheckDisposed();
- ThrowHelper.ThrowIfNullOrWhiteSpace(path);
+ ArgumentException.ThrowIfNullOrWhiteSpace(path);
if (_sftpSession is null)
{
@@ -516,8 +516,8 @@ namespace Renci.SshNet
public void RenameFile(string oldPath, string newPath, bool isPosix)
{
CheckDisposed();
- ThrowHelper.ThrowIfNull(oldPath);
- ThrowHelper.ThrowIfNull(newPath);
+ ArgumentNullException.ThrowIfNull(oldPath);
+ ArgumentNullException.ThrowIfNull(newPath);
if (_sftpSession is null)
{
@@ -553,8 +553,8 @@ namespace Renci.SshNet
public async Task RenameFileAsync(string oldPath, string newPath, CancellationToken cancellationToken)
{
CheckDisposed();
- ThrowHelper.ThrowIfNull(oldPath);
- ThrowHelper.ThrowIfNull(newPath);
+ ArgumentNullException.ThrowIfNull(oldPath);
+ ArgumentNullException.ThrowIfNull(newPath);
if (_sftpSession is null)
{
@@ -581,8 +581,8 @@ namespace Renci.SshNet
public void SymbolicLink(string path, string linkPath)
{
CheckDisposed();
- ThrowHelper.ThrowIfNullOrWhiteSpace(path);
- ThrowHelper.ThrowIfNullOrWhiteSpace(linkPath);
+ ArgumentException.ThrowIfNullOrWhiteSpace(path);
+ ArgumentException.ThrowIfNullOrWhiteSpace(linkPath);
if (_sftpSession is null)
{
@@ -633,7 +633,7 @@ namespace Renci.SshNet
public async IAsyncEnumerable ListDirectoryAsync(string path, [EnumeratorCancellation] CancellationToken cancellationToken)
{
CheckDisposed();
- ThrowHelper.ThrowIfNull(path);
+ ArgumentNullException.ThrowIfNull(path);
if (_sftpSession is null)
{
@@ -738,7 +738,7 @@ namespace Renci.SshNet
public ISftpFile Get(string path)
{
CheckDisposed();
- ThrowHelper.ThrowIfNull(path);
+ ArgumentNullException.ThrowIfNull(path);
if (_sftpSession is null)
{
@@ -768,7 +768,7 @@ namespace Renci.SshNet
public async Task GetAsync(string path, CancellationToken cancellationToken)
{
CheckDisposed();
- ThrowHelper.ThrowIfNull(path);
+ ArgumentNullException.ThrowIfNull(path);
if (_sftpSession is null)
{
@@ -799,7 +799,7 @@ namespace Renci.SshNet
public bool Exists(string path)
{
CheckDisposed();
- ThrowHelper.ThrowIfNullOrWhiteSpace(path);
+ ArgumentException.ThrowIfNullOrWhiteSpace(path);
if (_sftpSession is null)
{
@@ -855,7 +855,7 @@ namespace Renci.SshNet
public async Task ExistsAsync(string path, CancellationToken cancellationToken = default)
{
CheckDisposed();
- ThrowHelper.ThrowIfNullOrWhiteSpace(path);
+ ArgumentException.ThrowIfNullOrWhiteSpace(path);
if (_sftpSession is null)
{
@@ -977,8 +977,8 @@ namespace Renci.SshNet
public IAsyncResult BeginDownloadFile(string path, Stream output, AsyncCallback? asyncCallback, object? state, Action? downloadCallback = null)
{
CheckDisposed();
- ThrowHelper.ThrowIfNullOrWhiteSpace(path);
- ThrowHelper.ThrowIfNull(output);
+ ArgumentException.ThrowIfNullOrWhiteSpace(path);
+ ArgumentNullException.ThrowIfNull(output);
var asyncResult = new SftpDownloadAsyncResult(asyncCallback, state);
@@ -1028,8 +1028,8 @@ namespace Renci.SshNet
///
public void UploadFile(Stream input, string path, bool canOverride, Action? uploadCallback = null)
{
- ThrowHelper.ThrowIfNull(input);
- ThrowHelper.ThrowIfNullOrWhiteSpace(path);
+ ArgumentNullException.ThrowIfNull(input);
+ ArgumentException.ThrowIfNullOrWhiteSpace(path);
CheckDisposed();
var flags = Flags.Write | Flags.Truncate;
@@ -1056,8 +1056,8 @@ namespace Renci.SshNet
///
public Task UploadFileAsync(Stream input, string path, CancellationToken cancellationToken = default)
{
- ThrowHelper.ThrowIfNull(input);
- ThrowHelper.ThrowIfNullOrWhiteSpace(path);
+ ArgumentNullException.ThrowIfNull(input);
+ ArgumentException.ThrowIfNullOrWhiteSpace(path);
CheckDisposed();
return InternalUploadFile(
@@ -1182,8 +1182,8 @@ namespace Renci.SshNet
///
public IAsyncResult BeginUploadFile(Stream input, string path, bool canOverride, AsyncCallback? asyncCallback, object? state, Action? uploadCallback = null)
{
- ThrowHelper.ThrowIfNull(input);
- ThrowHelper.ThrowIfNullOrWhiteSpace(path);
+ ArgumentNullException.ThrowIfNull(input);
+ ArgumentException.ThrowIfNullOrWhiteSpace(path);
CheckDisposed();
var flags = Flags.Write | Flags.Truncate;
@@ -1258,7 +1258,7 @@ namespace Renci.SshNet
public SftpFileSystemInformation GetStatus(string path)
{
CheckDisposed();
- ThrowHelper.ThrowIfNull(path);
+ ArgumentNullException.ThrowIfNull(path);
if (_sftpSession is null)
{
@@ -1285,7 +1285,7 @@ namespace Renci.SshNet
public async Task GetStatusAsync(string path, CancellationToken cancellationToken)
{
CheckDisposed();
- ThrowHelper.ThrowIfNull(path);
+ ArgumentNullException.ThrowIfNull(path);
if (_sftpSession is null)
{
@@ -1315,7 +1315,7 @@ namespace Renci.SshNet
public void AppendAllLines(string path, IEnumerable contents)
{
CheckDisposed();
- ThrowHelper.ThrowIfNull(contents);
+ ArgumentNullException.ThrowIfNull(contents);
using (var stream = AppendText(path))
{
@@ -1339,7 +1339,7 @@ namespace Renci.SshNet
public void AppendAllLines(string path, IEnumerable contents, Encoding encoding)
{
CheckDisposed();
- ThrowHelper.ThrowIfNull(contents);
+ ArgumentNullException.ThrowIfNull(contents);
using (var stream = AppendText(path, encoding))
{
@@ -1422,7 +1422,7 @@ namespace Renci.SshNet
public StreamWriter AppendText(string path, Encoding encoding)
{
CheckDisposed();
- ThrowHelper.ThrowIfNull(encoding);
+ ArgumentNullException.ThrowIfNull(encoding);
return new StreamWriter(Open(path, FileMode.Append, FileAccess.Write), encoding);
}
@@ -1795,7 +1795,7 @@ namespace Renci.SshNet
public IEnumerable ReadLines(string path, Encoding encoding)
{
// We allow this usage exception to throw eagerly...
- ThrowHelper.ThrowIfNull(path);
+ ArgumentNullException.ThrowIfNull(path);
// ... but other exceptions will throw lazily i.e. inside the state machine created
// by yield. We could choose to open the file eagerly as well in order to throw
@@ -1868,7 +1868,7 @@ namespace Renci.SshNet
///
public void WriteAllBytes(string path, byte[] bytes)
{
- ThrowHelper.ThrowIfNull(bytes);
+ ArgumentNullException.ThrowIfNull(bytes);
UploadFile(new MemoryStream(bytes), path);
}
@@ -2014,8 +2014,8 @@ namespace Renci.SshNet
/// If a problem occurs while copying the file.
public IEnumerable SynchronizeDirectories(string sourcePath, string destinationPath, string searchPattern)
{
- ThrowHelper.ThrowIfNull(sourcePath);
- ThrowHelper.ThrowIfNullOrWhiteSpace(destinationPath);
+ ArgumentNullException.ThrowIfNull(sourcePath);
+ ArgumentException.ThrowIfNullOrWhiteSpace(destinationPath);
return InternalSynchronizeDirectories(sourcePath, destinationPath, searchPattern, asyncResult: null);
}
@@ -2036,9 +2036,9 @@ namespace Renci.SshNet
/// If a problem occurs while copying the file.
public IAsyncResult BeginSynchronizeDirectories(string sourcePath, string destinationPath, string searchPattern, AsyncCallback? asyncCallback, object? state)
{
- ThrowHelper.ThrowIfNull(sourcePath);
- ThrowHelper.ThrowIfNullOrWhiteSpace(destinationPath);
- ThrowHelper.ThrowIfNull(searchPattern);
+ ArgumentNullException.ThrowIfNull(sourcePath);
+ ArgumentException.ThrowIfNullOrWhiteSpace(destinationPath);
+ ArgumentNullException.ThrowIfNull(searchPattern);
var asyncResult = new SftpSynchronizeDirectoriesAsyncResult(asyncCallback, state);
@@ -2185,7 +2185,7 @@ namespace Renci.SshNet
/// Client not connected.
private List InternalListDirectory(string path, SftpListDirectoryAsyncResult? asyncResult, Action? listCallback)
{
- ThrowHelper.ThrowIfNull(path);
+ ArgumentNullException.ThrowIfNull(path);
if (_sftpSession is null)
{
@@ -2249,8 +2249,8 @@ namespace Renci.SshNet
/// Client not connected.
private void InternalDownloadFile(string path, Stream output, SftpDownloadAsyncResult? asyncResult, Action? downloadCallback)
{
- ThrowHelper.ThrowIfNull(output);
- ThrowHelper.ThrowIfNullOrWhiteSpace(path);
+ ArgumentNullException.ThrowIfNull(output);
+ ArgumentException.ThrowIfNullOrWhiteSpace(path);
if (_sftpSession is null)
{
@@ -2297,8 +2297,8 @@ namespace Renci.SshNet
private async Task InternalDownloadFileAsync(string path, Stream output, CancellationToken cancellationToken)
{
- ThrowHelper.ThrowIfNull(output);
- ThrowHelper.ThrowIfNullOrWhiteSpace(path);
+ ArgumentNullException.ThrowIfNull(output);
+ ArgumentException.ThrowIfNullOrWhiteSpace(path);
if (_sftpSession is null)
{
diff --git a/src/Renci.SshNet/ShellStream.cs b/src/Renci.SshNet/ShellStream.cs
index e3ef7ff0..958af4da 100644
--- a/src/Renci.SshNet/ShellStream.cs
+++ b/src/Renci.SshNet/ShellStream.cs
@@ -215,7 +215,7 @@ namespace Renci.SshNet
///
public override void Flush()
{
- ThrowHelper.ThrowObjectDisposedIf(_disposed, this);
+ ObjectDisposedException.ThrowIf(_disposed, this);
if (_writeBuffer.ActiveLength > 0)
{
@@ -295,7 +295,7 @@ namespace Renci.SshNet
/// The stream is closed.
public void ChangeWindowSize(uint columns, uint rows, uint width, uint height)
{
- ThrowHelper.ThrowObjectDisposedIf(_disposed, this);
+ ObjectDisposedException.ThrowIf(_disposed, this);
_channel.SendWindowChangeRequest(columns, rows, width, height);
}
@@ -864,7 +864,7 @@ namespace Renci.SshNet
private void Write(ReadOnlySpan buffer)
#endif
{
- ThrowHelper.ThrowObjectDisposedIf(_disposed, this);
+ ObjectDisposedException.ThrowIf(_disposed, this);
while (!buffer.IsEmpty)
{
diff --git a/src/Renci.SshNet/SshClient.cs b/src/Renci.SshNet/SshClient.cs
index 05508462..b174d508 100644
--- a/src/Renci.SshNet/SshClient.cs
+++ b/src/Renci.SshNet/SshClient.cs
@@ -155,7 +155,7 @@ namespace Renci.SshNet
///
public void AddForwardedPort(ForwardedPort port)
{
- ThrowHelper.ThrowIfNull(port);
+ ArgumentNullException.ThrowIfNull(port);
EnsureSessionIsOpen();
@@ -166,7 +166,7 @@ namespace Renci.SshNet
///
public void RemoveForwardedPort(ForwardedPort port)
{
- ThrowHelper.ThrowIfNull(port);
+ ArgumentNullException.ThrowIfNull(port);
// Stop port forwarding before removing it
port.Stop();
diff --git a/src/Renci.SshNet/SshCommand.cs b/src/Renci.SshNet/SshCommand.cs
index bd7ae139..ce104224 100644
--- a/src/Renci.SshNet/SshCommand.cs
+++ b/src/Renci.SshNet/SshCommand.cs
@@ -214,9 +214,9 @@ namespace Renci.SshNet
/// Either , is .
internal SshCommand(ISession session, string commandText, Encoding encoding)
{
- ThrowHelper.ThrowIfNull(session);
- ThrowHelper.ThrowIfNull(commandText);
- ThrowHelper.ThrowIfNull(encoding);
+ ArgumentNullException.ThrowIfNull(session);
+ ArgumentNullException.ThrowIfNull(commandText);
+ ArgumentNullException.ThrowIfNull(encoding);
_session = session;
CommandText = commandText;
@@ -244,7 +244,7 @@ namespace Renci.SshNet
#pragma warning disable CA1849 // Call async methods when in an async method; PipeStream.DisposeAsync would complete synchronously anyway.
public Task ExecuteAsync(CancellationToken cancellationToken = default)
{
- ThrowHelper.ThrowObjectDisposedIf(_isDisposed, this);
+ ObjectDisposedException.ThrowIf(_isDisposed, this);
if (cancellationToken.IsCancellationRequested)
{
@@ -385,7 +385,7 @@ namespace Renci.SshNet
/// Operation has timed out.
public IAsyncResult BeginExecute(string commandText, AsyncCallback? callback, object? state)
{
- ThrowHelper.ThrowIfNull(commandText);
+ ArgumentNullException.ThrowIfNull(commandText);
CommandText = commandText;
diff --git a/src/Renci.SshNet/SshMessageFactory.cs b/src/Renci.SshNet/SshMessageFactory.cs
index 038d7c3a..d598ff86 100644
--- a/src/Renci.SshNet/SshMessageFactory.cs
+++ b/src/Renci.SshNet/SshMessageFactory.cs
@@ -184,7 +184,7 @@ namespace Renci.SshNet
public void EnableAndActivateMessage(string messageName)
{
- ThrowHelper.ThrowIfNull(messageName);
+ ArgumentNullException.ThrowIfNull(messageName);
lock (_lock)
{
@@ -208,7 +208,7 @@ namespace Renci.SshNet
public void DisableAndDeactivateMessage(string messageName)
{
- ThrowHelper.ThrowIfNull(messageName);
+ ArgumentNullException.ThrowIfNull(messageName);
lock (_lock)
{
diff --git a/src/Renci.SshNet/SshNetLoggingConfiguration.cs b/src/Renci.SshNet/SshNetLoggingConfiguration.cs
index fa8581b3..6d68904a 100644
--- a/src/Renci.SshNet/SshNetLoggingConfiguration.cs
+++ b/src/Renci.SshNet/SshNetLoggingConfiguration.cs
@@ -1,9 +1,9 @@
#nullable enable
+using System;
+
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
-using Renci.SshNet.Common;
-
namespace Renci.SshNet
{
///
@@ -19,7 +19,7 @@ namespace Renci.SshNet
/// The logger factory.
public static void InitializeLogging(ILoggerFactory loggerFactory)
{
- ThrowHelper.ThrowIfNull(loggerFactory);
+ ArgumentNullException.ThrowIfNull(loggerFactory);
LoggerFactory = loggerFactory;
}
diff --git a/src/Renci.SshNet/SubsystemSession.cs b/src/Renci.SshNet/SubsystemSession.cs
index a632f41e..47e37161 100644
--- a/src/Renci.SshNet/SubsystemSession.cs
+++ b/src/Renci.SshNet/SubsystemSession.cs
@@ -55,7 +55,7 @@ namespace Renci.SshNet
{
get
{
- ThrowHelper.ThrowObjectDisposedIf(_isDisposed, this);
+ ObjectDisposedException.ThrowIf(_isDisposed, this);
return _channel;
}
@@ -89,8 +89,8 @@ namespace Renci.SshNet
/// or is .
protected SubsystemSession(ISession session, string subsystemName, int operationTimeout)
{
- ThrowHelper.ThrowIfNull(session);
- ThrowHelper.ThrowIfNull(subsystemName);
+ ArgumentNullException.ThrowIfNull(session);
+ ArgumentNullException.ThrowIfNull(subsystemName);
_session = session;
_subsystemName = subsystemName;
@@ -106,7 +106,7 @@ namespace Renci.SshNet
/// The channel session could not be opened, or the subsystem could not be executed.
public void Connect()
{
- ThrowHelper.ThrowObjectDisposedIf(_isDisposed, this);
+ ObjectDisposedException.ThrowIf(_isDisposed, this);
if (IsOpen)
{
@@ -166,7 +166,7 @@ namespace Renci.SshNet
/// The data to be sent.
public void SendData(byte[] data)
{
- ThrowHelper.ThrowObjectDisposedIf(_isDisposed, this);
+ ObjectDisposedException.ThrowIf(_isDisposed, this);
EnsureSessionIsOpen();
_channel.SendData(data);
diff --git a/test/Renci.SshNet.IntegrationTests/Common/Socks5Handler.cs b/test/Renci.SshNet.IntegrationTests/Common/Socks5Handler.cs
index 1c2beda8..d8b72cb3 100644
--- a/test/Renci.SshNet.IntegrationTests/Common/Socks5Handler.cs
+++ b/test/Renci.SshNet.IntegrationTests/Common/Socks5Handler.cs
@@ -22,7 +22,7 @@ namespace Renci.SshNet.IntegrationTests.Common
public Socket Connect(IPEndPoint endPoint)
{
- ThrowHelper.ThrowIfNull(endPoint);
+ ArgumentNullException.ThrowIfNull(endPoint);
var addressBytes = GetAddressBytes(endPoint);
return Connect(addressBytes, endPoint.Port);
@@ -30,7 +30,7 @@ namespace Renci.SshNet.IntegrationTests.Common
public Socket Connect(string host, int port)
{
- ThrowHelper.ThrowIfNull(host);
+ ArgumentNullException.ThrowIfNull(host);
if (host.Length > byte.MaxValue)
{