Skip to content

Commit 3910658

Browse files
authored
Enable nullable in ConnectionInfo (#1728)
1 parent 4e02502 commit 3910658

File tree

7 files changed

+76
-66
lines changed

7 files changed

+76
-66
lines changed

src/Renci.SshNet/ConnectionInfo.cs

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
#nullable enable
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Net;
@@ -79,7 +80,7 @@ public class ConnectionInfo : IConnectionInfoInternal
7980
/// <summary>
8081
/// Gets supported compression algorithms for this connection.
8182
/// </summary>
82-
public IOrderedDictionary<string, Func<Compressor>> CompressionAlgorithms { get; }
83+
public IOrderedDictionary<string, Func<Compressor>?> CompressionAlgorithms { get; }
8384

8485
/// <summary>
8586
/// Gets the supported channel requests for this connection.
@@ -129,7 +130,7 @@ public class ConnectionInfo : IConnectionInfoInternal
129130
/// <summary>
130131
/// Gets proxy connection host.
131132
/// </summary>
132-
public string ProxyHost { get; }
133+
public string? ProxyHost { get; }
133134

134135
/// <summary>
135136
/// Gets proxy connection port.
@@ -139,12 +140,12 @@ public class ConnectionInfo : IConnectionInfoInternal
139140
/// <summary>
140141
/// Gets proxy connection username.
141142
/// </summary>
142-
public string ProxyUsername { get; }
143+
public string? ProxyUsername { get; }
143144

144145
/// <summary>
145146
/// Gets proxy connection password.
146147
/// </summary>
147-
public string ProxyPassword { get; }
148+
public string? ProxyPassword { get; }
148149

149150
/// <summary>
150151
/// Gets or sets connection timeout.
@@ -219,57 +220,63 @@ public TimeSpan ChannelCloseTimeout
219220
/// <summary>
220221
/// Occurs when authentication banner is sent by the server.
221222
/// </summary>
222-
public event EventHandler<AuthenticationBannerEventArgs> AuthenticationBanner;
223+
public event EventHandler<AuthenticationBannerEventArgs>? AuthenticationBanner;
223224

224225
/// <summary>
225226
/// Gets the current key exchange algorithm.
226227
/// </summary>
227-
public string CurrentKeyExchangeAlgorithm { get; internal set; }
228+
public string? CurrentKeyExchangeAlgorithm { get; internal set; }
228229

229230
/// <summary>
230231
/// Gets the current server encryption.
231232
/// </summary>
232-
public string CurrentServerEncryption { get; internal set; }
233+
public string? CurrentServerEncryption { get; internal set; }
233234

234235
/// <summary>
235236
/// Gets the current client encryption.
236237
/// </summary>
237-
public string CurrentClientEncryption { get; internal set; }
238+
public string? CurrentClientEncryption { get; internal set; }
238239

239240
/// <summary>
240241
/// Gets the current server hash algorithm.
241242
/// </summary>
242-
public string CurrentServerHmacAlgorithm { get; internal set; }
243+
public string? CurrentServerHmacAlgorithm { get; internal set; }
243244

244245
/// <summary>
245246
/// Gets the current client hash algorithm.
246247
/// </summary>
247-
public string CurrentClientHmacAlgorithm { get; internal set; }
248+
public string? CurrentClientHmacAlgorithm { get; internal set; }
248249

249250
/// <summary>
250251
/// Gets the current host key algorithm.
251252
/// </summary>
252-
public string CurrentHostKeyAlgorithm { get; internal set; }
253+
public string? CurrentHostKeyAlgorithm { get; internal set; }
253254

254255
/// <summary>
255256
/// Gets the current server compression algorithm.
256257
/// </summary>
257-
public string CurrentServerCompressionAlgorithm { get; internal set; }
258+
public string? CurrentServerCompressionAlgorithm { get; internal set; }
258259

259260
/// <summary>
260-
/// Gets the server version.
261+
/// Gets the current client compression algorithm.
261262
/// </summary>
262-
public string ServerVersion { get; internal set; }
263+
public string? CurrentClientCompressionAlgorithm { get; internal set; }
263264

264265
/// <summary>
265-
/// Gets the client version.
266+
/// Gets the server version.
266267
/// </summary>
267-
public string ClientVersion { get; internal set; }
268+
public string? ServerVersion { get; internal set; }
268269

269270
/// <summary>
270-
/// Gets the current client compression algorithm.
271+
/// Gets the client version.
271272
/// </summary>
272-
public string CurrentClientCompressionAlgorithm { get; internal set; }
273+
public string ClientVersion
274+
{
275+
get
276+
{
277+
return Session.ClientVersionString;
278+
}
279+
}
273280

274281
/// <summary>
275282
/// Initializes a new instance of the <see cref="ConnectionInfo"/> class.
@@ -323,7 +330,7 @@ public ConnectionInfo(string host, int port, string username, params Authenticat
323330
/// <exception cref="ArgumentOutOfRangeException"><paramref name="proxyType"/> is not <see cref="ProxyTypes.None"/> and <paramref name="proxyPort" /> is not within <see cref="IPEndPoint.MinPort" /> and <see cref="IPEndPoint.MaxPort" />.</exception>
324331
/// <exception cref="ArgumentNullException"><paramref name="authenticationMethods"/> is <see langword="null"/>.</exception>
325332
/// <exception cref="ArgumentException">No <paramref name="authenticationMethods"/> specified.</exception>
326-
public ConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword, params AuthenticationMethod[] authenticationMethods)
333+
public ConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string? proxyHost, int proxyPort, string? proxyUsername, string? proxyPassword, params AuthenticationMethod[] authenticationMethods)
327334
{
328335
ArgumentNullException.ThrowIfNull(host);
329336
port.ValidatePort();
@@ -413,7 +420,7 @@ public ConnectionInfo(string host, int port, string username, ProxyTypes proxyTy
413420
#pragma warning restore SA1107 // Code should not contain multiple statements on one line
414421
HostKeyAlgorithms = hostAlgs;
415422

416-
CompressionAlgorithms = new OrderedDictionary<string, Func<Compressor>>
423+
CompressionAlgorithms = new OrderedDictionary<string, Func<Compressor>?>
417424
{
418425
{ "none", null },
419426
{ "[email protected]", () => new ZlibOpenSsh() },
@@ -472,7 +479,7 @@ internal void Authenticate(ISession session, IServiceFactory serviceFactory)
472479
/// </summary>
473480
/// <param name="sender">The session in which the banner message was received.</param>
474481
/// <param name="e">The banner message.</param>
475-
void IConnectionInfoInternal.UserAuthenticationBannerReceived(object sender, MessageEventArgs<BannerMessage> e)
482+
void IConnectionInfoInternal.UserAuthenticationBannerReceived(object? sender, MessageEventArgs<BannerMessage> e)
476483
{
477484
AuthenticationBanner?.Invoke(this, new AuthenticationBannerEventArgs(Username, e.Message.Message, e.Message.Language));
478485
}
@@ -507,6 +514,6 @@ IList<IAuthenticationMethod> IConnectionInfoInternal.AuthenticationMethods
507514
/// <value>
508515
/// The logger factory for this connection. If <see langword="null"/> then <see cref="SshNetLoggingConfiguration.LoggerFactory"/> is used.
509516
/// </value>
510-
public ILoggerFactory LoggerFactory { get; set; }
517+
public ILoggerFactory? LoggerFactory { get; set; }
511518
}
512519
}

src/Renci.SshNet/IConnectionInfo.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
#nullable enable
2+
using System;
23
using System.Collections.Generic;
34
using System.Text;
45

@@ -20,7 +21,7 @@ internal interface IConnectionInfo
2021
/// <value>
2122
/// The logger factory for this connection. If <see langword="null"/> then <see cref="SshNetLoggingConfiguration.LoggerFactory"/> is used.
2223
/// </value>
23-
public ILoggerFactory LoggerFactory { get; }
24+
public ILoggerFactory? LoggerFactory { get; }
2425

2526
/// <summary>
2627
/// Gets the timeout to used when waiting for a server to acknowledge closing a channel.
@@ -77,7 +78,7 @@ internal interface IConnectionInfo
7778
/// <summary>
7879
/// Gets proxy connection host.
7980
/// </summary>
80-
string ProxyHost { get; }
81+
string? ProxyHost { get; }
8182

8283
/// <summary>
8384
/// Gets proxy connection port.
@@ -87,12 +88,12 @@ internal interface IConnectionInfo
8788
/// <summary>
8889
/// Gets proxy connection username.
8990
/// </summary>
90-
string ProxyUsername { get; }
91+
string? ProxyUsername { get; }
9192

9293
/// <summary>
9394
/// Gets proxy connection password.
9495
/// </summary>
95-
string ProxyPassword { get; }
96+
string? ProxyPassword { get; }
9697

9798
/// <summary>
9899
/// Gets the number of retry attempts when session channel creation failed.
@@ -113,6 +114,6 @@ internal interface IConnectionInfo
113114
/// <summary>
114115
/// Occurs when authentication banner is sent by the server.
115116
/// </summary>
116-
event EventHandler<AuthenticationBannerEventArgs> AuthenticationBanner;
117+
event EventHandler<AuthenticationBannerEventArgs>? AuthenticationBanner;
117118
}
118119
}

