| | | 1 | | using AsiBackbone.Core.Actors; |
| | | 2 | | using AsiBackbone.Core.Audit; |
| | | 3 | | using AsiBackbone.Core.Constraints; |
| | | 4 | | using AsiBackbone.Core.Decisions; |
| | | 5 | | using AsiBackbone.Core.Emissions; |
| | | 6 | | using AsiBackbone.Core.HostIntegration; |
| | | 7 | | |
| | | 8 | | namespace AsiBackbone.Core.Signing; |
| | | 9 | | |
| | | 10 | | /// <summary> |
| | | 11 | | /// Maps enum values used by canonical signed payloads to their stable v1 wire names. |
| | | 12 | | /// </summary> |
| | | 13 | | /// <remarks> |
| | | 14 | | /// These strings are signature protocol constants. They intentionally do not depend on CLR member names so a source |
| | | 15 | | /// rename cannot silently change canonical bytes. Existing values preserve the names emitted by AsiBackbone 6.0. |
| | | 16 | | /// </remarks> |
| | | 17 | | internal static class CanonicalEnumWireNames |
| | | 18 | | { |
| | | 19 | | public static string ForActorType(GovernanceActorType value) |
| | | 20 | | { |
| | 81 | 21 | | return value switch |
| | 81 | 22 | | { |
| | 1 | 23 | | GovernanceActorType.Unknown => "Unknown", |
| | 24 | 24 | | GovernanceActorType.Human => "Human", |
| | 21 | 25 | | GovernanceActorType.System => "System", |
| | 34 | 26 | | GovernanceActorType.Service => "Service", |
| | 1 | 27 | | GovernanceActorType.Agent => "Agent", |
| | 0 | 28 | | _ => ThrowUndefined(value) |
| | 81 | 29 | | }; |
| | | 30 | | } |
| | | 31 | | |
| | | 32 | | public static string ForLifecycleStage(DecisionReceiptLifecycleStage value) |
| | | 33 | | { |
| | 63 | 34 | | return value switch |
| | 63 | 35 | | { |
| | 4 | 36 | | DecisionReceiptLifecycleStage.DecisionEvaluated => "DecisionEvaluated", |
| | 4 | 37 | | DecisionReceiptLifecycleStage.AcknowledgmentRequested => "AcknowledgmentRequested", |
| | 4 | 38 | | DecisionReceiptLifecycleStage.AcknowledgmentCompleted => "AcknowledgmentCompleted", |
| | 4 | 39 | | DecisionReceiptLifecycleStage.CapabilityTokenIssued => "CapabilityTokenIssued", |
| | 4 | 40 | | DecisionReceiptLifecycleStage.GatewayExecutionStarted => "GatewayExecutionStarted", |
| | 8 | 41 | | DecisionReceiptLifecycleStage.GatewayExecutionCompleted => "GatewayExecutionCompleted", |
| | 4 | 42 | | DecisionReceiptLifecycleStage.GatewayExecutionDenied => "GatewayExecutionDenied", |
| | 18 | 43 | | DecisionReceiptLifecycleStage.ExternalEmissionQueued => "ExternalEmissionQueued", |
| | 4 | 44 | | DecisionReceiptLifecycleStage.ExternalEmissionDelivered => "ExternalEmissionDelivered", |
| | 5 | 45 | | DecisionReceiptLifecycleStage.ExternalEmissionFailed => "ExternalEmissionFailed", |
| | 4 | 46 | | DecisionReceiptLifecycleStage.ExternalEmissionDeadLettered => "ExternalEmissionDeadLettered", |
| | 0 | 47 | | _ => ThrowUndefined(value) |
| | 63 | 48 | | }; |
| | | 49 | | } |
| | | 50 | | |
| | | 51 | | public static string ForDecisionOutcome(GovernanceDecisionOutcome value) |
| | | 52 | | { |
| | 35 | 53 | | return value switch |
| | 35 | 54 | | { |
| | 9 | 55 | | GovernanceDecisionOutcome.Allowed => "Allowed", |
| | 5 | 56 | | GovernanceDecisionOutcome.Warning => "Warning", |
| | 8 | 57 | | GovernanceDecisionOutcome.Denied => "Denied", |
| | 4 | 58 | | GovernanceDecisionOutcome.Deferred => "Deferred", |
| | 5 | 59 | | GovernanceDecisionOutcome.AcknowledgmentRequired => "AcknowledgmentRequired", |
| | 4 | 60 | | GovernanceDecisionOutcome.EscalationRecommended => "EscalationRecommended", |
| | 0 | 61 | | _ => ThrowUndefined(value) |
| | 35 | 62 | | }; |
| | | 63 | | } |
| | | 64 | | |
| | | 65 | | public static string ForConstraintOutcome(ConstraintEvaluationOutcome value) |
| | | 66 | | { |
| | 16 | 67 | | return value switch |
| | 16 | 68 | | { |
| | 3 | 69 | | ConstraintEvaluationOutcome.NotApplicable => "NotApplicable", |
| | 3 | 70 | | ConstraintEvaluationOutcome.Allowed => "Allowed", |
| | 6 | 71 | | ConstraintEvaluationOutcome.Warning => "Warning", |
| | 4 | 72 | | ConstraintEvaluationOutcome.Denied => "Denied", |
| | 0 | 73 | | _ => ThrowUndefined(value) |
| | 16 | 74 | | }; |
| | | 75 | | } |
| | | 76 | | |
| | | 77 | | public static string ForEmissionEventType(GovernanceEmissionEventType value) |
| | | 78 | | { |
| | 60 | 79 | | return value switch |
| | 60 | 80 | | { |
| | 1 | 81 | | GovernanceEmissionEventType.Decision => "Decision", |
| | 1 | 82 | | GovernanceEmissionEventType.Acknowledgment => "Acknowledgment", |
| | 1 | 83 | | GovernanceEmissionEventType.CapabilityToken => "CapabilityToken", |
| | 1 | 84 | | GovernanceEmissionEventType.Gateway => "Gateway", |
| | 20 | 85 | | GovernanceEmissionEventType.DecisionReceipt => "AuditResidue", |
| | 28 | 86 | | GovernanceEmissionEventType.AuditLifecycle => "AuditLifecycle", |
| | 7 | 87 | | GovernanceEmissionEventType.Outbox => "Outbox", |
| | 1 | 88 | | GovernanceEmissionEventType.ProviderEmission => "ProviderEmission", |
| | 0 | 89 | | _ => ThrowUndefined(value) |
| | 60 | 90 | | }; |
| | | 91 | | } |
| | | 92 | | |
| | | 93 | | public static string ForEmissionStatus(GovernanceEmissionStatus value) |
| | | 94 | | { |
| | 16 | 95 | | return value switch |
| | 16 | 96 | | { |
| | 9 | 97 | | GovernanceEmissionStatus.Pending => "Pending", |
| | 1 | 98 | | GovernanceEmissionStatus.Delivered => "Delivered", |
| | 1 | 99 | | GovernanceEmissionStatus.Deferred => "Deferred", |
| | 1 | 100 | | GovernanceEmissionStatus.Failed => "Failed", |
| | 3 | 101 | | GovernanceEmissionStatus.RetryableFailure => "RetryableFailure", |
| | 1 | 102 | | GovernanceEmissionStatus.DeadLettered => "DeadLettered", |
| | 0 | 103 | | _ => ThrowUndefined(value) |
| | 16 | 104 | | }; |
| | | 105 | | } |
| | | 106 | | |
| | | 107 | | public static string ForPersistenceOutcome(GovernedOperationPersistenceOutcome value) |
| | | 108 | | { |
| | 50 | 109 | | return value switch |
| | 50 | 110 | | { |
| | 24 | 111 | | GovernedOperationPersistenceOutcome.Committed => "Committed", |
| | 8 | 112 | | GovernedOperationPersistenceOutcome.Failed => "Failed", |
| | 8 | 113 | | GovernedOperationPersistenceOutcome.RolledBack => "RolledBack", |
| | 10 | 114 | | GovernedOperationPersistenceOutcome.CompletedWithoutMutation => "CompletedWithoutMutation", |
| | 0 | 115 | | _ => ThrowUndefined(value) |
| | 50 | 116 | | }; |
| | | 117 | | } |
| | | 118 | | |
| | | 119 | | private static string ThrowUndefined<TEnum>(TEnum value) |
| | | 120 | | where TEnum : struct, Enum |
| | | 121 | | { |
| | 0 | 122 | | throw new ArgumentOutOfRangeException(nameof(value), value, "Canonical enum wire values must be explicitly defin |
| | | 123 | | } |
| | | 124 | | } |