< Summary

Information
Class: AsiBackbone.Signing.LocalDevelopment.LocalDevelopmentSigningOptions
Assembly: AsiBackbone.Signing.LocalDevelopment
File(s): /home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Signing.LocalDevelopment/LocalDevelopmentSigningOptions.cs
Line coverage
100%
Covered lines: 27
Uncovered lines: 0
Coverable lines: 27
Total lines: 119
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
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_ProviderName()100%11100%
get_KeyId()100%11100%
get_KeyVersion()100%11100%
get_SignatureAlgorithm()100%11100%
get_KeySizeBits()100%11100%
get_ReturnUnsignedOnFailure()100%11100%
Validate()100%22100%
Create(...)100%88100%

File(s)

/home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Signing.LocalDevelopment/LocalDevelopmentSigningOptions.cs

#LineLine coverage
 1namespace AsiBackbone.Signing.LocalDevelopment;
 2
 3/// <summary>
 4/// Configures the local-development signing provider.
 5/// </summary>
 6/// <remarks>
 7/// This provider is intended for local development, samples, and tests. It is not a production managed-key provider and
 8/// </remarks>
 9public sealed class LocalDevelopmentSigningOptions
 10{
 11    /// <summary>
 12    /// Gets the minimum supported RSA key size for generated local-development keys.
 13    /// </summary>
 14    public const int MinimumKeySizeBits = 2048;
 15
 16    /// <summary>
 17    /// Gets the default provider descriptor returned in signing metadata.
 18    /// </summary>
 19    public const string DefaultProviderName = "local-development";
 20
 21    /// <summary>
 22    /// Gets the default local-development key identifier.
 23    /// </summary>
 24    public const string DefaultKeyId = "local-dev-key";
 25
 26    /// <summary>
 27    /// Gets the default local-development key version.
 28    /// </summary>
 29    public const string DefaultKeyVersion = "dev";
 30
 31    /// <summary>
 32    /// Gets the default provider-neutral signature algorithm descriptor.
 33    /// </summary>
 34    public const string DefaultSignatureAlgorithm = "RSASSA-PSS-SHA256-LOCAL-DEV";
 35
 36    /// <summary>
 37    /// Gets the default RSA key size for generated local-development keys.
 38    /// </summary>
 39    public const int DefaultKeySizeBits = MinimumKeySizeBits;
 40
 41    /// <summary>
 42    /// Gets or sets the provider descriptor returned in signing metadata.
 43    /// </summary>
 13444    public string ProviderName { get; set; } = DefaultProviderName;
 45
 46    /// <summary>
 47    /// Gets or sets the local-development key identifier returned in signing metadata.
 48    /// </summary>
 15449    public string KeyId { get; set; } = DefaultKeyId;
 50
 51    /// <summary>
 52    /// Gets or sets the local-development key version returned in signing metadata.
 53    /// </summary>
 15454    public string KeyVersion { get; set; } = DefaultKeyVersion;
 55
 56    /// <summary>
 57    /// Gets or sets the signature algorithm descriptor returned in signing metadata.
 58    /// </summary>
 10459    public string SignatureAlgorithm { get; set; } = DefaultSignatureAlgorithm;
 60
 61    /// <summary>
 62    /// Gets or sets the generated RSA key size in bits.
 63    /// </summary>
 64    /// <remarks>
 65    /// Values below <see cref="MinimumKeySizeBits" /> are invalid. Omitted configuration uses
 66    /// <see cref="DefaultKeySizeBits" />.
 67    /// </remarks>
 18268    public int KeySizeBits { get; set; } = DefaultKeySizeBits;
 69
 70    /// <summary>
 71    /// Gets or sets a value indicating whether signing failures should return unsigned metadata with explicit failure d
 72    /// </summary>
 8473    public bool ReturnUnsignedOnFailure { get; set; } = true;
 74
 75    /// <summary>
 76    /// Validates the configured local-development signing options.
 77    /// </summary>
 78    /// <exception cref="InvalidOperationException">
 79    /// Thrown when <see cref="KeySizeBits" /> is below <see cref="MinimumKeySizeBits" />.
 80    /// </exception>
 81    public void Validate()
 82    {
 5083        if (KeySizeBits < MinimumKeySizeBits)
 84        {
 2285            throw new InvalidOperationException(
 2286                $"Local-development RSA key size must be at least {MinimumKeySizeBits} bits. Configured value: {KeySizeB
 87        }
 2888    }
 89
 90    /// <summary>
 91    /// Creates options for the local-development signing provider.
 92    /// </summary>
 93    public static LocalDevelopmentSigningOptions Create(
 94        string? providerName = null,
 95        string? keyId = null,
 96        string? keyVersion = null,
 97        string? signatureAlgorithm = null,
 98        int keySizeBits = DefaultKeySizeBits,
 99        bool returnUnsignedOnFailure = true)
 100    {
 40101        return new LocalDevelopmentSigningOptions
 40102        {
 40103            ProviderName = string.IsNullOrWhiteSpace(providerName)
 40104                ? DefaultProviderName
 40105                : providerName.Trim(),
 40106            KeyId = string.IsNullOrWhiteSpace(keyId)
 40107                ? DefaultKeyId
 40108                : keyId.Trim(),
 40109            KeyVersion = string.IsNullOrWhiteSpace(keyVersion)
 40110                ? DefaultKeyVersion
 40111                : keyVersion.Trim(),
 40112            SignatureAlgorithm = string.IsNullOrWhiteSpace(signatureAlgorithm)
 40113                ? DefaultSignatureAlgorithm
 40114                : signatureAlgorithm.Trim(),
 40115            KeySizeBits = keySizeBits,
 40116            ReturnUnsignedOnFailure = returnUnsignedOnFailure
 40117        };
 118    }
 119}