-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Condition S.S.Cryptography tests on SHA1 signature support
- Loading branch information
Showing
18 changed files
with
171 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/libraries/Common/tests/System/Security/Cryptography/SignatureSupport.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace System.Security.Cryptography.Tests | ||
{ | ||
internal static class SignatureSupport | ||
{ | ||
internal static bool CanProduceSha1Signature(AsymmetricAlgorithm algorithm) | ||
{ | ||
// 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."); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.