mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-27 10:47:01 +02:00
cleanup + fix tests for net8
This commit is contained in:
@@ -43,11 +43,11 @@ internal static class CertificateLoader
|
||||
}
|
||||
finally
|
||||
{
|
||||
#if NETSTANDARD || NET46
|
||||
//#if NETSTANDARD || NET48
|
||||
certStore.Dispose();
|
||||
#else
|
||||
//#else
|
||||
certStore.Close();
|
||||
#endif
|
||||
//#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ internal static class CertificateLoader
|
||||
if (options.X509CertificateFilePath.EndsWith(ExtensionPem, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// PEM logic based on: https://www.scottbrady91.com/c-sharp/pem-loading-in-dotnet-core-and-dotnet
|
||||
#if NET5_0_OR_GREATER
|
||||
#if NET8_0_OR_GREATER
|
||||
if (!string.IsNullOrEmpty(options.X509CertificatePassword))
|
||||
{
|
||||
var certPem = File.ReadAllText(options.X509CertificateFilePath);
|
||||
@@ -66,18 +66,8 @@ internal static class CertificateLoader
|
||||
return new X509Certificate2(cert.Export(X509ContentType.Pfx, defaultPasswordPem), defaultPasswordPem);
|
||||
}
|
||||
return X509Certificate2.CreateFromPemFile(options.X509CertificateFilePath);
|
||||
|
||||
#elif NETCOREAPP3_1
|
||||
var cert = new X509Certificate2(options.X509CertificateFilePath);
|
||||
if (!string.IsNullOrEmpty(options.X509CertificatePassword))
|
||||
{
|
||||
var key = System.Security.Cryptography.ECDsa.Create()!;
|
||||
key.ImportECPrivateKey(System.Text.Encoding.UTF8.GetBytes(options.X509CertificatePassword), out _);
|
||||
return cert.CopyWithPrivateKey(key);
|
||||
}
|
||||
return cert;
|
||||
#else
|
||||
throw new InvalidOperationException("Loading a PEM Certificate is only supported for .NET Core App 3.1, .NET 5.0 and higher.");
|
||||
throw new InvalidOperationException("Loading a PEM Certificate is only supported for .NET 8.0 and higher.");
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -123,11 +113,11 @@ internal static class CertificateLoader
|
||||
}
|
||||
finally
|
||||
{
|
||||
#if NETSTANDARD || NET46
|
||||
//#if NETSTANDARD || NET46
|
||||
certStore.Dispose();
|
||||
#else
|
||||
//#else
|
||||
certStore.Close();
|
||||
#endif
|
||||
//#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user