This repository has been archived by the owner on Feb 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for hashing of at_hash with all supported algorithms
- Loading branch information
1 parent
49595f9
commit a5e1176
Showing
1 changed file
with
31 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Text; | ||
using FluentAssertions; | ||
using IdentityModel; | ||
using IdentityModel.OidcClient; | ||
using Xunit; | ||
|
||
public class CryptoHelperTests | ||
{ | ||
[Theory] | ||
[InlineData("asdf", "RS256")] | ||
[InlineData("asdf", "RS384")] | ||
[InlineData("asdf", "RS512")] | ||
public void ComputeHash_should_compute_correct_hashes_for_all_signature_algorithms(string data, string algorithmName) | ||
{ | ||
var sut = new CryptoHelper(new OidcClientOptions()); | ||
var algorithm = sut.GetMatchingHashAlgorithm(algorithmName); | ||
|
||
var hash = algorithm.ComputeHash(Encoding.ASCII.GetBytes(data)); | ||
|
||
var bytesInLeftHalf = algorithm.HashSize / 16; // Divide by 8 for bytes and then 2 to get just half. | ||
|
||
var leftHalf = new byte[bytesInLeftHalf]; | ||
Array.Copy(hash, leftHalf, bytesInLeftHalf); | ||
|
||
var hashString = Base64Url.Encode(leftHalf); | ||
|
||
sut.ValidateHash(data, hashString, algorithmName).Should().BeTrue(); | ||
} | ||
|
||
} |