43 lines
2.2 KiB
C#
43 lines
2.2 KiB
C#
using DigitalData.Core.Abstractions.Security;
|
|
using DigitalData.Core.Security.Config;
|
|
using DigitalData.Core.Security.Cryptographer;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace DigitalData.Core.Security
|
|
{
|
|
public static class DIExtensions
|
|
{
|
|
private static IServiceCollection AddAsymCryptService<TAsymCryptParams>(this IServiceCollection services)
|
|
where TAsymCryptParams : AsymCryptParams
|
|
{
|
|
services.TryAddScoped<IAsymCryptService<TAsymCryptParams>, AsymCryptService<TAsymCryptParams>>();
|
|
return services;
|
|
}
|
|
|
|
public static IServiceCollection AddAsymCryptService<TAsymCryptParams>(this IServiceCollection services, IConfigurationSection section)
|
|
where TAsymCryptParams : AsymCryptParams
|
|
=> services.Configure<TAsymCryptParams>(section).AddAsymCryptService<TAsymCryptParams>();
|
|
|
|
public static IServiceCollection AddAsymCryptService<TAsymCryptParams>(this IServiceCollection services, TAsymCryptParams param)
|
|
where TAsymCryptParams : AsymCryptParams
|
|
=> services.AddSingleton(Options.Create(param)).AddAsymCryptService<TAsymCryptParams>();
|
|
|
|
private static IServiceCollection AddRSAFactory<TRSAFactoryParams>(this IServiceCollection services)
|
|
where TRSAFactoryParams : RSAFactoryParams
|
|
{
|
|
services.TryAddScoped<IRSAFactory<TRSAFactoryParams>, RSAFactory<TRSAFactoryParams>>();
|
|
return services;
|
|
}
|
|
|
|
public static IServiceCollection AddRSAFactory<TRSAFactoryParams>(this IServiceCollection services, IConfigurationSection section)
|
|
where TRSAFactoryParams : RSAFactoryParams
|
|
=> services.Configure<TRSAFactoryParams>(section).AddRSAFactory<TRSAFactoryParams>();
|
|
|
|
public static IServiceCollection AddRSAFactory<TRSAFactoryParams>(this IServiceCollection services, TRSAFactoryParams param)
|
|
where TRSAFactoryParams : RSAFactoryParams
|
|
=> services.AddSingleton(Options.Create(param)).AddRSAFactory<TRSAFactoryParams>();
|
|
}
|
|
} |