Skip to content

Commit

Permalink
just move the definition
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob-Hague committed Jan 11, 2025
1 parent 4dcd67e commit 7efd655
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 164 deletions.
74 changes: 18 additions & 56 deletions src/Renci.SshNet/AuthenticationMethod.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
<<<<<<< HEAD
using Renci.SshNet.Common;
using System;
using System.Threading;
using Renci.SshNet.Security.Org.BouncyCastle.Crypto.Parameters;
=======
using System;

using Renci.SshNet.Common;
>>>>>>> develop

namespace Renci.SshNet
{
Expand All @@ -16,16 +9,6 @@ namespace Renci.SshNet
/// </summary>
public abstract class AuthenticationMethod : IAuthenticationMethod, IDisposable
{
/// <summary>
/// Tracks result of current authentication process
/// </summary>
protected AuthenticationResult _authenticationResult = AuthenticationResult.Failure;

/// <summary>
/// Tracks completion of current authentication process
/// </summary>
protected EventWaitHandle _authenticationCompleted = null;

/// <summary>
/// Gets the name of the authentication method.
/// </summary>
Expand Down Expand Up @@ -58,45 +41,6 @@ protected AuthenticationMethod(string username)
Username = username;
}

#region IDisposable Members

private bool _isDisposed = false;

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}


/// <summary>
/// Releases unmanaged and - optionally - managed resources
/// </summary>
/// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
protected void Dispose(bool disposing)
{
if (_isDisposed)
return;

if (disposing)
{
var authenticationCompleted = _authenticationCompleted;
if (authenticationCompleted != null)
{
authenticationCompleted.Dispose();
_authenticationCompleted = null;
}

// Only if called with Dispose(true) otherwise we treat it is as not Disposed properly
_isDisposed = true;
}
}

#endregion

/// <summary>
/// Authenticates the specified session.
/// </summary>
Expand All @@ -117,5 +61,23 @@ AuthenticationResult IAuthenticationMethod.Authenticate(ISession session)
{
return Authenticate((Session)session);
}

/// <summary>
/// Releases unmanaged and - optionally - managed resources.
/// </summary>
/// <param name="disposing">
/// <see langword="true"/> to release both managed and unmanaged resources;
/// <see langword="false"/> to release only unmanaged resources.
/// </param>
protected virtual void Dispose(bool disposing)
{
}

/// <inheritdoc/>
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}
26 changes: 4 additions & 22 deletions src/Renci.SshNet/KeyboardInteractiveAuthenticationMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@ namespace Renci.SshNet
/// </summary>
public class KeyboardInteractiveAuthenticationMethod : AuthenticationMethod
{
<<<<<<< HEAD
private Session _session;
=======
private readonly RequestMessageKeyboardInteractive _requestMessage;
private AuthenticationResult _authenticationResult = AuthenticationResult.Failure;
private Session _session;
private EventWaitHandle _authenticationCompleted = new AutoResetEvent(initialState: false);
>>>>>>> develop
private Exception _exception;
private bool _isDisposed;

Expand Down Expand Up @@ -51,7 +47,6 @@ public KeyboardInteractiveAuthenticationMethod(string username)
: base(username)
{
_requestMessage = new RequestMessageKeyboardInteractive(ServiceName.Connection, username);
_authenticationCompleted = new AutoResetEvent(false);
}

/// <summary>
Expand Down Expand Up @@ -155,23 +150,9 @@ private void Session_UserAuthenticationInformationRequestReceived(object sender,
}
});
}
<<<<<<< HEAD
=======

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}

