< Summary

Information
Class: AsiBackbone.Signing.ManagedKey.ManagedKeySignRequest
Assembly: AsiBackbone.Signing.ManagedKey
File(s): /home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Signing.ManagedKey/ManagedKeySignRequest.cs
Line coverage
100%
Covered lines: 38
Uncovered lines: 0
Coverable lines: 38
Total lines: 103
Line coverage: 100%
Branch coverage
100%
Covered branches: 16
Total branches: 16
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
.ctor(...)100%11100%
get_SigningHash()100%11100%
get_HashAlgorithm()100%11100%
get_SignatureAlgorithm()100%11100%
get_KeyId()100%11100%
get_KeyVersion()100%11100%
get_Purpose()100%11100%
get_Metadata()100%11100%
NormalizeRequired(...)100%11100%
NormalizeOptional(...)100%22100%
NormalizeMetadata(...)100%1414100%

File(s)

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

#LineLine coverage
 1using System.Collections.ObjectModel;
 2
 3namespace AsiBackbone.Signing.ManagedKey;
 4
 5/// <summary>
 6/// Represents a managed-key client request to sign a precomputed governance artifact hash.
 7/// </summary>
 8public sealed class ManagedKeySignRequest
 9{
 210    private static readonly ReadOnlyDictionary<string, string> EmptyMetadata =
 211        new(new Dictionary<string, string>(StringComparer.Ordinal));
 12
 13    /// <summary>
 14    /// Initializes a new instance of the <see cref="ManagedKeySignRequest" /> class.
 15    /// </summary>
 9616    public ManagedKeySignRequest(
 9617        string signingHash,
 9618        string hashAlgorithm,
 9619        string signatureAlgorithm,
 9620        string keyId,
 9621        string? keyVersion = null,
 9622        string? purpose = null,
 9623        IReadOnlyDictionary<string, string>? metadata = null)
 24    {
 9625        ArgumentException.ThrowIfNullOrWhiteSpace(signingHash);
 9026        ArgumentException.ThrowIfNullOrWhiteSpace(hashAlgorithm);
 8427        ArgumentException.ThrowIfNullOrWhiteSpace(signatureAlgorithm);
 7828        ArgumentException.ThrowIfNullOrWhiteSpace(keyId);
 29
 7230        SigningHash = signingHash.Trim();
 7231        HashAlgorithm = NormalizeRequired(hashAlgorithm);
 7232        SignatureAlgorithm = NormalizeRequired(signatureAlgorithm);
 7233        KeyId = NormalizeRequired(keyId);
 7234        KeyVersion = NormalizeOptional(keyVersion);
 7235        Purpose = NormalizeOptional(purpose);
 7236        Metadata = NormalizeMetadata(metadata);
 7237    }
 38
 39    /// <summary>
 40    /// Gets the precomputed hash to sign.
 41    /// </summary>
 1242    public string SigningHash { get; }
 43
 44    /// <summary>
 45    /// Gets the hash algorithm descriptor associated with <see cref="SigningHash" />.
 46    /// </summary>
 647    public string HashAlgorithm { get; }
 48
 49    /// <summary>
 50    /// Gets the requested provider-neutral signature algorithm descriptor.
 51    /// </summary>
 1452    public string SignatureAlgorithm { get; }
 53
 54    /// <summary>
 55    /// Gets the managed key identifier or key URI reference.
 56    /// </summary>
 1457    public string KeyId { get; }
 58
 59    /// <summary>
 60    /// Gets the managed key version, when supplied.
 61    /// </summary>
 1662    public string? KeyVersion { get; }
 63
 64    /// <summary>
 65    /// Gets the host-defined signing purpose, when supplied.
 66    /// </summary>
 467    public string? Purpose { get; }
 68
 69    /// <summary>
 70    /// Gets provider-neutral request metadata.
 71    /// </summary>
 3272    public IReadOnlyDictionary<string, string> Metadata { get; }
 73
 74    private static string NormalizeRequired(string value)
 75    {
 21676        return value.Trim();
 77    }
 78
 79    private static string? NormalizeOptional(string? value)
 80    {
 14481        return string.IsNullOrWhiteSpace(value) ? null : value.Trim();
 82    }
 83
 84    private static ReadOnlyDictionary<string, string> NormalizeMetadata(IReadOnlyDictionary<string, string>? metadata)
 85    {
 7286        if (metadata is null || metadata.Count == 0)
 87        {
 6288            return EmptyMetadata;
 89        }
 90
 1091        Dictionary<string, string> normalized = new(StringComparer.Ordinal);
 92
 17293        foreach (KeyValuePair<string, string> item in metadata)
 94        {
 7695            if (!string.IsNullOrWhiteSpace(item.Key))
 96            {
 7097                normalized[item.Key.Trim()] = item.Value?.Trim() ?? string.Empty;
 98            }
 99        }
 100
 10101        return normalized.Count == 0 ? EmptyMetadata : new ReadOnlyDictionary<string, string>(normalized);
 102    }
 103}