< Summary

Information
Class: AsiBackbone.Signing.ManagedKey.ManagedKeySigningOptions
Assembly: AsiBackbone.Signing.ManagedKey
File(s): /home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Signing.ManagedKey/ManagedKeySigningOptions.cs
Line coverage
100%
Covered lines: 54
Uncovered lines: 0
Coverable lines: 54
Total lines: 205
Line coverage: 100%
Branch coverage
100%
Covered branches: 22
Total branches: 22
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_DefaultMaxRetryDelay()100%11100%
get_ProviderName()100%11100%
get_KeyId()100%11100%
get_KeyVersion()100%11100%
get_SignatureAlgorithm()100%11100%
get_HashAlgorithm()100%11100%
get_RequireKeyVersion()100%11100%
get_ReturnUnsignedOnFailure()100%11100%
get_MaxRetryAttempts()100%11100%
get_RetryDelay()100%11100%
get_MaxRetryDelay()100%11100%
Create(...)100%22100%
CreateLocalValidation(...)100%11100%
Validate()100%1616100%
NormalizeRequired(...)100%22100%
NormalizeOptional(...)100%22100%

File(s)

/home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Signing.ManagedKey/ManagedKeySigningOptions.cs

#LineLine coverage
 1namespace AsiBackbone.Signing.ManagedKey;
 2
 3/// <summary>
 4/// Configures the managed-key signing provider.
 5/// </summary>
 6/// <remarks>
 7/// The options carry provider-neutral key references and operational behavior. They must not contain private keys,
 8/// credentials, connection strings, client secrets, or managed identity tokens.
 9/// </remarks>
 10public sealed class ManagedKeySigningOptions
 11{
 12    /// <summary>
 13    /// Gets the default provider descriptor returned in signing metadata.
 14    /// </summary>
 15    public const string DefaultProviderName = "managed-key";
 16
 17    /// <summary>
 18    /// Gets the default provider-neutral signature algorithm descriptor.
 19    /// </summary>
 20    public const string DefaultSignatureAlgorithm = "RSASSA-PSS-SHA256-MANAGED-KEY";
 21
 22    /// <summary>
 23    /// Gets the default supported hash algorithm descriptor.
 24    /// </summary>
 25    public const string DefaultHashAlgorithm = "SHA-256";
 26
 27    /// <summary>
 28    /// Gets the default maximum retry delay.
 29    /// </summary>
 11030    public static TimeSpan DefaultMaxRetryDelay { get; } = TimeSpan.FromSeconds(5);
 31
 32    /// <summary>
 33    /// Gets or sets the provider descriptor returned in signing metadata.
 34    /// </summary>
 45235    public string ProviderName { get; set; } = DefaultProviderName;
 36
 37    /// <summary>
 38    /// Gets or sets the managed key identifier or key URI reference.
 39    /// </summary>
 46040    public string KeyId { get; set; } = string.Empty;
 41
 42    /// <summary>
 43    /// Gets or sets the managed key version expected for signing.
 44    /// </summary>
 17445    public string? KeyVersion { get; set; }
 46
 47    /// <summary>
 48    /// Gets or sets the provider-neutral signature algorithm descriptor requested from the managed-key client.
 49    /// </summary>
 48250    public string SignatureAlgorithm { get; set; } = DefaultSignatureAlgorithm;
 51
 52    /// <summary>
 53    /// Gets or sets the hash algorithm expected on incoming signing requests.
 54    /// </summary>
 42855    public string HashAlgorithm { get; set; } = DefaultHashAlgorithm;
 56
 57    /// <summary>
 58    /// Gets or sets a value indicating whether signing requests must specify or resolve a key version.
 59    /// </summary>
 23060    public bool RequireKeyVersion { get; set; } = true;
 61
 62    /// <summary>
 63    /// Gets or sets a value indicating whether signing failures should return unsigned failure metadata instead of thro
 64    /// </summary>
 65    /// <remarks>
 66    /// The production-oriented default is <see langword="false" /> so signing failures fail closed unless a host explic
 67    /// opts into unsigned failure metadata for local validation, samples, or policy-routed fallback behavior.
 68    /// </remarks>
 13469    public bool ReturnUnsignedOnFailure { get; set; }
 70
 71    /// <summary>
 72    /// Gets or sets the maximum number of retry attempts after the initial managed-key signing call.
 73    /// </summary>
 46474    public int MaxRetryAttempts { get; set; } = 2;
 75
 76    /// <summary>
 77    /// Gets or sets the base delay used by the exponential retry backoff calculation.
 78    /// </summary>
 79    /// <remarks>
 80    /// A zero value keeps retries immediate and disables jittered waiting.
 81    /// </remarks>
 64682    public TimeSpan RetryDelay { get; set; } = TimeSpan.FromMilliseconds(200);
 83
 84    /// <summary>
 85    /// Gets or sets the maximum delay applied before any single retry attempt.
 86    /// </summary>
 54287    public TimeSpan MaxRetryDelay { get; set; } = DefaultMaxRetryDelay;
 88
 89    /// <summary>
 90    /// Creates production-oriented managed-key signing options that fail closed by default when signing cannot complete
 91    /// </summary>
 92    public static ManagedKeySigningOptions Create(
 93        string keyId,
 94        string? keyVersion = null,
 95        string? providerName = null,
 96        string? signatureAlgorithm = null,
 97        string? hashAlgorithm = null,
 98        bool requireKeyVersion = true,
 99        bool returnUnsignedOnFailure = false,
 100        int maxRetryAttempts = 2,
 101        TimeSpan? retryDelay = null)
 102    {
 68103        var options = new ManagedKeySigningOptions
 68104        {
 68105            KeyId = NormalizeRequired(keyId, string.Empty),
 68106            KeyVersion = NormalizeOptional(keyVersion),
 68107            ProviderName = NormalizeRequired(providerName, DefaultProviderName),
 68108            SignatureAlgorithm = NormalizeRequired(signatureAlgorithm, DefaultSignatureAlgorithm),
 68109            HashAlgorithm = NormalizeRequired(hashAlgorithm, DefaultHashAlgorithm),
 68110            RequireKeyVersion = requireKeyVersion,
 68111            ReturnUnsignedOnFailure = returnUnsignedOnFailure,
 68112            MaxRetryAttempts = maxRetryAttempts,
 68113            RetryDelay = retryDelay ?? TimeSpan.FromMilliseconds(200)
 68114        };
 115
 68116        options.Validate();
 68117        return options;
 118    }
 119
 120    /// <summary>
 121    /// Creates local-validation managed-key signing options that return unsigned failure metadata instead of throwing.
 122    /// </summary>
 123    /// <remarks>
 124    /// Use this only for samples, tests, diagnostics, or hosts that explicitly route unsigned failure metadata through 
 125    /// Production signing paths should prefer <see cref="Create" /> or set <see cref="ReturnUnsignedOnFailure" /> to
 126    /// <see langword="false" />.
 127    /// </remarks>
 128    public static ManagedKeySigningOptions CreateLocalValidation(
 129        string keyId,
 130        string? keyVersion = null,
 131        string? providerName = null,
 132        string? signatureAlgorithm = null,
 133        string? hashAlgorithm = null,
 134        bool requireKeyVersion = true,
 135        int maxRetryAttempts = 2,
 136        TimeSpan? retryDelay = null)
 137    {
 10138        return Create(
 10139            keyId,
 10140            keyVersion,
 10141            providerName,
 10142            signatureAlgorithm,
 10143            hashAlgorithm,
 10144            requireKeyVersion,
 10145            returnUnsignedOnFailure: true,
 10146            maxRetryAttempts: maxRetryAttempts,
 10147            retryDelay: retryDelay);
 148    }
 149
 150    /// <summary>
 151    /// Validates the managed-key signing options.
 152    /// </summary>
 153    public void Validate()
 154    {
 184155        if (string.IsNullOrWhiteSpace(ProviderName))
 156        {
 2157            throw new InvalidOperationException("Managed-key signing provider name is required.");
 158        }
 159
 182160        if (string.IsNullOrWhiteSpace(KeyId))
 161        {
 4162            throw new InvalidOperationException("Managed-key signing key ID is required.");
 163        }
 164
 178165        if (string.IsNullOrWhiteSpace(SignatureAlgorithm))
 166        {
 2167            throw new InvalidOperationException("Managed-key signing signature algorithm is required.");
 168        }
 169
 176170        if (string.IsNullOrWhiteSpace(HashAlgorithm))
 171        {
 2172            throw new InvalidOperationException("Managed-key signing hash algorithm is required.");
 173        }
 174
 174175        if (MaxRetryAttempts < 0)
 176        {
 2177            throw new InvalidOperationException("Managed-key signing retry attempts must be greater than or equal to zer
 178        }
 179
 172180        if (RetryDelay < TimeSpan.Zero)
 181        {
 2182            throw new InvalidOperationException("Managed-key signing retry delay must be greater than or equal to zero."
 183        }
 184
 170185        if (MaxRetryDelay < TimeSpan.Zero)
 186        {
 2187            throw new InvalidOperationException("Managed-key signing maximum retry delay must be greater than or equal t
 188        }
 189
 168190        if (MaxRetryDelay < RetryDelay)
 191        {
 2192            throw new InvalidOperationException("Managed-key signing maximum retry delay must be greater than or equal t
 193        }
 166194    }
 195
 196    private static string NormalizeRequired(string? value, string fallback)
 197    {
 272198        return string.IsNullOrWhiteSpace(value) ? fallback : value.Trim();
 199    }
 200
 201    private static string? NormalizeOptional(string? value)
 202    {
 68203        return string.IsNullOrWhiteSpace(value) ? null : value.Trim();
 204    }
 205}