-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into chore/remove-rabbitmq
- Loading branch information
Showing
72 changed files
with
306 additions
and
207 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
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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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
1 change: 0 additions & 1 deletion
1
src/Digdir.Domain.Dialogporten.Application/Common/ICompactJwsGenerator.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
28 changes: 19 additions & 9 deletions
28
src/Digdir.Domain.Dialogporten.Application/Common/MappingUtils.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 |
---|---|---|
@@ -1,24 +1,34 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
|
||
namespace Digdir.Domain.Dialogporten.Application.Common; | ||
|
||
internal static class MappingUtils | ||
internal interface IStringHasher | ||
{ | ||
internal static byte[] GetHashSalt(int size = 16) => RandomNumberGenerator.GetBytes(size); | ||
[return: NotNullIfNotNull(nameof(personIdentifier))] | ||
string? Hash(string? personIdentifier); | ||
} | ||
|
||
internal class RandomSaltStringHasher : IStringHasher | ||
{ | ||
private const int SaltSize = 16; | ||
private readonly Lazy<byte[]> _lazySalt = new(() => RandomNumberGenerator.GetBytes(SaltSize)); | ||
|
||
internal static string HashPid(string personIdentifier, byte[] salt) | ||
public string? Hash(string? personIdentifier) | ||
{ | ||
if (string.IsNullOrWhiteSpace(personIdentifier)) | ||
{ | ||
return null; | ||
} | ||
|
||
var identifierBytes = Encoding.UTF8.GetBytes(personIdentifier); | ||
Span<byte> buffer = stackalloc byte[identifierBytes.Length + salt.Length]; | ||
Span<byte> buffer = stackalloc byte[identifierBytes.Length + _lazySalt.Value.Length]; | ||
identifierBytes.CopyTo(buffer); | ||
salt.CopyTo(buffer[identifierBytes.Length..]); | ||
_lazySalt.Value.CopyTo(buffer[identifierBytes.Length..]); | ||
|
||
var hashBytes = SHA256.HashData(buffer); | ||
|
||
return BitConverter | ||
.ToString(hashBytes, 0, 5) | ||
.Replace("-", "") | ||
.ToLowerInvariant(); | ||
return BitConverter.ToString(hashBytes, 0, 5).Replace("-", "").ToLowerInvariant(); | ||
} | ||
} |
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.