68 lines
1.9 KiB
C#
68 lines
1.9 KiB
C#
using StellaOps.Cryptography;
|
|
using StellaOps.Cryptography.DependencyInjection;
|
|
using StellaOps.Cryptography.Plugin.Pkcs11Gost;
|
|
using System;
|
|
#if STELLAOPS_CRYPTO_PRO
|
|
using StellaOps.Cryptography.Plugin.CryptoPro;
|
|
#endif
|
|
|
|
namespace StellaOps.Configuration;
|
|
|
|
public static partial class StellaOpsCryptoServiceCollectionExtensions
|
|
{
|
|
private static void ApplyRegistry(
|
|
CryptoProviderRegistryOptions target,
|
|
CryptoProviderRegistryOptions source)
|
|
{
|
|
target.ActiveProfile = source.ActiveProfile;
|
|
target.PreferredProviders.Clear();
|
|
foreach (var provider in source.PreferredProviders)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(provider))
|
|
{
|
|
target.PreferredProviders.Add(provider.Trim());
|
|
}
|
|
}
|
|
|
|
target.Profiles.Clear();
|
|
foreach (var kvp in source.Profiles)
|
|
{
|
|
if (kvp.Value is null)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var profile = new CryptoProviderProfileOptions();
|
|
foreach (var provider in kvp.Value.PreferredProviders)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(provider))
|
|
{
|
|
profile.PreferredProviders.Add(provider.Trim());
|
|
}
|
|
}
|
|
|
|
target.Profiles[kvp.Key] = profile;
|
|
}
|
|
}
|
|
|
|
private static void CopyPkcs11Options(Pkcs11GostProviderOptions target, Pkcs11GostProviderOptions source)
|
|
{
|
|
target.Keys.Clear();
|
|
foreach (var key in source.Keys)
|
|
{
|
|
target.Keys.Add(key.Clone());
|
|
}
|
|
}
|
|
|
|
#if STELLAOPS_CRYPTO_PRO
|
|
private static void CopyCryptoProOptions(CryptoProGostProviderOptions target, CryptoProGostProviderOptions source)
|
|
{
|
|
target.Keys.Clear();
|
|
foreach (var key in source.Keys)
|
|
{
|
|
target.Keys.Add(key.Clone());
|
|
}
|
|
}
|
|
#endif
|
|
}
|