diff --git a/src/Particular.LicensingComponent.Report.UnitTests/ApprovalFiles/ApiApprovals.Approve.approved.txt b/src/Particular.LicensingComponent.Report.UnitTests/ApprovalFiles/ApiApprovals.Approve.approved.txt index da8dade..6e97c6a 100644 --- a/src/Particular.LicensingComponent.Report.UnitTests/ApprovalFiles/ApiApprovals.Approve.approved.txt +++ b/src/Particular.LicensingComponent.Report.UnitTests/ApprovalFiles/ApiApprovals.Approve.approved.txt @@ -25,6 +25,7 @@ namespace Particular.LicensingComponent.Report public class QueueThroughput : System.IEquatable { public QueueThroughput() { } + public string NameHash { get; set; } public string QueueName { get; set; } public long? Throughput { get; set; } public Particular.LicensingComponent.Report.DailyThroughput[] DailyThroughputFromAudit { get; init; } @@ -77,4 +78,16 @@ namespace Particular.LicensingComponent.Report public Particular.LicensingComponent.Report.Report ReportData { get; init; } public string Signature { get; init; } } +} +namespace Particular.LicensingComponent.Report.Utility +{ + public class Masker + { + public Masker(string[] wordsToMask) { } + public string Mask(string stringToMask) { } + } + public static class OneWayHasher + { + public static string CalculateOneWayHash(string input) { } + } } \ No newline at end of file diff --git a/src/Particular.LicensingComponent.Report/Report.cs b/src/Particular.LicensingComponent.Report/Report.cs index 87c6a64..ef75c74 100644 --- a/src/Particular.LicensingComponent.Report/Report.cs +++ b/src/Particular.LicensingComponent.Report/Report.cs @@ -116,6 +116,14 @@ public record QueueThroughput /// public string QueueName { get; set; } + /// + /// A hash of the queue name to support unique identification of queues across reports without exposing potentially sensitive information. + /// + /// + /// This should be a one-way hash of the unmasked queue name. + /// + public string NameHash { get; set; } + /// /// Queue max daily throughput /// diff --git a/src/Particular.LicensingComponent.Report/Utility/Masker.cs b/src/Particular.LicensingComponent.Report/Utility/Masker.cs new file mode 100644 index 0000000..3a8319b --- /dev/null +++ b/src/Particular.LicensingComponent.Report/Utility/Masker.cs @@ -0,0 +1,36 @@ +namespace Particular.LicensingComponent.Report.Utility; +/// +/// Provides functionality to mask specified words in a given string with unique replacement values. +/// +public class Masker +{ + readonly (string Mask, string Replacement)[] masks; + + /// + /// Initializes a new instance of the Masker class with the specified words to be masked. + /// + public Masker(string[] wordsToMask) + { + var number = 0; + masks = [.. wordsToMask + .Select(mask => + { + number++; + return (mask, $"REDACTED{number}"); + })]; + } + + /// + /// Replaces all occurrences of specified substrings in the input string with their corresponding masked values + /// using a predefined set of masks. + /// + public string Mask(string stringToMask) + { + var result = stringToMask; + foreach (var (mask, replacement) in masks) + { + result = result.Replace(mask, replacement, StringComparison.OrdinalIgnoreCase); + } + return result; + } +} \ No newline at end of file diff --git a/src/Particular.LicensingComponent.Report/Utility/OneWayHasher.cs b/src/Particular.LicensingComponent.Report/Utility/OneWayHasher.cs new file mode 100644 index 0000000..6e2fe03 --- /dev/null +++ b/src/Particular.LicensingComponent.Report/Utility/OneWayHasher.cs @@ -0,0 +1,16 @@ +namespace Particular.LicensingComponent.Report.Utility; + +using System.Security.Cryptography; +using System.Text; + +/// +/// Provides static methods for computing one-way hashes using the SHA3-256 algorithm. +/// +public static class OneWayHasher +{ + /// + /// Calculates the SHA3-256 hash of the specified input string and returns the result as a hexadecimal string. + /// + public static string CalculateOneWayHash(string input) + => BitConverter.ToString(SHA3_256.HashData(Encoding.UTF8.GetBytes(input))).Replace("-", ""); +} \ No newline at end of file