< 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
92%
Covered lines: 35
Uncovered lines: 3
Coverable lines: 38
Total lines: 103
Line coverage: 92.1%
Branch coverage
68%
Covered branches: 11
Total branches: 16
Branch coverage: 68.7%
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%210%
get_SignatureAlgorithm()100%11100%
get_KeyId()100%11100%
get_KeyVersion()100%11100%
get_Purpose()100%210%
get_Metadata()100%210%
NormalizeRequired(...)100%11100%
NormalizeOptional(...)50%22100%
NormalizeMetadata(...)71.42%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>
 616    public ManagedKeySignRequest(
 617        string signingHash,
 618        string hashAlgorithm,
 619        string signatureAlgorithm,
 620        string keyId,
 621        string? keyVersion = null,
 622        string? purpose = null,
 623        IReadOnlyDictionary<string, string>? metadata = null)
 24    {
 625        ArgumentException.ThrowIfNullOrWhiteSpace(signingHash);
 626        ArgumentException.ThrowIfNullOrWhiteSpace(hashAlgorithm);
 627        ArgumentException.ThrowIfNullOrWhiteSpace(signatureAlgorithm);
 628        ArgumentException.ThrowIfNullOrWhiteSpace(keyId);
 29
 630        SigningHash = signingHash.Trim();
 631        HashAlgorithm = NormalizeRequired(hashAlgorithm);
 632        SignatureAlgorithm = NormalizeRequired(signatureAlgorithm);
 633        KeyId = NormalizeRequired(keyId);
 634        KeyVersion = NormalizeOptional(keyVersion);
 635        Purpose = NormalizeOptional(purpose);
 636        Metadata = NormalizeMetadata(metadata);
 637    }
 38
 39    /// <summary>
 40    /// Gets the precomputed hash to sign.
 41    /// </summary>
 442    public string SigningHash { get; }
 43
 44    /// <summary>
 45    /// Gets the hash algorithm descriptor associated with <see cref="SigningHash" />.
 46    /// </summary>
 047    public string HashAlgorithm { get; }
 48
 49    /// <summary>
 50    /// Gets the requested provider-neutral signature algorithm descriptor.
 51    /// </summary>
 452    public string SignatureAlgorithm { get; }
 53
 54    /// <summary>
 55    /// Gets the managed key identifier or key URI reference.
 56    /// </summary>
 457    public string KeyId { get; }
 58
 59    /// <summary>
 60    /// Gets the managed key version, when supplied.
 61    /// </summary>
 462    public string? KeyVersion { get; }
 63
 64    /// <summary>
 65    /// Gets the host-defined signing purpose, when supplied.
 66    /// </summary>
 067    public string? Purpose { get; }
 68
 69    /// <summary>
 70    /// Gets provider-neutral request metadata.
 71    /// </summary>
 072    public IReadOnlyDictionary<string, string> Metadata { get; }
 73
 74    private static string NormalizeRequired(string value)
 75    {
 1876        return value.Trim();
 77    }
 78
 79    private static string? NormalizeOptional(string? value)
 80    {
 1281        return string.IsNullOrWhiteSpace(value) ? null : value.Trim();
 82    }
 83
 84    private static ReadOnlyDictionary<string, string> NormalizeMetadata(IReadOnlyDictionary<string, string>? metadata)
 85    {
 686        if (metadata is null || metadata.Count == 0)
 87        {
 488            return EmptyMetadata;
 89        }
 90
 291        Dictionary<string, string> normalized = new(StringComparer.Ordinal);
 92
 1293        foreach (KeyValuePair<string, string> item in metadata)
 94        {
 495            if (!string.IsNullOrWhiteSpace(item.Key))
 96            {
 497                normalized[item.Key.Trim()] = item.Value?.Trim() ?? string.Empty;
 98            }
 99        }
 100
 2101        return normalized.Count == 0 ? EmptyMetadata : new ReadOnlyDictionary<string, string>(normalized);
 102    }
 103}