using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace Renci.SshNet
{
///
/// Provides connection information when private key authentication method is used.
///
///
///
///
public class PrivateKeyConnectionInfo : ConnectionInfo, IDisposable
{
private bool _isDisposed;
///
/// Gets the key files used for authentication.
///
public ICollection KeyFiles { get; private set; }
///
/// Initializes a new instance of the class.
///
/// Connection host.
/// Connection username.
/// Connection key files.
///
///
///
///
public PrivateKeyConnectionInfo(string host, string username, params PrivateKeyFile[] keyFiles)
: this(host, DefaultPort, username, ProxyTypes.None, string.Empty, 0, string.Empty, string.Empty, keyFiles)
{
}
///
/// Initializes a new instance of the class.
///
/// Connection host.
/// Connection port.
/// Connection username.
/// Connection key files.
public PrivateKeyConnectionInfo(string host, int port, string username, params IPrivateKeySource[] keyFiles)
: this(host, port, username, ProxyTypes.None, string.Empty, 0, string.Empty, string.Empty, keyFiles)
{
}
///
/// Initializes a new instance of the class.
///
/// Connection host.
/// The port.
/// Connection username.
/// Type of the proxy.
/// The proxy host.
/// The proxy port.
/// The key files.
public PrivateKeyConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, params IPrivateKeySource[] keyFiles)
: this(host, port, username, proxyType, proxyHost, proxyPort, string.Empty, string.Empty, keyFiles)
{
}
///
/// Initializes a new instance of the class.
///
/// Connection host.
/// The port.
/// Connection username.
/// Type of the proxy.
/// The proxy host.
/// The proxy port.
/// The proxy username.
/// The key files.
public PrivateKeyConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, params IPrivateKeySource[] keyFiles)
: this(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, string.Empty, keyFiles)
{
}
///
/// Initializes a new instance of the class.
///
/// Connection host.
/// Connection username.
/// Type of the proxy.
/// The proxy host.
/// The proxy port.
/// The key files.
public PrivateKeyConnectionInfo(string host, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, params IPrivateKeySource[] keyFiles)
: this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, string.Empty, string.Empty, keyFiles)
{
}
///
/// Initializes a new instance of the class.
///
/// Connection host.
/// Connection username.
/// Type of the proxy.
/// The proxy host.
/// The proxy port.
/// The proxy username.
/// The key files.
public PrivateKeyConnectionInfo(string host, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, params IPrivateKeySource[] keyFiles)
: this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, proxyUsername, string.Empty, keyFiles)
{
}
///
/// Initializes a new instance of the class.
///
/// Connection host.
/// Connection username.
/// Type of the proxy.
/// The proxy host.
/// The proxy port.
/// The proxy username.
/// The proxy password.
/// The key files.
public PrivateKeyConnectionInfo(string host, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword, params IPrivateKeySource[] keyFiles)
: this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, keyFiles)
{
}
///
/// Initializes a new instance of the class.
///
/// Connection host.
/// The port.
/// Connection username.
/// Type of the proxy.
/// The proxy host.
/// The proxy port.
/// The proxy username.
/// The proxy password.
/// The key files.
public PrivateKeyConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword, params IPrivateKeySource[] keyFiles)
: base(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, new PrivateKeyAuthenticationMethod(username, keyFiles))
{
KeyFiles = new Collection(keyFiles);
}
///
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
///
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
///
/// Releases unmanaged and - optionally - managed resources.
///
/// true to release both managed and unmanaged resources; false to release only unmanaged resources.
protected virtual void Dispose(bool disposing)
{
if (_isDisposed)
{
return;
}
if (disposing)
{
// Dispose managed resources.
if (AuthenticationMethods != null)
{
foreach (var authenticationMethod in AuthenticationMethods)
{
if (authenticationMethod is IDisposable disposable)
{
disposable.Dispose();
}
}
}
_isDisposed = true;
}
}
///
/// Finalizes an instance of the class.
///
~PrivateKeyConnectionInfo()
{
Dispose(disposing: false);
}
}
}