< Summary

Information
Class: AsiBackbone.Signing.ManagedKey.ManagedKeySigningServiceCollectionExtensions
Assembly: AsiBackbone.Signing.ManagedKey
File(s): /home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Signing.ManagedKey/ManagedKeySigningServiceCollectionExtensions.cs
Line coverage
100%
Covered lines: 39
Uncovered lines: 0
Coverable lines: 39
Total lines: 128
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

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

#LineLine coverage
 1using AsiBackbone.Core.Signing;
 2using Microsoft.Extensions.DependencyInjection;
 3
 4namespace AsiBackbone.Signing.ManagedKey;
 5
 6/// <summary>
 7/// Provides dependency injection registration helpers for managed-key signing.
 8/// </summary>
 9public static class ManagedKeySigningServiceCollectionExtensions
 10{
 11    /// <summary>
 12    /// Adds production-oriented managed-key signing with a host-owned managed-key client factory.
 13    /// </summary>
 14    /// <remarks>
 15    /// The production-oriented registration fails closed by default because <see cref="ManagedKeySigningOptions.ReturnU
 16    /// defaults to <see langword="false" />.
 17    /// </remarks>
 18    public static IServiceCollection AddAsiBackboneManagedKeySigning(
 19        this IServiceCollection services,
 20        Action<ManagedKeySigningOptions> configure,
 21        Func<IServiceProvider, IManagedKeySigningClient> clientFactory)
 22    {
 1223        ArgumentNullException.ThrowIfNull(services);
 1024        ArgumentNullException.ThrowIfNull(configure);
 825        ArgumentNullException.ThrowIfNull(clientFactory);
 26
 627        ManagedKeySigningOptions options = new();
 628        configure(options);
 629        options.Validate();
 30
 631        return AddManagedKeySigningCore(services, options, clientFactory);
 32    }
 33
 34    /// <summary>
 35    /// Adds production-oriented managed-key signing using an already-registered <see cref="IManagedKeySigningClient" />
 36    /// </summary>
 37    /// <remarks>
 38    /// The production-oriented registration fails closed by default because <see cref="ManagedKeySigningOptions.ReturnU
 39    /// defaults to <see langword="false" />.
 40    /// </remarks>
 41    public static IServiceCollection AddAsiBackboneManagedKeySigning(
 42        this IServiceCollection services,
 43        Action<ManagedKeySigningOptions> configure)
 44    {
 1045        ArgumentNullException.ThrowIfNull(services);
 846        ArgumentNullException.ThrowIfNull(configure);
 47
 648        ManagedKeySigningOptions options = new();
 649        configure(options);
 650        options.Validate();
 51
 452        return AddManagedKeySigningCore(services, options);
 53    }
 54
 55    /// <summary>
 56    /// Adds local-validation managed-key signing with a host-owned managed-key client factory.
 57    /// </summary>
 58    /// <remarks>
 59    /// This helper explicitly sets <see cref="ManagedKeySigningOptions.ReturnUnsignedOnFailure" /> to <see langword="tr
 60    /// so samples, tests, and diagnostics can inspect unsigned failure metadata. Do not use this helper as the default
 61    /// production registration unless host policy explicitly routes unsigned failure metadata.
 62    /// </remarks>
 63    public static IServiceCollection AddAsiBackboneManagedKeySigningForLocalValidation(
 64        this IServiceCollection services,
 65        Action<ManagedKeySigningOptions> configure,
 66        Func<IServiceProvider, IManagedKeySigningClient> clientFactory)
 67    {
 1068        ArgumentNullException.ThrowIfNull(services);
 869        ArgumentNullException.ThrowIfNull(configure);
 670        ArgumentNullException.ThrowIfNull(clientFactory);
 71
 472        ManagedKeySigningOptions options = new();
 473        configure(options);
 474        options.ReturnUnsignedOnFailure = true;
 475        options.Validate();
 76
 477        return AddManagedKeySigningCore(services, options, clientFactory);
 78    }
 79
 80    /// <summary>
 81    /// Adds local-validation managed-key signing using an already-registered <see cref="IManagedKeySigningClient" />.
 82    /// </summary>
 83    /// <remarks>
 84    /// This helper explicitly sets <see cref="ManagedKeySigningOptions.ReturnUnsignedOnFailure" /> to <see langword="tr
 85    /// so samples, tests, and diagnostics can inspect unsigned failure metadata. Do not use this helper as the default
 86    /// production registration unless host policy explicitly routes unsigned failure metadata.
 87    /// </remarks>
 88    public static IServiceCollection AddAsiBackboneManagedKeySigningForLocalValidation(
 89        this IServiceCollection services,
 90        Action<ManagedKeySigningOptions> configure)
 91    {
 692        ArgumentNullException.ThrowIfNull(services);
 493        ArgumentNullException.ThrowIfNull(configure);
 94
 295        ManagedKeySigningOptions options = new();
 296        configure(options);
 297        options.ReturnUnsignedOnFailure = true;
 298        options.Validate();
 99
 2100        return AddManagedKeySigningCore(services, options);
 101    }
 102
 103    private static IServiceCollection AddManagedKeySigningCore(
 104        IServiceCollection services,
 105        ManagedKeySigningOptions options,
 106        Func<IServiceProvider, IManagedKeySigningClient> clientFactory)
 107    {
 10108        _ = services.AddSingleton(options);
 10109        _ = services.AddSingleton(clientFactory);
 10110        _ = services.AddSingleton<ManagedKeySigningService>();
 10111        _ = services.AddSingleton<IAsiBackboneSigningService>(serviceProvider =>
 20112            serviceProvider.GetRequiredService<ManagedKeySigningService>());
 113
 10114        return services;
 115    }
 116
 117    private static IServiceCollection AddManagedKeySigningCore(
 118        IServiceCollection services,
 119        ManagedKeySigningOptions options)
 120    {
 6121        _ = services.AddSingleton(options);
 6122        _ = services.AddSingleton<ManagedKeySigningService>();
 6123        _ = services.AddSingleton<IAsiBackboneSigningService>(serviceProvider =>
 12124            serviceProvider.GetRequiredService<ManagedKeySigningService>());
 125
 6126        return services;
 127    }
 128}