Skip to content

Commit

Permalink
Fixed #151. Also fixed AES support.
Browse files Browse the repository at this point in the history
  • Loading branch information
lextm committed Sep 3, 2021
1 parent c113929 commit e4bfc8e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 24 deletions.
30 changes: 25 additions & 5 deletions SharpSnmpLib/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,38 @@ public static PhysicalAddress ToPhysicalAddress(this OctetString address)
return new PhysicalAddress(raw);
}

private static bool? securitySupported;
private static bool? desSupported;

public static bool SecuritySupported
public static bool DESSupported
{
get
{
if (securitySupported != null)
if (desSupported != null)
{
return securitySupported.Value;
return desSupported.Value;
}

return (securitySupported = RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework")).Value;
return (desSupported = RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework")
|| RuntimeInformation.FrameworkDescription.StartsWith(".NET 6.")
|| RuntimeInformation.FrameworkDescription.StartsWith(".NET 5.")
|| RuntimeInformation.FrameworkDescription.StartsWith(".NET Core 3.1.")).Value;
}
}

private static bool? aesSupported;

public static bool AESSupported
{
get
{
if (aesSupported != null)
{
return aesSupported.Value;
}

return (aesSupported = RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework")
|| RuntimeInformation.FrameworkDescription.StartsWith(".NET 6.")
|| RuntimeInformation.FrameworkDescription.StartsWith(".NET 5.")).Value;
}
}
}
Expand Down
9 changes: 1 addition & 8 deletions SharpSnmpLib/Security/AESPrivacyProviderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,8 @@ public static bool IsSupported
get
{
#if NETSTANDARD2_0
return Helper.SecuritySupported;
return Helper.AESSupported;
#else
if (RuntimeInformation.FrameworkDescription.Contains(".NET Core"))
{
// netcoreappX.X
return false;
}

// netXXX, xamarin.ios10, and monoandroid80
return true;
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion SharpSnmpLib/Security/DESPrivacyProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static bool IsSupported
get
{
#if NETSTANDARD2_0
return Helper.SecuritySupported;
return Helper.DESSupported;
#else
return true;
#endif
Expand Down
2 changes: 1 addition & 1 deletion Tests/CSharpCore/Tests.NetStandard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>
<PropertyGroup>
<OutputType Condition="'$(TargetFramework)'!='net471'">Exe</OutputType>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net5.0;netcoreapp3.1;netcoreapp2.1;net471</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net6.0;net5.0;netcoreapp3.1;net471</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp3.1;netcoreapp2.1</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,11 @@ public void TestDecrypt()
public void TestIsSupported()
{
#if NET6_0
Assert.False(AESPrivacyProviderBase.IsSupported);
Assert.True(AESPrivacyProviderBase.IsSupported);
#elif NET5_0
Assert.False(AESPrivacyProviderBase.IsSupported);
Assert.True(AESPrivacyProviderBase.IsSupported);
#elif NETCOREAPP3_1
Assert.False(AESPrivacyProviderBase.IsSupported);
#elif NETCOREAPP2_1
Assert.False(AESPrivacyProviderBase.IsSupported);
#elif NET471
Assert.True(AESPrivacyProviderBase.IsSupported);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ public void TestException()
public void TestIsSupported()
{
#if NET6_0
Assert.False(DESPrivacyProvider.IsSupported);
Assert.True(DESPrivacyProvider.IsSupported);
#elif NET5_0
Assert.False(DESPrivacyProvider.IsSupported);
Assert.True(DESPrivacyProvider.IsSupported);
#elif NETCOREAPP3_1
Assert.False(DESPrivacyProvider.IsSupported);
#elif NETCOREAPP2_1
Assert.False(DESPrivacyProvider.IsSupported);
Assert.True(DESPrivacyProvider.IsSupported);
#elif NET471
Assert.True(DESPrivacyProvider.IsSupported);
#endif
Expand Down

0 comments on commit e4bfc8e

Please sign in to comment.