Skip to content

Commit 77e10aa

Browse files
authored
Merge pull request #414 from dotnet/bugfix/mac-cryptofix
Switch to overridable platform check
2 parents 9422d22 + 429e4b3 commit 77e10aa

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

Kerberos.NET/Crypto/Pal/CryptoPal.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ namespace Kerberos.NET.Crypto
99
{
1010
public abstract class CryptoPal
1111
{
12+
protected CryptoPal()
13+
{
14+
this.PlatformCheck();
15+
}
16+
1217
protected static bool IsWindows => OSPlatform.IsWindows;
1318

1419
protected static bool IsLinux => OSPlatform.IsLinux;
@@ -18,7 +23,7 @@ public abstract class CryptoPal
1823
public static CryptoPal Platform => lazyPlatform.Value;
1924

2025
private static readonly Lazy<CryptoPal> lazyPlatform
21-
= new Lazy<CryptoPal>(() => CreatePal());
26+
= new(() => CreatePal());
2227

2328
private static Func<CryptoPal> injectedPal;
2429

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

35+
protected virtual void PlatformCheck()
36+
{
37+
}
38+
3039
private static CryptoPal CreatePal()
3140
{
3241
var injected = injectedPal;
@@ -40,15 +49,13 @@ private static CryptoPal CreatePal()
4049
{
4150
return new WindowsCryptoPal();
4251
}
43-
44-
if (IsLinux)
52+
else if (IsOsX)
4553
{
46-
return new LinuxCryptoPal();
54+
return new OSXCryptoPal();
4755
}
48-
49-
if (IsOsX)
56+
else if (IsLinux)
5057
{
51-
return new OSXCryptoPal();
58+
return new LinuxCryptoPal();
5259
}
5360

5461
throw PlatformNotSupported();

Kerberos.NET/Crypto/Pal/Linux/LinuxCryptoPal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Kerberos.NET.Crypto
1010
{
1111
public class LinuxCryptoPal : CryptoPal
1212
{
13-
public LinuxCryptoPal()
13+
protected override void PlatformCheck()
1414
{
1515
if (!IsLinux)
1616
{

Kerberos.NET/Crypto/Pal/OSX/OSXCryptoPal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Kerberos.NET.Crypto
77
{
88
public class OSXCryptoPal : LinuxCryptoPal
99
{
10-
public OSXCryptoPal()
10+
protected override void PlatformCheck()
1111
{
1212
if (!IsOsX)
1313
{

Kerberos.NET/Crypto/Pal/Windows/WindowsCryptoPal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Kerberos.NET.Crypto
1010
{
1111
public class WindowsCryptoPal : CryptoPal
1212
{
13-
public WindowsCryptoPal()
13+
protected override void PlatformCheck()
1414
{
1515
if (!IsWindows)
1616
{

0 commit comments

Comments
 (0)