< Summary

Information
Class: AsiBackbone.Signing.ManagedKey.KeySignatureVerificationOptions
Assembly: AsiBackbone.Signing.ManagedKey
File(s): /home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Signing.ManagedKey/KeySignatureVerificationOptions.cs
Line coverage
89%
Covered lines: 17
Uncovered lines: 2
Coverable lines: 19
Total lines: 60
Line coverage: 89.4%
Branch coverage
50%
Covered branches: 3
Total branches: 6
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
get_Keys()100%11100%
get_AllowedAlgorithms()100%11100%
AddPemKey(...)100%11100%
AddJwkKey(...)100%11100%
Validate()50%8660%

File(s)

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

#LineLine coverage
 1namespace AsiBackbone.Signing.ManagedKey;
 2
 3/// <summary>Configures public-key signature verification.</summary>
 4public sealed class KeySignatureVerificationOptions
 5{
 56    private readonly List<GovernanceVerificationKey> keys = [];
 57    private readonly HashSet<string> allowedAlgorithms = new(StringComparer.Ordinal)
 58    {
 59        ManagedKeySignatureAlgorithms.RsaPssSha256,
 510        ManagedKeySignatureAlgorithms.EcdsaP256Sha256
 511    };
 12
 13    /// <summary>Gets the configured trusted key versions.</summary>
 914    public IList<GovernanceVerificationKey> Keys => keys;
 15
 16    /// <summary>Gets the explicit signature algorithm allow-list.</summary>
 1017    public ISet<string> AllowedAlgorithms => allowedAlgorithms;
 18
 19    /// <summary>Gets or sets whether pre-6.0 hash-only signature input is accepted.</summary>
 20    public bool AllowLegacySignatureInput { get; set; }
 21
 22    /// <summary>Adds an SPKI PEM public key.</summary>
 23    public void AddPemKey(
 24        string keyId,
 25        string keyVersion,
 26        string signatureAlgorithm,
 27        string publicKeyPem,
 28        bool isRevoked = false,
 29        int minimumRsaKeySize = 2048)
 30    {
 531        keys.Add(GovernanceVerificationKey.FromPem(
 532            keyId, keyVersion, signatureAlgorithm, publicKeyPem, isRevoked, minimumRsaKeySize));
 533    }
 34
 35    /// <summary>Adds an RSA or EC public JWK.</summary>
 36    public void AddJwkKey(
 37        string keyId,
 38        string keyVersion,
 39        string signatureAlgorithm,
 40        string publicJwk,
 41        bool isRevoked = false,
 42        int minimumRsaKeySize = 2048)
 43    {
 144        keys.Add(GovernanceVerificationKey.FromJwk(
 145            keyId, keyVersion, signatureAlgorithm, publicJwk, isRevoked, minimumRsaKeySize));
 146    }
 47
 48    internal void Validate()
 49    {
 1050        if (allowedAlgorithms.Count == 0 || allowedAlgorithms.Any(string.IsNullOrWhiteSpace))
 51        {
 052            throw new InvalidOperationException("At least one non-empty signature algorithm must be allowed.");
 53        }
 54
 1055        if (keys.GroupBy(key => (key.KeyId, key.KeyVersion)).Any(group => group.Count() > 1))
 56        {
 057            throw new InvalidOperationException("Each configured verification key ID and version pair must be unique.");
 58        }
 1059    }
 60}