< Summary

Information
Class: AsiBackbone.Core.CapabilityTokens.CapabilityGrantValidationOptions
Assembly: AsiBackbone.Core
File(s): /home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Core/CapabilityTokens/CapabilityGrantValidationOptions.cs
Line coverage
100%
Covered lines: 142
Uncovered lines: 0
Coverable lines: 142
Total lines: 233
Line coverage: 100%
Branch coverage
100%
Covered branches: 12
Total branches: 12
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Core/CapabilityTokens/CapabilityGrantValidationOptions.cs

#LineLine coverage
 1namespace AsiBackbone.Core.CapabilityTokens;
 2
 3public sealed class CapabilityGrantValidationOptions
 4{
 25    private static readonly string[] EmptyScopes = [];
 6
 1207    private CapabilityGrantValidationOptions(
 1208        string? issuer,
 1209        string? audience,
 12010        IReadOnlyList<string> scopes,
 12011        DateTimeOffset? validationUtc,
 12012        TimeSpan allowedClockSkew,
 12013        string? policyVersion,
 12014        string? policyHash,
 12015        string? acknowledgmentId,
 12016        string? handshakeId,
 12017        string? gatewayBinding,
 12018        string? resourceBinding,
 12019        bool requireProof,
 12020        bool requireAcknowledgmentReference,
 12021        bool requireUseCheck,
 12022        int maxUseCount,
 12023        string? expectedProofKeyId,
 12024        string? expectedProofKeyVersion,
 12025        string? expectedProofPolicyVersion,
 12026        string? expectedProofPolicyHash,
 12027        string? requiredProofProvider,
 12028        string? requiredProofHashAlgorithm)
 29    {
 12030        if (allowedClockSkew < TimeSpan.Zero)
 31        {
 232            throw new ArgumentOutOfRangeException(
 233                nameof(allowedClockSkew),
 234                allowedClockSkew,
 235                "Allowed clock skew must be greater than or equal to zero.");
 36        }
 37
 11838        if (maxUseCount < 1)
 39        {
 240            throw new ArgumentOutOfRangeException(nameof(maxUseCount), maxUseCount, "Maximum use count must be greater t
 41        }
 42
 11643        Issuer = NormalizeOptional(issuer);
 11644        Audience = NormalizeOptional(audience);
 11645        Scopes = scopes;
 11646        ValidationUtc = validationUtc?.ToUniversalTime();
 11647        AllowedClockSkew = allowedClockSkew;
 11648        PolicyVersion = NormalizeOptional(policyVersion);
 11649        PolicyHash = NormalizeOptional(policyHash);
 11650        AcknowledgmentId = NormalizeOptional(acknowledgmentId);
 11651        HandshakeId = NormalizeOptional(handshakeId);
 11652        GatewayBinding = NormalizeOptional(gatewayBinding);
 11653        ResourceBinding = NormalizeOptional(resourceBinding);
 11654        RequireProof = requireProof;
 11655        RequireAcknowledgmentReference = requireAcknowledgmentReference;
 11656        RequireUseCheck = requireUseCheck;
 11657        MaxUseCount = maxUseCount;
 11658        ExpectedProofKeyId = NormalizeOptional(expectedProofKeyId);
 11659        ExpectedProofKeyVersion = NormalizeOptional(expectedProofKeyVersion);
 11660        ExpectedProofPolicyVersion = NormalizeOptional(expectedProofPolicyVersion);
 11661        ExpectedProofPolicyHash = NormalizeOptional(expectedProofPolicyHash);
 11662        RequiredProofProvider = NormalizeOptional(requiredProofProvider);
 11663        RequiredProofHashAlgorithm = NormalizeOptional(requiredProofHashAlgorithm);
 11664    }
 65
 14866    public string? Issuer { get; }
 14467    public string? Audience { get; }
 11468    public IReadOnlyList<string> Scopes { get; }
 10669    public DateTimeOffset? ValidationUtc { get; }
 13870    public TimeSpan AllowedClockSkew { get; }
 9671    public string? PolicyVersion { get; }
 9272    public string? PolicyHash { get; }
 7873    public string? AcknowledgmentId { get; }
 7474    public string? HandshakeId { get; }
 7075    public string? GatewayBinding { get; }
 6676    public string? ResourceBinding { get; }
 11077    public bool RequireProof { get; }
 5678    public bool RequireAcknowledgmentReference { get; }
 4879    public bool RequireUseCheck { get; }
 3080    public int MaxUseCount { get; }
 2881    public string? ExpectedProofKeyId { get; }
 2882    public string? ExpectedProofKeyVersion { get; }
 2883    public string? ExpectedProofPolicyVersion { get; }
 2884    public string? ExpectedProofPolicyHash { get; }
 3085    public string? RequiredProofProvider { get; }
 2886    public string? RequiredProofHashAlgorithm { get; }
 87
 88    public static CapabilityGrantValidationOptions Create(
 89        string? issuer = null,
 90        string? audience = null,
 91        IEnumerable<string>? scopes = null,
 92        DateTimeOffset? validationUtc = null,
 93        string? policyVersion = null,
 94        string? policyHash = null,
 95        string? acknowledgmentId = null,
 96        string? handshakeId = null,
 97        string? gatewayBinding = null,
 98        string? resourceBinding = null,
 99        bool requireProof = false,
 100        bool requireAcknowledgmentReference = false,
 101        bool requireUseCheck = false,
 102        int maxUseCount = 1,
 103        TimeSpan allowedClockSkew = default,
 104        string? expectedProofKeyId = null,
 105        string? expectedProofKeyVersion = null,
 106        string? expectedProofPolicyVersion = null,
 107        string? expectedProofPolicyHash = null,
 108        string? requiredProofProvider = null,
 109        string? requiredProofHashAlgorithm = null)
 110    {
 120111        return new CapabilityGrantValidationOptions(
 120112            issuer,
 120113            audience,
 120114            NormalizeScopes(scopes),
 120115            validationUtc,
 120116            allowedClockSkew,
 120117            policyVersion,
 120118            policyHash,
 120119            acknowledgmentId,
 120120            handshakeId,
 120121            gatewayBinding,
 120122            resourceBinding,
 120123            requireProof,
 120124            requireAcknowledgmentReference,
 120125            requireUseCheck,
 120126            maxUseCount,
 120127            expectedProofKeyId,
 120128            expectedProofKeyVersion,
 120129            expectedProofPolicyVersion,
 120130            expectedProofPolicyHash,
 120131            requiredProofProvider,
 120132            requiredProofHashAlgorithm);
 133    }
 134
 135    public static CapabilityGrantValidationOptions CreateExecutionBoundary(
 136        string? issuer = null,
 137        string? audience = null,
 138        IEnumerable<string>? scopes = null,
 139        DateTimeOffset? validationUtc = null,
 140        string? policyVersion = null,
 141        string? policyHash = null,
 142        string? acknowledgmentId = null,
 143        string? handshakeId = null,
 144        string? gatewayBinding = null,
 145        string? resourceBinding = null,
 146        bool requireAcknowledgmentReference = false,
 147        bool requireUseCheck = true,
 148        int maxUseCount = 1,
 149        TimeSpan allowedClockSkew = default,
 150        string? expectedProofKeyId = null,
 151        string? expectedProofKeyVersion = null,
 152        string? expectedProofPolicyVersion = null,
 153        string? expectedProofPolicyHash = null,
 154        string? requiredProofProvider = null,
 155        string? requiredProofHashAlgorithm = null)
 156    {
 8157        return Create(
 8158            issuer: issuer,
 8159            audience: audience,
 8160            scopes: scopes,
 8161            validationUtc: validationUtc,
 8162            policyVersion: policyVersion,
 8163            policyHash: policyHash,
 8164            acknowledgmentId: acknowledgmentId,
 8165            handshakeId: handshakeId,
 8166            gatewayBinding: gatewayBinding,
 8167            resourceBinding: resourceBinding,
 8168            requireProof: true,
 8169            requireAcknowledgmentReference: requireAcknowledgmentReference,
 8170            requireUseCheck: requireUseCheck,
 8171            maxUseCount: maxUseCount,
 8172            allowedClockSkew: allowedClockSkew,
 8173            expectedProofKeyId: expectedProofKeyId,
 8174            expectedProofKeyVersion: expectedProofKeyVersion,
 8175            expectedProofPolicyVersion: expectedProofPolicyVersion,
 8176            expectedProofPolicyHash: expectedProofPolicyHash,
 8177            requiredProofProvider: requiredProofProvider,
 8178            requiredProofHashAlgorithm: requiredProofHashAlgorithm);
 179    }
 180
 181    public static CapabilityGrantValidationOptions CreateMetadataValidation(
 182        string? issuer = null,
 183        string? audience = null,
 184        IEnumerable<string>? scopes = null,
 185        DateTimeOffset? validationUtc = null,
 186        string? policyVersion = null,
 187        string? policyHash = null,
 188        string? acknowledgmentId = null,
 189        string? handshakeId = null,
 190        string? gatewayBinding = null,
 191        string? resourceBinding = null,
 192        bool requireAcknowledgmentReference = false,
 193        TimeSpan allowedClockSkew = default)
 194    {
 4195        return Create(
 4196            issuer: issuer,
 4197            audience: audience,
 4198            scopes: scopes,
 4199            validationUtc: validationUtc,
 4200            policyVersion: policyVersion,
 4201            policyHash: policyHash,
 4202            acknowledgmentId: acknowledgmentId,
 4203            handshakeId: handshakeId,
 4204            gatewayBinding: gatewayBinding,
 4205            resourceBinding: resourceBinding,
 4206            requireProof: false,
 4207            requireAcknowledgmentReference: requireAcknowledgmentReference,
 4208            requireUseCheck: false,
 4209            maxUseCount: 1,
 4210            allowedClockSkew: allowedClockSkew);
 211    }
 212
 213    private static IReadOnlyList<string> NormalizeScopes(IEnumerable<string>? scopes)
 214    {
 120215        if (scopes is null)
 216        {
 22217            return EmptyScopes;
 218        }
 219
 98220        string[] normalized = [.. scopes
 112221            .Where(scope => !string.IsNullOrWhiteSpace(scope))
 106222            .Select(scope => scope.Trim())
 98223            .Distinct(StringComparer.Ordinal)
 110224            .OrderBy(scope => scope, StringComparer.Ordinal)];
 225
 98226        return normalized.Length == 0 ? EmptyScopes : Array.AsReadOnly(normalized);
 227    }
 228
 229    private static string? NormalizeOptional(string? value)
 230    {
 1624231        return string.IsNullOrWhiteSpace(value) ? null : value.Trim();
 232    }
 233}

Methods/Properties

.cctor()
.ctor(System.String,System.String,System.Collections.Generic.IReadOnlyList`1<System.String>,System.Nullable`1<System.DateTimeOffset>,System.TimeSpan,System.String,System.String,System.String,System.String,System.String,System.String,System.Boolean,System.Boolean,System.Boolean,System.Int32,System.String,System.String,System.String,System.String,System.String,System.String)
get_Issuer()
get_Audience()
get_Scopes()
get_ValidationUtc()
get_AllowedClockSkew()
get_PolicyVersion()
get_PolicyHash()
get_AcknowledgmentId()
get_HandshakeId()
get_GatewayBinding()
get_ResourceBinding()
get_RequireProof()
get_RequireAcknowledgmentReference()
get_RequireUseCheck()
get_MaxUseCount()
get_ExpectedProofKeyId()
get_ExpectedProofKeyVersion()
get_ExpectedProofPolicyVersion()
get_ExpectedProofPolicyHash()
get_RequiredProofProvider()
get_RequiredProofHashAlgorithm()
Create(System.String,System.String,System.Collections.Generic.IEnumerable`1<System.String>,System.Nullable`1<System.DateTimeOffset>,System.String,System.String,System.String,System.String,System.String,System.String,System.Boolean,System.Boolean,System.Boolean,System.Int32,System.TimeSpan,System.String,System.String,System.String,System.String,System.String,System.String)
CreateExecutionBoundary(System.String,System.String,System.Collections.Generic.IEnumerable`1<System.String>,System.Nullable`1<System.DateTimeOffset>,System.String,System.String,System.String,System.String,System.String,System.String,System.Boolean,System.Boolean,System.Int32,System.TimeSpan,System.String,System.String,System.String,System.String,System.String,System.String)
CreateMetadataValidation(System.String,System.String,System.Collections.Generic.IEnumerable`1<System.String>,System.Nullable`1<System.DateTimeOffset>,System.String,System.String,System.String,System.String,System.String,System.String,System.Boolean,System.TimeSpan)
NormalizeScopes(System.Collections.Generic.IEnumerable`1<System.String>)
NormalizeOptional(System.String)