| | | 1 | | namespace ProjectTemplate.Infrastructure.Data.Auditing; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Describes how an audited property value should be represented. |
| | | 5 | | /// </summary> |
| | 20 | 6 | | public sealed record ApplicationAuditValueDecision( |
| | 20 | 7 | | ApplicationAuditValueDisposition Disposition, |
| | 20 | 8 | | int? MaximumLength = null) |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// Gets the UTF-8 key used when <see cref="Disposition" /> is <see cref="ApplicationAuditValueDisposition.HmacSha25 |
| | | 12 | | /// Required for HMAC-SHA-256 and ignored for other dispositions. |
| | | 13 | | /// </summary> |
| | | 14 | | public string? HmacSha256Key { get; init; } |
| | | 15 | | |
| | | 16 | | public static ApplicationAuditValueDecision Include { get; } = new(ApplicationAuditValueDisposition.Include); |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// Gets a decision that records the property as changed while replacing its value with a fixed mask. |
| | | 20 | | /// </summary> |
| | | 21 | | public static ApplicationAuditValueDecision Mask { get; } = new(ApplicationAuditValueDisposition.Mask); |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Creates a decision that records an HMAC-SHA-256 digest using the supplied key. |
| | | 25 | | /// </summary> |
| | | 26 | | public static ApplicationAuditValueDecision HmacSha256(string key) |
| | | 27 | | { |
| | 2 | 28 | | ArgumentException.ThrowIfNullOrWhiteSpace(key); |
| | | 29 | | |
| | 2 | 30 | | return new(ApplicationAuditValueDisposition.HmacSha256) |
| | 2 | 31 | | { |
| | 2 | 32 | | HmacSha256Key = key |
| | 2 | 33 | | }; |
| | | 34 | | } |
| | | 35 | | } |