| | | 1 | | using AsiBackbone.Core.Signing; |
| | | 2 | | |
| | | 3 | | namespace AsiBackbone.Core.CapabilityGrants; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Represents the outcome of decoding a capability grant token with <see cref="CapabilityGrantToken.Decode" />. |
| | | 7 | | /// </summary> |
| | | 8 | | /// <remarks> |
| | | 9 | | /// A successful decode establishes only that the token is well formed. The decoded grant has not been verified: pass |
| | | 10 | | /// <see cref="SignedGrant" /> to <see cref="CapabilityGrantValidator.ValidateAsync" /> with a proof-requiring profile |
| | | 11 | | /// before trusting any of its values. |
| | | 12 | | /// </remarks> |
| | | 13 | | public sealed class CapabilityGrantTokenDecodeResult |
| | | 14 | | { |
| | 87 | 15 | | private CapabilityGrantTokenDecodeResult( |
| | 87 | 16 | | SignedGovernanceArtifact<CapabilityGrant>? signedGrant, |
| | 87 | 17 | | string? failureCode, |
| | 87 | 18 | | string? failureMessage) |
| | | 19 | | { |
| | 87 | 20 | | SignedGrant = signedGrant; |
| | 87 | 21 | | FailureCode = failureCode; |
| | 87 | 22 | | FailureMessage = failureMessage; |
| | 87 | 23 | | } |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Gets a value indicating whether the token decoded into a signed grant. |
| | | 27 | | /// </summary> |
| | 84 | 28 | | public bool Succeeded => SignedGrant is not null; |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Gets the decoded, not yet verified, signed grant when decoding succeeded. |
| | | 32 | | /// </summary> |
| | | 33 | | /// <remarks> |
| | | 34 | | /// The canonical payload and hash are rebuilt from the decoded grant fields rather than read from the token, so a |
| | | 35 | | /// grant field edited after signing produces a hash the signature does not cover. |
| | | 36 | | /// </remarks> |
| | | 37 | | public SignedGovernanceArtifact<CapabilityGrant>? SignedGrant { get; } |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Gets the machine-readable failure code, such as <c>capability.token-malformed</c>, when decoding failed. |
| | | 41 | | /// </summary> |
| | | 42 | | public string? FailureCode { get; } |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// Gets a human-readable failure message, when decoding failed. |
| | | 46 | | /// </summary> |
| | | 47 | | /// <remarks> |
| | | 48 | | /// The message describes the token structure only and never echoes token content. |
| | | 49 | | /// </remarks> |
| | | 50 | | public string? FailureMessage { get; } |
| | | 51 | | |
| | | 52 | | internal static CapabilityGrantTokenDecodeResult Success(SignedGovernanceArtifact<CapabilityGrant> signedGrant) |
| | | 53 | | { |
| | 64 | 54 | | return new CapabilityGrantTokenDecodeResult(signedGrant, failureCode: null, failureMessage: null); |
| | | 55 | | } |
| | | 56 | | |
| | | 57 | | internal static CapabilityGrantTokenDecodeResult Failure(string failureCode, string failureMessage) |
| | | 58 | | { |
| | 23 | 59 | | return new CapabilityGrantTokenDecodeResult(signedGrant: null, failureCode, failureMessage); |
| | | 60 | | } |
| | | 61 | | } |