refactor(AsymCryptService): umbenannt in AsymCryptHandler
This commit is contained in:
42
DigitalData.Core.Security/AsymCryptHandler.cs
Normal file
42
DigitalData.Core.Security/AsymCryptHandler.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using DigitalData.Core.Abstractions.Security;
|
||||
using DigitalData.Core.Security.Config;
|
||||
using DigitalData.Core.Security.Cryptographer;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace DigitalData.Core.Security
|
||||
{
|
||||
public class AsymCryptHandler : RSAFactory<AsymCryptParams>, IAsymCryptHandler, IRSAFactory
|
||||
{
|
||||
public IEnumerable<IRSADecryptor> Decryptors { get; }
|
||||
|
||||
/// <summary>
|
||||
/// It is a separate decryptor for permanently stored encrypted data. It is assigned to the first Default decryptor by default.
|
||||
/// </summary>
|
||||
public IRSADecryptor Vault { get; }
|
||||
|
||||
private readonly Lazy<IEnumerable<IRSAEncryptor>> _lazyEncryptors;
|
||||
|
||||
public IEnumerable<IRSAEncryptor> Encryptors => _lazyEncryptors.Value;
|
||||
|
||||
public IEnumerable<TokenDescription> TokenDescriptions { get; init; } = new List<TokenDescription>();
|
||||
|
||||
public AsymCryptHandler(IOptions<AsymCryptParams> options, ILogger<AsymCryptHandler>? logger = null) : base(options)
|
||||
{
|
||||
logger?.LogInformation("Core.Secrets version: {Version}, Created on: {CreationDate}.", Secrets.Version, Secrets.CreationDate.ToString("dd.MM.yyyy"));
|
||||
|
||||
if (!_params.Decryptors.Any())
|
||||
throw new InvalidOperationException(
|
||||
"Any decryptor is not found. Ensure that at least one decryptor is configured in the provided parameters. " +
|
||||
"This issue typically arises if the configuration for decryptors is incomplete or missing. " +
|
||||
"Check the 'Decryptors' collection in the configuration and verify that it contains valid entries."
|
||||
);
|
||||
|
||||
Decryptors = _params.Decryptors;
|
||||
|
||||
Vault = _params.Vault ?? Decryptors.First();
|
||||
|
||||
_lazyEncryptors = new(Decryptors.Select(decryptor => decryptor.Encryptor));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user