cleanup + fix tests for net8

This commit is contained in:
Stef Heyenrath
2025-08-31 11:39:03 +02:00
parent bb561c94d0
commit b111b019bc
20 changed files with 93 additions and 294 deletions

View File

@@ -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
}
}
}