| | | 1 | | namespace AsiBackbone.Core.Signing; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Represents the provider-neutral result of a signature verification operation. |
| | | 5 | | /// </summary> |
| | | 6 | | public sealed class SignatureVerificationResult |
| | | 7 | | { |
| | 79 | 8 | | private SignatureVerificationResult( |
| | 79 | 9 | | bool isValid, |
| | 79 | 10 | | string status, |
| | 79 | 11 | | string? failureCode, |
| | 79 | 12 | | string? failureMessage) |
| | | 13 | | { |
| | 79 | 14 | | ArgumentException.ThrowIfNullOrWhiteSpace(status); |
| | | 15 | | |
| | 79 | 16 | | IsValid = isValid; |
| | 79 | 17 | | Status = status.Trim(); |
| | 79 | 18 | | FailureCode = NormalizeOptional(failureCode); |
| | 79 | 19 | | FailureMessage = NormalizeOptional(failureMessage); |
| | 79 | 20 | | } |
| | | 21 | | |
| | | 22 | | /// <summary> |
| | | 23 | | /// Gets a value indicating whether the signature was verified successfully. |
| | | 24 | | /// </summary> |
| | 94 | 25 | | public bool IsValid { get; } |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// Gets a provider-neutral verification status. |
| | | 29 | | /// </summary> |
| | 122 | 30 | | public string Status { get; } |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// Gets a provider-neutral failure code when verification did not succeed. |
| | | 34 | | /// </summary> |
| | 123 | 35 | | public string? FailureCode { get; } |
| | | 36 | | |
| | | 37 | | /// <summary> |
| | | 38 | | /// Gets a provider-neutral failure message when verification did not succeed. |
| | | 39 | | /// </summary> |
| | 34 | 40 | | public string? FailureMessage { get; } |
| | | 41 | | |
| | | 42 | | /// <summary> |
| | | 43 | | /// Creates a successful verification result. |
| | | 44 | | /// </summary> |
| | | 45 | | public static SignatureVerificationResult Verified() |
| | | 46 | | { |
| | 26 | 47 | | return new SignatureVerificationResult(true, "Verified", null, null); |
| | | 48 | | } |
| | | 49 | | |
| | | 50 | | /// <summary> |
| | | 51 | | /// Creates a failed verification result. |
| | | 52 | | /// </summary> |
| | | 53 | | public static SignatureVerificationResult Failed(string failureCode, string? failureMessage = null) |
| | | 54 | | { |
| | 48 | 55 | | return new SignatureVerificationResult(false, "Failed", failureCode, failureMessage); |
| | | 56 | | } |
| | | 57 | | |
| | | 58 | | /// <summary> |
| | | 59 | | /// Creates a result indicating that no signature metadata was available to verify. |
| | | 60 | | /// </summary> |
| | | 61 | | public static SignatureVerificationResult MissingSignature(string? failureMessage = null) |
| | | 62 | | { |
| | 5 | 63 | | return new SignatureVerificationResult(false, "MissingSignature", "signature.missing", failureMessage); |
| | | 64 | | } |
| | | 65 | | |
| | | 66 | | private static string? NormalizeOptional(string? value) |
| | | 67 | | { |
| | 158 | 68 | | return string.IsNullOrWhiteSpace(value) |
| | 158 | 69 | | ? null |
| | 158 | 70 | | : value.Trim(); |
| | | 71 | | } |
| | | 72 | | } |