From 429e4b3908d981b5e345864d46a61a1bd399a669 Mon Sep 17 00:00:00 2001 From: Steve Syfuhs Date: Thu, 13 Nov 2025 09:21:47 -0800 Subject: [PATCH] Switch to overridable platform check --- Kerberos.NET/Crypto/Pal/CryptoPal.cs | 21 ++++++++++++------- .../Crypto/Pal/Linux/LinuxCryptoPal.cs | 2 +- Kerberos.NET/Crypto/Pal/OSX/OSXCryptoPal.cs | 2 +- .../Crypto/Pal/Windows/WindowsCryptoPal.cs | 2 +- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Kerberos.NET/Crypto/Pal/CryptoPal.cs b/Kerberos.NET/Crypto/Pal/CryptoPal.cs index 235e0f29..3dcfbc57 100644 --- a/Kerberos.NET/Crypto/Pal/CryptoPal.cs +++ b/Kerberos.NET/Crypto/Pal/CryptoPal.cs @@ -9,6 +9,11 @@ namespace Kerberos.NET.Crypto { public abstract class CryptoPal { + protected CryptoPal() + { + this.PlatformCheck(); + } + protected static bool IsWindows => OSPlatform.IsWindows; protected static bool IsLinux => OSPlatform.IsLinux; @@ -18,7 +23,7 @@ public abstract class CryptoPal public static CryptoPal Platform => lazyPlatform.Value; private static readonly Lazy lazyPlatform - = new Lazy(() => CreatePal()); + = new(() => CreatePal()); private static Func injectedPal; @@ -27,6 +32,10 @@ public static void RegisterPal(Func palFunc) injectedPal = palFunc ?? throw new InvalidOperationException("Cannot register a null PAL"); } + protected virtual void PlatformCheck() + { + } + private static CryptoPal CreatePal() { var injected = injectedPal; @@ -40,15 +49,13 @@ private static CryptoPal CreatePal() { return new WindowsCryptoPal(); } - - if (IsLinux) + else if (IsOsX) { - return new LinuxCryptoPal(); + return new OSXCryptoPal(); } - - if (IsOsX) + else if (IsLinux) { - return new OSXCryptoPal(); + return new LinuxCryptoPal(); } throw PlatformNotSupported(); diff --git a/Kerberos.NET/Crypto/Pal/Linux/LinuxCryptoPal.cs b/Kerberos.NET/Crypto/Pal/Linux/LinuxCryptoPal.cs index 29f43a20..3148465f 100644 --- a/Kerberos.NET/Crypto/Pal/Linux/LinuxCryptoPal.cs +++ b/Kerberos.NET/Crypto/Pal/Linux/LinuxCryptoPal.cs @@ -10,7 +10,7 @@ namespace Kerberos.NET.Crypto { public class LinuxCryptoPal : CryptoPal { - public LinuxCryptoPal() + protected override void PlatformCheck() { if (!IsLinux) { diff --git a/Kerberos.NET/Crypto/Pal/OSX/OSXCryptoPal.cs b/Kerberos.NET/Crypto/Pal/OSX/OSXCryptoPal.cs index e02e75e3..ec18850c 100644 --- a/Kerberos.NET/Crypto/Pal/OSX/OSXCryptoPal.cs +++ b/Kerberos.NET/Crypto/Pal/OSX/OSXCryptoPal.cs @@ -7,7 +7,7 @@ namespace Kerberos.NET.Crypto { public class OSXCryptoPal : LinuxCryptoPal { - public OSXCryptoPal() + protected override void PlatformCheck() { if (!IsOsX) { diff --git a/Kerberos.NET/Crypto/Pal/Windows/WindowsCryptoPal.cs b/Kerberos.NET/Crypto/Pal/Windows/WindowsCryptoPal.cs index 32ea414e..2fa7822b 100644 --- a/Kerberos.NET/Crypto/Pal/Windows/WindowsCryptoPal.cs +++ b/Kerberos.NET/Crypto/Pal/Windows/WindowsCryptoPal.cs @@ -10,7 +10,7 @@ namespace Kerberos.NET.Crypto { public class WindowsCryptoPal : CryptoPal { - public WindowsCryptoPal() + protected override void PlatformCheck() { if (!IsWindows) {