using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; namespace StellaOps.Signer.KeyManagement; /// /// Manages trust anchors and their key bindings. /// Implements advisory ยง8.3 trust anchor structure. /// public interface ITrustAnchorManager { /// /// Get a trust anchor by ID. /// /// The anchor ID. /// Cancellation token. /// The trust anchor or null. Task GetAnchorAsync( Guid anchorId, CancellationToken ct = default); /// /// Find a trust anchor matching a PURL. /// Uses pattern matching (e.g., pkg:npm/* matches pkg:npm/lodash@4.17.21). /// /// The PURL to match. /// Cancellation token. /// The matching trust anchor or null. Task FindAnchorForPurlAsync( string purl, CancellationToken ct = default); /// /// Create a new trust anchor. /// /// The creation request. /// Cancellation token. /// The created trust anchor. Task CreateAnchorAsync( CreateTrustAnchorRequest request, CancellationToken ct = default); /// /// Update a trust anchor. /// /// The anchor ID. /// The update request. /// Cancellation token. /// The updated trust anchor. Task UpdateAnchorAsync( Guid anchorId, UpdateTrustAnchorRequest request, CancellationToken ct = default); /// /// Deactivate a trust anchor (soft delete). /// /// The anchor ID. /// Cancellation token. Task DeactivateAnchorAsync( Guid anchorId, CancellationToken ct = default); /// /// Verify a signature against a trust anchor's allowed keys. /// Supports temporal verification for historical proofs. /// /// The anchor ID. /// The key ID that signed. /// When the signature was created. /// The predicate type (if restricted). /// Cancellation token. /// The verification result. Task VerifySignatureAuthorizationAsync( Guid anchorId, string keyId, DateTimeOffset signedAt, string? predicateType = null, CancellationToken ct = default); /// /// Get all active trust anchors. /// /// Cancellation token. /// List of active anchors. Task> GetActiveAnchorsAsync( CancellationToken ct = default); } /// /// Full trust anchor information including key history. /// public sealed record TrustAnchorInfo { /// /// The anchor ID. /// public required Guid AnchorId { get; init; } /// /// PURL glob pattern. /// public required string PurlPattern { get; init; } /// /// Currently allowed key IDs. /// public required IReadOnlyList AllowedKeyIds { get; init; } /// /// Allowed predicate types (null = all). /// public IReadOnlyList? AllowedPredicateTypes { get; init; } /// /// Policy reference. /// public string? PolicyRef { get; init; } /// /// Policy version. /// public string? PolicyVersion { get; init; } /// /// Revoked key IDs (still valid for historical proofs). /// public required IReadOnlyList RevokedKeyIds { get; init; } /// /// Full key history. /// public required IReadOnlyList KeyHistory { get; init; } /// /// Whether the anchor is active. /// public bool IsActive { get; init; } = true; /// /// When the anchor was created. /// public required DateTimeOffset CreatedAt { get; init; } /// /// When the anchor was last updated. /// public required DateTimeOffset UpdatedAt { get; init; } } /// /// Request to create a trust anchor. /// public sealed record CreateTrustAnchorRequest { /// /// PURL glob pattern. /// public required string PurlPattern { get; init; } /// /// Initial allowed key IDs. /// public required IReadOnlyList AllowedKeyIds { get; init; } /// /// Allowed predicate types (null = all). /// public IReadOnlyList? AllowedPredicateTypes { get; init; } /// /// Policy reference. /// public string? PolicyRef { get; init; } /// /// Policy version. /// public string? PolicyVersion { get; init; } } /// /// Request to update a trust anchor. /// public sealed record UpdateTrustAnchorRequest { /// /// Updated predicate types. /// public IReadOnlyList? AllowedPredicateTypes { get; init; } /// /// Updated policy reference. /// public string? PolicyRef { get; init; } /// /// Updated policy version. /// public string? PolicyVersion { get; init; } } /// /// Result of trust verification. /// public sealed record TrustVerificationResult { /// /// Whether the signature is authorized. /// public required bool IsAuthorized { get; init; } /// /// Reason for authorization failure (if applicable). /// public string? FailureReason { get; init; } /// /// The key status at the time of signing. /// public required KeyStatus KeyStatus { get; init; } /// /// Whether the predicate type was allowed. /// public bool? PredicateTypeAllowed { get; init; } }