/// <summary>
/// Releases unmanaged and - optionally - managed resources.
/// </summary>
/// <param name="disposing"><see langword="true"/> to release both managed and unmanaged resources; <see langword="false"/> to release only unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
/// <inheritdoc/>
protected override void Dispose(bool disposing)
{
if (_isDisposed)
{
Expand All @@ -189,7 +170,8 @@ protected virtual void Dispose(bool disposing)

_isDisposed = true;
}

base.Dispose(disposing);
}
>>>>>>> develop
}
}
7 changes: 2 additions & 5 deletions src/Renci.SshNet/KeyboardInteractiveConnectionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,9 @@ protected virtual void Dispose(bool disposing)
{
if (AuthenticationMethods != null)
{
foreach (var authenticationMethods in AuthenticationMethods)
foreach (var authenticationMethod in AuthenticationMethods)
{
if (authenticationMethods is IDisposable disposable)
{
disposable.Dispose();
}
authenticationMethod.Dispose();
}
}

Expand Down
27 changes: 4 additions & 23 deletions src/Renci.SshNet/NoneAuthenticationMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,12 @@ namespace Renci.SshNet
/// </summary>
public class NoneAuthenticationMethod : AuthenticationMethod
{
<<<<<<< HEAD
/// <summary>
/// Gets connection name
=======
private AuthenticationResult _authenticationResult = AuthenticationResult.Failure;
private EventWaitHandle _authenticationCompleted = new AutoResetEvent(initialState: false);
private bool _isDisposed;

/// <summary>
/// Gets the name of the authentication method.
>>>>>>> develop
/// </summary>
public override string Name
{
Expand All @@ -37,7 +32,6 @@ public override string Name
public NoneAuthenticationMethod(string username)
: base(username)
{
_authenticationCompleted = new AutoResetEvent(false);
}

/// <summary>
Expand Down Expand Up @@ -92,23 +86,9 @@ private void Session_UserAuthenticationFailureReceived(object sender, MessageEve

_ = _authenticationCompleted.Set();
}
<<<<<<< HEAD
=======

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}

/// <summary>
/// Releases unmanaged and - optionally - managed resources.
/// </summary>
/// <param name="disposing"><see langword="true"/> to release both managed and unmanaged resources; <see langword="false"/> to release only unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
/// <inheritdoc/>
protected override void Dispose(bool disposing)
{
if (_isDisposed)
{
Expand All @@ -126,7 +106,8 @@ protected virtual void Dispose(bool disposing)

_isDisposed = true;
}

base.Dispose(disposing);
}
>>>>>>> develop
}
}
27 changes: 4 additions & 23 deletions src/Renci.SshNet/PasswordAuthenticationMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@ namespace Renci.SshNet
/// </summary>
public class PasswordAuthenticationMethod : AuthenticationMethod
{
<<<<<<< HEAD
private Session _session;
=======
private readonly RequestMessagePassword _requestMessage;
private readonly byte[] _password;
private AuthenticationResult _authenticationResult = AuthenticationResult.Failure;
private Session _session;
private EventWaitHandle _authenticationCompleted = new AutoResetEvent(initialState: false);
>>>>>>> develop
private Exception _exception;
private bool _isDisposed;

Expand Down Expand Up @@ -61,7 +57,6 @@ internal byte[] Password
public PasswordAuthenticationMethod(string username, string password)
: this(username, Encoding.UTF8.GetBytes(password))
{
_authenticationCompleted = new AutoResetEvent(false);
}

/// <summary>
Expand All @@ -78,7 +73,6 @@ public PasswordAuthenticationMethod(string username, byte[] password)

_password = password;
_requestMessage = new RequestMessagePassword(ServiceName.Connection, Username, _password);
_authenticationCompleted = new AutoResetEvent(false);
}

/// <summary>
Expand Down Expand Up @@ -168,23 +162,9 @@ private void Session_UserAuthenticationPasswordChangeRequiredReceived(object sen
}
});
}
<<<<<<< HEAD
=======

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}

/// <summary>
/// Releases unmanaged and - optionally - managed resources.
/// </summary>
/// <param name="disposing"><see langword="true"/> to release both managed and unmanaged resources; <see langword="false"/> to release only unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
/// <inheritdoc/>
protected override void Dispose(bool disposing)
{
if (_isDisposed)
{
Expand All @@ -202,7 +182,8 @@ protected virtual void Dispose(bool disposing)

_isDisposed = true;
}

base.Dispose(disposing);
}
>>>>>>> develop
}
}
5 changes: 1 addition & 4 deletions src/Renci.SshNet/PasswordConnectionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,7 @@ protected virtual void Dispose(bool disposing)
{
foreach (var authenticationMethod in AuthenticationMethods)
{
if (authenticationMethod is IDisposable disposable)
{
disposable.Dispose();
}
authenticationMethod.Dispose();
}
}

Expand Down
31 changes: 4 additions & 27 deletions src/Renci.SshNet/PrivateKeyAuthenticationMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@ namespace Renci.SshNet
/// </summary>
public class PrivateKeyAuthenticationMethod : AuthenticationMethod
{
<<<<<<< HEAD
private bool _isSignatureRequired;
=======
private AuthenticationResult _authenticationResult = AuthenticationResult.Failure;
private EventWaitHandle _authenticationCompleted = new ManualResetEvent(initialState: false);
private bool _isSignatureRequired;
private bool _isDisposed;
>>>>>>> develop

/// <summary>
/// Gets the name of the authentication method.
Expand All @@ -48,12 +44,7 @@ public PrivateKeyAuthenticationMethod(string username, params IPrivateKeySource[
{
ThrowHelper.ThrowIfNull(keyFiles);

<<<<<<< HEAD
KeyFiles = new Collection<PrivateKeyFile>(keyFiles);
_authenticationCompleted = new ManualResetEvent(false);
=======
KeyFiles = new Collection<IPrivateKeySource>(keyFiles);
>>>>>>> develop
}

/// <summary>
Expand Down Expand Up @@ -164,23 +155,8 @@ private void Session_UserAuthenticationPublicKeyReceived(object sender, MessageE
_ = _authenticationCompleted.Set();
}

<<<<<<< HEAD
private class SignatureData : SshData
=======
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}

/// <summary>
/// Releases unmanaged and - optionally - managed resources.
/// </summary>
/// <param name="disposing"><see langword="true"/> to release both managed and unmanaged resources; <see langword="false"/> to release only unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
/// <inheritdoc/>
protected override void Dispose(bool disposing)
{
if (_isDisposed)
{
Expand All @@ -198,10 +174,11 @@ protected virtual void Dispose(bool disposing)

_isDisposed = true;
}

base.Dispose(disposing);
}

private sealed class SignatureData : SshData
>>>>>>> develop
{
private readonly RequestMessagePublicKey _message;

Expand Down
5 changes: 1 addition & 4 deletions src/Renci.SshNet/PrivateKeyConnectionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,7 @@ protected virtual void Dispose(bool disposing)
{
foreach (var authenticationMethod in AuthenticationMethods)
{
if (authenticationMethod is IDisposable disposable)
{
disposable.Dispose();
}
authenticationMethod.Dispose();
}
}

Expand Down

0 comments on commit 7efd655

Please sign in to comment.