src/Renci.SshNet/IConnectionInfoInternal.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
#nullable enable
2+
using System.Collections.Generic;
23

34
using Renci.SshNet.Messages.Authentication;
45

@@ -14,7 +15,7 @@ internal interface IConnectionInfoInternal : IConnectionInfo
1415
/// </summary>
1516
/// <param name="sender">The session in which the banner message was received.</param>
1617
/// <param name="e">The banner message.</param>
17-
void UserAuthenticationBannerReceived(object sender, MessageEventArgs<BannerMessage> e);
18+
void UserAuthenticationBannerReceived(object? sender, MessageEventArgs<BannerMessage> e);
1819

1920
/// <summary>
2021
/// Gets the supported authentication methods for this connection.

src/Renci.SshNet/KeyboardInteractiveConnectionInfo.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
#nullable enable
2+
using System;
23

34
using Renci.SshNet.Common;
45

@@ -14,7 +15,7 @@ public class KeyboardInteractiveConnectionInfo : ConnectionInfo, IDisposable
1415
/// <summary>
1516
/// Occurs when server prompts for more authentication information.
1617
/// </summary>
17-
public event EventHandler<AuthenticationPromptEventArgs> AuthenticationPrompt;
18+
public event EventHandler<AuthenticationPromptEventArgs>? AuthenticationPrompt;
1819

