Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions Kerberos.NET/Crypto/Pal/CryptoPal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,7 +23,7 @@ public abstract class CryptoPal
public static CryptoPal Platform => lazyPlatform.Value;

private static readonly Lazy<CryptoPal> lazyPlatform
= new Lazy<CryptoPal>(() => CreatePal());
= new(() => CreatePal());

private static Func<CryptoPal> injectedPal;

Expand All @@ -27,6 +32,10 @@ public static void RegisterPal(Func<CryptoPal> palFunc)
injectedPal = palFunc ?? throw new InvalidOperationException("Cannot register a null PAL");
}

protected virtual void PlatformCheck()
{
}

private static CryptoPal CreatePal()
{
var injected = injectedPal;
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Kerberos.NET/Crypto/Pal/Linux/LinuxCryptoPal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Kerberos.NET.Crypto
{
public class LinuxCryptoPal : CryptoPal
{
public LinuxCryptoPal()
protected override void PlatformCheck()
{
if (!IsLinux)
{
Expand Down
2 changes: 1 addition & 1 deletion Kerberos.NET/Crypto/Pal/OSX/OSXCryptoPal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Kerberos.NET.Crypto
{
public class OSXCryptoPal : LinuxCryptoPal
{
public OSXCryptoPal()
protected override void PlatformCheck()
{
if (!IsOsX)
{
Expand Down
2 changes: 1 addition & 1 deletion Kerberos.NET/Crypto/Pal/Windows/WindowsCryptoPal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Kerberos.NET.Crypto
{
public class WindowsCryptoPal : CryptoPal
{
public WindowsCryptoPal()
protected override void PlatformCheck()
{
if (!IsWindows)
{
Expand Down
Loading