Add more checks for NET5_0

This commit is contained in:
SilverFox
2021-04-02 18:03:44 +08:00
parent fbb5cd45a0
commit e174546b5a
7 changed files with 9 additions and 21 deletions
@@ -291,7 +291,7 @@ namespace MQTTnet.Client.Options
#pragma warning disable CS0618 // Type or member is obsolete
CertificateValidationCallback = _tlsParameters.CertificateValidationCallback,
#pragma warning restore CS0618 // Type or member is obsolete
#if NETCOREAPP3_1
#if NETCOREAPP3_1 || NET5_0
ApplicationProtocols = _tlsParameters.ApplicationProtocols,
#endif
CertificateValidationHandler = _tlsParameters.CertificateValidationHandler,
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Net.Security;
using System.Security.Authentication;
@@ -31,9 +31,9 @@ namespace MQTTnet.Client.Options
public IEnumerable<X509Certificate> Certificates { get; set; }
#endif
#if NETCOREAPP3_1
#if NETCOREAPP3_1 || NET5_0
public List<SslApplicationProtocol> ApplicationProtocols { get;set; }
#endif
#endif
public bool AllowUntrustedCertificates { get; set; }
@@ -22,7 +22,7 @@ namespace MQTTnet.Client.Options
public List<X509Certificate> Certificates { get; set; }
#endif
#if NETCOREAPP3_1
#if NETCOREAPP3_1 || NET5_0
public List<SslApplicationProtocol> ApplicationProtocols { get; set; }
#endif
@@ -75,23 +75,11 @@ namespace MQTTnet.Implementations
_socket.Control.IgnorableServerCertificateErrors.Add(ignorableChainValidationResult);
}
#if NETCOREAPP3_1 || NET5_0
var socketProtectionLevel = SocketProtectionLevel.Tls13;
if (_options.TlsOptions.SslProtocol == SslProtocols.Tls12)
{
socketProtectionLevel = SocketProtectionLevel.Tls12;
}
else if (_options.TlsOptions.SslProtocol == SslProtocols.Tls11)
{
socketProtectionLevel = SocketProtectionLevel.Tls11;
}
#else
var socketProtectionLevel = SocketProtectionLevel.Tls12;
if (_options.TlsOptions.SslProtocol == SslProtocols.Tls11)
{
socketProtectionLevel = SocketProtectionLevel.Tls11;
}
#endif
else if (_options.TlsOptions.SslProtocol == SslProtocols.Tls)
{
socketProtectionLevel = SocketProtectionLevel.Tls10;
@@ -83,7 +83,7 @@ namespace MQTTnet.Implementations
var sslStream = new SslStream(networkStream, false, InternalUserCertificateValidationCallback);
try
{
#if NETCOREAPP3_1
#if NETCOREAPP3_1 || NET5_0
var sslOptions = new SslClientAuthenticationOptions
{
ApplicationProtocols = _tcpOptions.TlsOptions.ApplicationProtocols,
@@ -100,7 +100,7 @@ namespace MQTTnet.Implementations
}
catch
{
#if NETSTANDARD2_1 || NETCOREAPP3_1
#if NETSTANDARD2_1 || NETCOREAPP3_1 || NET5_0
await sslStream.DisposeAsync().ConfigureAwait(false);
#else
sslStream.Dispose();
@@ -98,7 +98,7 @@ namespace MQTTnet.Implementations
{
_socket?.Dispose();
#if NETSTANDARD1_3 || NETSTANDARD2_0 || NET461 || NET472
#if !NET452
_tlsCertificate?.Dispose();
#endif
}
@@ -17,7 +17,7 @@ namespace MQTTnet.Implementations
public static void Sleep(TimeSpan timeout)
{
#if NET452 || NETSTANDARD2_0 || NETSTANDARD2_1 || NETCOREAPP3_1
#if !NETSTANDARD1_3
System.Threading.Thread.Sleep(timeout);
#else
Task.Delay(timeout).Wait();