1920
/// <summary>
2021
/// Initializes a new instance of the <see cref="KeyboardInteractiveConnectionInfo"/> class.
@@ -46,7 +47,7 @@ public KeyboardInteractiveConnectionInfo(string host, int port, string username)
4647
/// <param name="proxyType">Type of the proxy.</param>
4748
/// <param name="proxyHost">The proxy host.</param>
4849
/// <param name="proxyPort">The proxy port.</param>
49-
public KeyboardInteractiveConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort)
50+
public KeyboardInteractiveConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string? proxyHost, int proxyPort)
5051
: this(host, port, username, proxyType, proxyHost, proxyPort, string.Empty, string.Empty)
5152
{
5253
}
@@ -61,7 +62,7 @@ public KeyboardInteractiveConnectionInfo(string host, int port, string username,
6162
/// <param name="proxyHost">The proxy host.</param>
6263
/// <param name="proxyPort">The proxy port.</param>
6364
/// <param name="proxyUsername">The proxy username.</param>
64-
public KeyboardInteractiveConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername)
65+
public KeyboardInteractiveConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string? proxyHost, int proxyPort, string? proxyUsername)
6566
: this(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, string.Empty)
6667
{
6768
}
@@ -74,7 +75,7 @@ public KeyboardInteractiveConnectionInfo(string host, int port, string username,
7475
/// <param name="proxyType">Type of the proxy.</param>
7576
/// <param name="proxyHost">The proxy host.</param>
7677
/// <param name="proxyPort">The proxy port.</param>
77-
public KeyboardInteractiveConnectionInfo(string host, string username, ProxyTypes proxyType, string proxyHost, int proxyPort)
78+
public KeyboardInteractiveConnectionInfo(string host, string username, ProxyTypes proxyType, string? proxyHost, int proxyPort)
7879
: this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, string.Empty, string.Empty)
7980
{
8081
}
@@ -88,7 +89,7 @@ public KeyboardInteractiveConnectionInfo(string host, string username, ProxyType
8889
/// <param name="proxyHost">The proxy host.</param>
8990
/// <param name="proxyPort">The proxy port.</param>
9091
/// <param name="proxyUsername">The proxy username.</param>
91-
public KeyboardInteractiveConnectionInfo(string host, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername)
92+
public KeyboardInteractiveConnectionInfo(string host, string username, ProxyTypes proxyType, string? proxyHost, int proxyPort, string? proxyUsername)
9293
: this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, proxyUsername, string.Empty)
9394
{
9495
}
@@ -103,7 +104,7 @@ public KeyboardInteractiveConnectionInfo(string host, string username, ProxyType
103104
/// <param name="proxyPort">The proxy port.</param>
104105
/// <param name="proxyUsername">The proxy username.</param>
105106
/// <param name="proxyPassword">The proxy password.</param>
106-
public KeyboardInteractiveConnectionInfo(string host, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword)
107+
public KeyboardInteractiveConnectionInfo(string host, string username, ProxyTypes proxyType, string? proxyHost, int proxyPort, string? proxyUsername, string? proxyPassword)
107108
: this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword)
108109
{
109110
}
@@ -119,7 +120,7 @@ public KeyboardInteractiveConnectionInfo(string host, string username, ProxyType
119120
/// <param name="proxyPort">The proxy port.</param>
120121
/// <param name="proxyUsername">The proxy username.</param>
121122
/// <param name="proxyPassword">The proxy password.</param>
122-
public KeyboardInteractiveConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword)
123+
public KeyboardInteractiveConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string? proxyHost, int proxyPort, string? proxyUsername, string? proxyPassword)
123124
: base(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, new KeyboardInteractiveAuthenticationMethod(username))
124125
{
125126
foreach (var authenticationMethod in AuthenticationMethods)
@@ -131,7 +132,7 @@ public KeyboardInteractiveConnectionInfo(string host, int port, string username,
131132
}
132133
}
133134

134-
private void AuthenticationMethod_AuthenticationPrompt(object sender, AuthenticationPromptEventArgs e)
135+
private void AuthenticationMethod_AuthenticationPrompt(object? sender, AuthenticationPromptEventArgs e)
135136
{
136137
#pragma warning disable MA0091 // Sender should be 'this' for instance events
137138
AuthenticationPrompt?.Invoke(sender, e);

0 commit comments

Comments
 (0)