refactor(AsymCryptHandler): Renamed to Cryptograph

This commit is contained in:
Developer 02
2025-01-07 12:03:01 +01:00
parent d9d61368e3
commit ac0b6f739b
2 changed files with 3 additions and 3 deletions

View 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 Cryptograph : RSAFactory<AsymCryptParams>, ICryptograph, IAsymmetricKeyFactory
{
public IEnumerable<IAsymmetricPrivateKey> PrivateKeys { get; }
/// <summary>
/// It is a separate decryptor for permanently stored encrypted data. It is assigned to the first Default decryptor by default.
/// </summary>
public IAsymmetricPrivateKey VaultPrivateKey { get; }
private readonly Lazy<IEnumerable<IAsymmetricPublicKey>> _lazyPublicKeys;
public IEnumerable<IAsymmetricPublicKey> PublicKeys => _lazyPublicKeys.Value;
public IEnumerable<TokenDescription> TokenDescriptions { get; init; } = new List<TokenDescription>();
public Cryptograph(IOptions<AsymCryptParams> options, ILogger<Cryptograph>? logger = null) : base(options)
{
logger?.LogInformation("Core.Secrets version: {Version}, Created on: {CreationDate}.", Secrets.Version, Secrets.CreationDate.ToString("dd.MM.yyyy"));
if (!_params.PrivateKeys.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."
);
PrivateKeys = _params.PrivateKeys;
VaultPrivateKey = _params.VaultPrivateKey ?? PrivateKeys.First();
_lazyPublicKeys = new(PrivateKeys.Select(decryptor => decryptor.PublicKey));
}
}
}