Skip to content

Commit

Permalink
refactor: Remove unnecessary preprocessor directives (target is alway…
Browse files Browse the repository at this point in the history
…s >= netstandard2.0)
  • Loading branch information
HofmeisterAn committed Jul 22, 2022
1 parent ed48af6 commit e3ab167
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 73 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ The `CertFile` in the example above should be a .pfx file (PKCS12 format), if yo
//
// You can do this globally for all certificates:
// (Note: This is not available on netstandard1.6)
ServicePointManager.ServerCertificateValidationCallback += (o, c, ch, er) => true;

// Or you can do this on a credential by credential basis:
Expand Down
4 changes: 0 additions & 4 deletions src/Docker.DotNet.BasicAuth/BasicAuthCredentials.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Net.Http;
#if !NETSTANDARD1_6
using System.Security;
#endif

namespace Docker.DotNet.BasicAuth
{
Expand All @@ -17,12 +15,10 @@ public override HttpMessageHandler GetHandler(HttpMessageHandler innerHandler)
return new BasicAuthHandler(_username, _password, innerHandler);
}

#if !NETSTANDARD1_6
public BasicAuthCredentials(SecureString username, SecureString password, bool isTls = false)
: this(new MaybeSecureString(username), new MaybeSecureString(password), isTls)
{
}
#endif

public BasicAuthCredentials(string username, string password, bool isTls = false)
: this(new MaybeSecureString(username), new MaybeSecureString(password), isTls)
Expand Down
33 changes: 0 additions & 33 deletions src/Docker.DotNet.BasicAuth/MaybeSecureString.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
using System;
#if !NETSTANDARD1_6
using System.Security;
using System.Runtime.InteropServices;
#endif

namespace Docker.DotNet.BasicAuth
{
internal class MaybeSecureString : IDisposable
{
#if !NETSTANDARD1_6

public SecureString Value { get; }

public MaybeSecureString(string str)
Expand Down Expand Up @@ -66,34 +62,5 @@ public override string ToString()
Marshal.ZeroFreeGlobalAllocUnicode(unmanagedString);
}
}

#else

public string Value { get; }

public MaybeSecureString(string str)
{
if (string.IsNullOrEmpty(str))
{
throw new ArgumentNullException(nameof(str));
}

Value = str;
}

public void Dispose()
{
}

public MaybeSecureString Copy()
{
return this;
}

public override string ToString()
{
return Value;
}
#endif
}
}
8 changes: 2 additions & 6 deletions src/Docker.DotNet.X509/CertificateCredentials.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#if !NETSTANDARD1_6
using System.Net;
#endif

using System.Net;
using System.Net.Http;
using System.Security.Cryptography.X509Certificates;
using Microsoft.Net.Http.Client;
Expand Down Expand Up @@ -29,12 +26,11 @@ public override HttpMessageHandler GetHandler(HttpMessageHandler innerHandler)
};

handler.ServerCertificateValidationCallback = this.ServerCertificateValidationCallback;
#if !NETSTANDARD1_6

if (handler.ServerCertificateValidationCallback == null)
{
handler.ServerCertificateValidationCallback = ServicePointManager.ServerCertificateValidationCallback;
}
#endif

return handler;
}
Expand Down
5 changes: 0 additions & 5 deletions src/Docker.DotNet.X509/RSAUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
using System.Text;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

#if !NETSTANDARD1_6
using System.Security;
#endif

namespace Docker.DotNet.X509
{
Expand All @@ -19,7 +16,6 @@ public static X509Certificate2 GetCertFromPFX(string pfxFilePath, string passwor
return new X509Certificate2(pfxFilePath, password);
}

#if !NETSTANDARD1_6
public static X509Certificate2 GetCertFromPFXSecure(string pfxFilePath, SecureString password)
{
return new X509Certificate2(pfxFilePath, password);
Expand All @@ -31,7 +27,6 @@ public static X509Certificate2 GetCertFromPEMFiles(string certFilePath, string k
cert.PrivateKey = RSAUtil.ReadFromPemFile(keyFilePath);
return cert;
}
#endif

private static RSACryptoServiceProvider ReadFromPemFile(string pemFilePath)
{
Expand Down
10 changes: 2 additions & 8 deletions src/Docker.DotNet/DockerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Net.Http.Client;

#if (NETSTANDARD1_6 || NETSTANDARD2_0)
using System.Net.Sockets;
#endif

namespace Docker.DotNet
{
public sealed class DockerClient : IDockerClient
Expand Down Expand Up @@ -100,19 +97,16 @@ internal DockerClient(DockerClientConfiguration configuration, Version requested
case "https":
handler = new ManagedHandler();
break;

#if (NETSTANDARD1_6 || NETSTANDARD2_0)
case "unix":
var pipeString = uri.LocalPath;
handler = new ManagedHandler(async (string host, int port, CancellationToken cancellationToken) =>
{
var sock = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
await sock.ConnectAsync(new UnixDomainSocketEndPoint(pipeString));
await sock.ConnectAsync(new Microsoft.Net.Http.Client.UnixDomainSocketEndPoint(pipeString));
return sock;
});
uri = new UriBuilder("http", uri.Segments.Last()).Uri;
break;
#endif

default:
throw new Exception($"Unknown URL scheme {configuration.EndpointBaseUri.Scheme}");
Expand Down
9 changes: 0 additions & 9 deletions src/Docker.DotNet/Microsoft.Net.Http.Client/ManagedHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,7 @@ private static async Task<Socket> TCPSocketOpenerAsync(string host, int port, Ca
var s = new Socket(address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
try
{
#if (NETSTANDARD1_3 || NETSTANDARD1_6 || NETSTANDARD2_0)
await s.ConnectAsync(address, port).ConfigureAwait(false);
#else
await Task.Factory.FromAsync(
s.BeginConnect,
s.EndConnect,
new IPEndPoint(address, port),
null
).ConfigureAwait(false);
#endif
connectedSocket = s;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE-MIT.txt file for more information.

#if (NETSTANDARD1_6 || NETSTANDARD2_0)

using System;
using System.Diagnostics;
using System.Text;
Expand Down Expand Up @@ -95,5 +93,3 @@ public override SocketAddress Serialize()
public override string ToString() => _path;
}
}

#endif
3 changes: 0 additions & 3 deletions src/Docker.DotNet/QueryStringParameterAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System;
using System.Linq;
#if (NETSTANDARD1_3 || NETSTANDARD1_6 || NETSTANDARD2_0)
using System.Reflection;
#endif

namespace Docker.DotNet
{
Expand Down

0 comments on commit e3ab167

Please sign in to comment.