Skip to content

Commit

Permalink
Dispose algorithm for linux (#70458)
Browse files Browse the repository at this point in the history
  • Loading branch information
vcsjones authored Jun 9, 2022
1 parent 207da07 commit 87ca75f
Showing 1 changed file with 34 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,44 @@ internal static class SignatureSupport
{
internal static bool CanProduceSha1Signature(AsymmetricAlgorithm algorithm)
{
#if NETFRAMEWORK
algorithm.Dispose();
return true;
#else
// We expect all non-Linux platforms to support SHA1 signatures, currently.
if (!OperatingSystem.IsLinux())
using (algorithm)
{
#if NETFRAMEWORK
return true;
}
#else
// We expect all non-Linux platforms to support SHA1 signatures, currently.
if (!OperatingSystem.IsLinux())
{
return true;
}

switch (algorithm)
{
case ECDsa ecdsa:
try
{
ecdsa.SignData(Array.Empty<byte>(), HashAlgorithmName.SHA1);
return true;
}
catch (CryptographicException)
{
return false;
}
finally
{
algorithm.Dispose();
}
case RSA rsa:
try
{
rsa.SignData(Array.Empty<byte>(), HashAlgorithmName.SHA1, RSASignaturePadding.Pkcs1);
return true;
}
catch (CryptographicException)
{
return false;
}
finally
{
algorithm.Dispose();
}
default:
throw new NotSupportedException($"Algorithm type {algorithm.GetType()} is not supported.");
}
switch (algorithm)
{
case ECDsa ecdsa:
try
{
ecdsa.SignData(Array.Empty<byte>(), HashAlgorithmName.SHA1);
return true;
}
catch (CryptographicException)
{
return false;
}
case RSA rsa:
try
{
rsa.SignData(Array.Empty<byte>(), HashAlgorithmName.SHA1, RSASignaturePadding.Pkcs1);
return true;
}
catch (CryptographicException)
{
return false;
}
default:
throw new NotSupportedException($"Algorithm type {algorithm.GetType()} is not supported.");
}
#endif
}
}
}
}

0 comments on commit 87ca75f

Please sign in to comment.